1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
|
"""
Shows a list of all current issues (AKA tripped triggers)
"""
from pyzabbix import ZabbixAPI
# The hostname at which the Zabbix web interface is available
ZABBIX_SERVER = "https://zabbix.example.com"
zapi = ZabbixAPI(ZABBIX_SERVER)
# Login to the Zabbix API
zapi.login("api_username", "api_password")
# Get a list of all issues (AKA tripped triggers)
triggers = zapi.trigger.get(
only_true=1,
skipDependent=1,
monitored=1,
active=1,
output="extend",
expandDescription=1,
selectHosts=["host"],
)
# Do another query to find out which issues are Unacknowledged
unack_triggers = zapi.trigger.get(
only_true=1,
skipDependent=1,
monitored=1,
active=1,
output="extend",
expandDescription=1,
selectHosts=["host"],
withLastEventUnacknowledged=1,
)
unack_trigger_ids = [t["triggerid"] for t in unack_triggers]
for t in triggers:
t["unacknowledged"] = True if t["triggerid"] in unack_trigger_ids else False
# Print a list containing only "tripped" triggers
for t in triggers:
if int(t["value"]) == 1:
print(
"{} - {} {}".format(
t["hosts"][0]["host"],
t["description"],
"(Unack)" if t["unacknowledged"] else "",
)
)
|