Added Exception for incorrect Zabbix authentication and implemented global color for module result
This commit is contained in:
parent
0c15903d4e
commit
0c52b5586c
@ -6,6 +6,12 @@ class Zabbix(IntervalModule):
|
|||||||
"""
|
"""
|
||||||
Zabbix alerts watcher
|
Zabbix alerts watcher
|
||||||
|
|
||||||
|
.. rubric:: Available formatters
|
||||||
|
* {default} - Full output count alerts like total:a5/a4/a3/a2/a1/a0
|
||||||
|
* {total} - Total count of alerts
|
||||||
|
* {aX_count} - Count alerts of X severity
|
||||||
|
* {colorX} - Predicted color for X severity. It can be used with Pango markup hint for different colours at each severity with
|
||||||
|
|
||||||
Requires pyzabbix
|
Requires pyzabbix
|
||||||
"""
|
"""
|
||||||
settings = (
|
settings = (
|
||||||
@ -23,29 +29,37 @@ class Zabbix(IntervalModule):
|
|||||||
|
|
||||||
alerts_color = ["#DBDBDB", "#D6F6FF", "#FFF6A5", "#FFB689", "#FF9999", "#FF3838"]
|
alerts_color = ["#DBDBDB", "#D6F6FF", "#FFF6A5", "#FFB689", "#FF9999", "#FF3838"]
|
||||||
zapi = ZabbixAPI(self.zabbix_server)
|
zapi = ZabbixAPI(self.zabbix_server)
|
||||||
zapi.login(self.zabbix_user, self.zabbix_password)
|
try:
|
||||||
triggers = zapi.trigger.get(only_true=1,
|
zapi.login(self.zabbix_user, self.zabbix_password)
|
||||||
skipDependent=1,
|
triggers = zapi.trigger.get(only_true=1,
|
||||||
monitored=1,
|
skipDependent=1,
|
||||||
active=1,
|
monitored=1,
|
||||||
min_severity=2,
|
active=1,
|
||||||
output=["priority"],
|
min_severity=2,
|
||||||
withLastEventUnacknowledged=1,
|
output=["priority"],
|
||||||
)
|
withLastEventUnacknowledged=1,
|
||||||
alerts_list = [t['priority'] for t in triggers]
|
)
|
||||||
alerts = [0, 0, 0, 0, 0, 0]
|
alerts_list = [t['priority'] for t in triggers]
|
||||||
cdict = {}
|
alerts = [0, 0, 0, 0, 0, 0]
|
||||||
for i in range(0, 6):
|
cdict = {}
|
||||||
alerts[i] = alerts_list.count(str(i))
|
for i in range(0, 6):
|
||||||
cdict["a%s" % i]=alerts[i]
|
alerts[i] = alerts_list.count(str(i))
|
||||||
if alerts[i] == 0:
|
cdict["a%s_count" % i]=alerts[i]
|
||||||
cdict["c%s" % i] = "#FFFFFF"
|
if alerts[i] == 0:
|
||||||
else:
|
cdict["color%s" % i] = "#FFFFFF"
|
||||||
cdict["c%s" % i] = alerts_color[i]
|
else:
|
||||||
|
cdict["color%s" % i] = alerts_color[i]
|
||||||
|
|
||||||
cdict["default"] = "{0}:{a[5]}/{a[4]}/{a[3]}/{a[2]}/{a[1]}/{a[0]}".format(sum(alerts), a=alerts)
|
cdict["default"] = "{0}:{a[5]}/{a[4]}/{a[3]}/{a[2]}/{a[1]}/{a[0]}".format(sum(alerts), a=alerts)
|
||||||
cdict["total"] = sum(alerts)
|
cdict["total"] = sum(alerts)
|
||||||
|
color = alerts_color[max(alerts)]
|
||||||
|
result = self.format.format(**cdict)
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
result = "Zabbix connection error"
|
||||||
|
color = "#FF0000"
|
||||||
|
|
||||||
self.output = {
|
self.output = {
|
||||||
"full_text": self.format.format(**cdict)
|
"full_text": result,
|
||||||
|
"color": color
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user