forked from aigarskadikis/externalscripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
current-issues.py
executable file
·56 lines (47 loc) · 1.86 KB
/
current-issues.py
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
51
52
53
54
55
#!/bin/python
"""
Shows a list of all current issues (AKA tripped triggers)
"""
from pyzabbix import ZabbixAPI
import urllib3
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
#import credentials from external file
import sys
sys.path.insert(0,'/var/lib/zabbix')
import config
# The hostname at which the Zabbix web interface is available
ZABBIX_SERVER = config.url
zapi = ZabbixAPI(ZABBIX_SERVER)
zapi.session.verify=False
# Login to the Zabbix API
zapi.login(config.username, config.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("{0} - {1} {2}".format(t['hosts'][0]['host'],
t['description'],
'(Unack)' if t['unacknowledged'] else '')
)