feat(ack): rassemble les services acked

This commit is contained in:
François Poulain 2020-08-23 17:59:44 +02:00
parent d973210b81
commit 86a89976cf

View File

@ -108,7 +108,7 @@ class Icinga2ServiceManager:
"X-HTTP-Method-Override": "GET",
}
data = {
"attrs": ["last_check_result", "display_name", "host_name"],
"attrs": ["last_check_result", "display_name", "host_name", "acknowledgement"],
"filter": "service.state!=ServiceOK",
}
try:
@ -310,6 +310,9 @@ class IcingaBot(Icinga2ServiceManager, irc.bot.SingleServerIRCBot):
def do_leave(self, c, e):
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 regroup_key(elem):
return elem["attrs"]["display_name"]
@ -317,7 +320,7 @@ class IcingaBot(Icinga2ServiceManager, irc.bot.SingleServerIRCBot):
return [
(group, [service["attrs"]["host_name"] for service in services])
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:
self.send("Nothing particularly exciting.")