ref(bot): renomme pour éviter d ajouter du mal au monde
This commit is contained in:
parent
fd0f995aca
commit
2b6385b0b4
38
icingabot.py
38
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
|
||||
|
Loading…
Reference in New Issue
Block a user