feat(ack): rassemble les services acked
This commit is contained in:
parent
d973210b81
commit
86a89976cf
15
icingabot.py
15
icingabot.py
@ -108,7 +108,7 @@ class Icinga2ServiceManager:
|
|||||||
"X-HTTP-Method-Override": "GET",
|
"X-HTTP-Method-Override": "GET",
|
||||||
}
|
}
|
||||||
data = {
|
data = {
|
||||||
"attrs": ["last_check_result", "display_name", "host_name"],
|
"attrs": ["last_check_result", "display_name", "host_name", "acknowledgement"],
|
||||||
"filter": "service.state!=ServiceOK",
|
"filter": "service.state!=ServiceOK",
|
||||||
}
|
}
|
||||||
try:
|
try:
|
||||||
@ -310,6 +310,9 @@ class IcingaBot(Icinga2ServiceManager, irc.bot.SingleServerIRCBot):
|
|||||||
def do_leave(self, c, e):
|
def do_leave(self, c, e):
|
||||||
self.disconnect()
|
self.disconnect()
|
||||||
|
|
||||||
|
def get_unack_ko_services(self):
|
||||||
|
return [s for s in self.ko_services if not s["attrs"]["acknowledgement"]]
|
||||||
|
|
||||||
def regrouped_ko_services(self):
|
def regrouped_ko_services(self):
|
||||||
def regroup_key(elem):
|
def regroup_key(elem):
|
||||||
return elem["attrs"]["display_name"]
|
return elem["attrs"]["display_name"]
|
||||||
@ -317,7 +320,7 @@ class IcingaBot(Icinga2ServiceManager, irc.bot.SingleServerIRCBot):
|
|||||||
return [
|
return [
|
||||||
(group, [service["attrs"]["host_name"] for service in services])
|
(group, [service["attrs"]["host_name"] for service in services])
|
||||||
for group, services in groupby(
|
for group, services in groupby(
|
||||||
sorted(self.ko_services, key=regroup_key), regroup_key
|
sorted(self.get_unack_ko_services(), key=regroup_key), regroup_key
|
||||||
)
|
)
|
||||||
]
|
]
|
||||||
|
|
||||||
@ -339,6 +342,14 @@ class IcingaBot(Icinga2ServiceManager, irc.bot.SingleServerIRCBot):
|
|||||||
]
|
]
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
acknowledged = [s for s in self.ko_services if s["attrs"]["acknowledgement"]]
|
||||||
|
if acknowledged:
|
||||||
|
self.send(
|
||||||
|
"Acknowledged ({}): {}".format(
|
||||||
|
len(acknowledged),
|
||||||
|
', '.join([s["attrs"]["display_name"] for s in acknowledged])
|
||||||
|
)
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
self.send("Nothing particularly exciting.")
|
self.send("Nothing particularly exciting.")
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user