Files
ZCE/zabbix_api_v3.py
T
2025-03-20 10:57:00 +00:00

32 lines
977 B
Python

#!/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="<PERMANENT-API-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)