diff --git a/zabbix_api_v3.py b/zabbix_api_v3.py new file mode 100644 index 0000000..d12e42b --- /dev/null +++ b/zabbix_api_v3.py @@ -0,0 +1,31 @@ +#!/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)