#!/usr/bin/python3 from zabbix_utils import ZabbixAPI from datetime import datetime # Zabbix server details zabbix_url = "https://student-XX-zbxtr-YYYY.zabbix.training" api = ZabbixAPI(url=zabbix_url) api.login(token="") print("Connected to Zabbix API Version %s" % api.api_version()) hosts = api.host.get( search={"name":"API Server"}, output=["hostid","name"] ) print (hosts) hostid = hosts[0]["hostid"] print ('HostID: ' + str(hostid)) items = api.item.get ( hostids=hostid, output=["itemid","name","key_","flags"] ) #print (items) startTime = datetime.now() items_to_delete = [] for item in items: itemid = item["itemid"] flags = item["flags"] if (flags == "4"): items_to_delete.append(itemid) if items_to_delete: deleteitems = api.item.delete (*items_to_delete) print ("Items with ids: " + str(deleteitems) + " removed") print (datetime.now() - startTime)