From 2b6385b0b4a827bdca0e1b69339937c1c45d35f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Poulain?= Date: Fri, 1 May 2020 12:06:30 +0200 Subject: [PATCH] =?UTF-8?q?ref(bot):=20renomme=20pour=20=C3=A9viter=20d=20?= =?UTF-8?q?ajouter=20du=20mal=20au=20monde?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- icingabot.py | 38 ++++++++++++++++++-------------------- 1 file changed, 18 insertions(+), 20 deletions(-) diff --git a/icingabot.py b/icingabot.py index 4c933c9..d9ae33d 100755 --- a/icingabot.py +++ b/icingabot.py @@ -84,7 +84,7 @@ else: class Icinga2ServiceManager: - notifications = [] + ko_services = [] def build_request_url(self, uri, params={}): # Since icinga2 wants « URL-encoded strings » but requests @@ -101,7 +101,7 @@ class Icinga2ServiceManager: .url.replace("+", "%20") ) - def fetch_notifications(self): + def fetch_ko_services(self): headers = { "Accept": "application/json", "X-HTTP-Method-Override": "GET", @@ -119,22 +119,20 @@ class Icinga2ServiceManager: verify=settings["icinga2ca"], ) if r.status_code == 200: - new_notifications = [ + new_ko_services = [ n for n in r.json()["results"] if n is not None ] news = [ n - for n in new_notifications - if n["name"] - not in [nn["name"] for nn in self.notifications] + for n in new_ko_services + if n["name"] not in [nn["name"] for nn in self.ko_services] ] lost = [ n - for n in self.notifications - if n["name"] - not in [nn["name"] for nn in new_notifications] + for n in self.ko_services + if n["name"] not in [nn["name"] for nn in new_ko_services] ] - self.notifications = new_notifications + self.ko_services = new_ko_services return (lost, news) except Exception: self.send("Unable to fetch from Icinga2") @@ -231,8 +229,8 @@ class IcingaBot(Icinga2ServiceManager, irc.bot.SingleServerIRCBot): ) self.nick = nickname self.channel = channel - self.connection.execute_every(30, self.refresh_notifications) - self.refresh_notifications() + self.connection.execute_every(30, self.refresh_ko_services) + self.refresh_ko_services() def suffix_nick(self, suffix): self.nick_suffix = suffix @@ -241,8 +239,8 @@ class IcingaBot(Icinga2ServiceManager, irc.bot.SingleServerIRCBot): def unmute(self): self.muted = False - if self.notifications: - self.suffix_nick("[{}]".format(len(self.notifications))) + if self.ko_services: + self.suffix_nick("[{}]".format(len(self.ko_services))) else: self.suffix_nick("") @@ -251,12 +249,12 @@ class IcingaBot(Icinga2ServiceManager, irc.bot.SingleServerIRCBot): for line in msg.split("\n"): self.connection.privmsg(self.channel, line) - def refresh_notifications(self): - lost, news = self.fetch_notifications() + def refresh_ko_services(self): + lost, news = self.fetch_ko_services() if lost is False and news is False: return - if self.notifications: - self.suffix_nick("[{}]".format(len(self.notifications))) + if self.ko_services: + self.suffix_nick("[{}]".format(len(self.ko_services))) else: self.suffix_nick("") return @@ -344,12 +342,12 @@ class IcingaBot(Icinga2ServiceManager, irc.bot.SingleServerIRCBot): if self.args == "all": self.args = None self.recheck_service(self.args) - self.connection.execute_delayed(1, self.refresh_notifications) + self.connection.execute_delayed(1, self.refresh_ko_services) def do_mute(self, c, e): self.muted = True self.suffix_nick("[zZz]") - self.connection.execute_delayed(3600, self.refresh_notifications) + self.connection.execute_delayed(3600, self.refresh_ko_services) def do_command(self, e, cmd): nick = e.source.nick