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:
|
class Icinga2ServiceManager:
|
||||||
notifications = []
|
ko_services = []
|
||||||
|
|
||||||
def build_request_url(self, uri, params={}):
|
def build_request_url(self, uri, params={}):
|
||||||
# Since icinga2 wants « URL-encoded strings » but requests
|
# Since icinga2 wants « URL-encoded strings » but requests
|
||||||
@ -101,7 +101,7 @@ class Icinga2ServiceManager:
|
|||||||
.url.replace("+", "%20")
|
.url.replace("+", "%20")
|
||||||
)
|
)
|
||||||
|
|
||||||
def fetch_notifications(self):
|
def fetch_ko_services(self):
|
||||||
headers = {
|
headers = {
|
||||||
"Accept": "application/json",
|
"Accept": "application/json",
|
||||||
"X-HTTP-Method-Override": "GET",
|
"X-HTTP-Method-Override": "GET",
|
||||||
@ -119,22 +119,20 @@ class Icinga2ServiceManager:
|
|||||||
verify=settings["icinga2ca"],
|
verify=settings["icinga2ca"],
|
||||||
)
|
)
|
||||||
if r.status_code == 200:
|
if r.status_code == 200:
|
||||||
new_notifications = [
|
new_ko_services = [
|
||||||
n for n in r.json()["results"] if n is not None
|
n for n in r.json()["results"] if n is not None
|
||||||
]
|
]
|
||||||
news = [
|
news = [
|
||||||
n
|
n
|
||||||
for n in new_notifications
|
for n in new_ko_services
|
||||||
if n["name"]
|
if n["name"] not in [nn["name"] for nn in self.ko_services]
|
||||||
not in [nn["name"] for nn in self.notifications]
|
|
||||||
]
|
]
|
||||||
lost = [
|
lost = [
|
||||||
n
|
n
|
||||||
for n in self.notifications
|
for n in self.ko_services
|
||||||
if n["name"]
|
if n["name"] not in [nn["name"] for nn in new_ko_services]
|
||||||
not in [nn["name"] for nn in new_notifications]
|
|
||||||
]
|
]
|
||||||
self.notifications = new_notifications
|
self.ko_services = new_ko_services
|
||||||
return (lost, news)
|
return (lost, news)
|
||||||
except Exception:
|
except Exception:
|
||||||
self.send("Unable to fetch from Icinga2")
|
self.send("Unable to fetch from Icinga2")
|
||||||
@ -231,8 +229,8 @@ class IcingaBot(Icinga2ServiceManager, irc.bot.SingleServerIRCBot):
|
|||||||
)
|
)
|
||||||
self.nick = nickname
|
self.nick = nickname
|
||||||
self.channel = channel
|
self.channel = channel
|
||||||
self.connection.execute_every(30, self.refresh_notifications)
|
self.connection.execute_every(30, self.refresh_ko_services)
|
||||||
self.refresh_notifications()
|
self.refresh_ko_services()
|
||||||
|
|
||||||
def suffix_nick(self, suffix):
|
def suffix_nick(self, suffix):
|
||||||
self.nick_suffix = suffix
|
self.nick_suffix = suffix
|
||||||
@ -241,8 +239,8 @@ class IcingaBot(Icinga2ServiceManager, irc.bot.SingleServerIRCBot):
|
|||||||
|
|
||||||
def unmute(self):
|
def unmute(self):
|
||||||
self.muted = False
|
self.muted = False
|
||||||
if self.notifications:
|
if self.ko_services:
|
||||||
self.suffix_nick("[{}]".format(len(self.notifications)))
|
self.suffix_nick("[{}]".format(len(self.ko_services)))
|
||||||
else:
|
else:
|
||||||
self.suffix_nick("")
|
self.suffix_nick("")
|
||||||
|
|
||||||
@ -251,12 +249,12 @@ class IcingaBot(Icinga2ServiceManager, irc.bot.SingleServerIRCBot):
|
|||||||
for line in msg.split("\n"):
|
for line in msg.split("\n"):
|
||||||
self.connection.privmsg(self.channel, line)
|
self.connection.privmsg(self.channel, line)
|
||||||
|
|
||||||
def refresh_notifications(self):
|
def refresh_ko_services(self):
|
||||||
lost, news = self.fetch_notifications()
|
lost, news = self.fetch_ko_services()
|
||||||
if lost is False and news is False:
|
if lost is False and news is False:
|
||||||
return
|
return
|
||||||
if self.notifications:
|
if self.ko_services:
|
||||||
self.suffix_nick("[{}]".format(len(self.notifications)))
|
self.suffix_nick("[{}]".format(len(self.ko_services)))
|
||||||
else:
|
else:
|
||||||
self.suffix_nick("")
|
self.suffix_nick("")
|
||||||
return
|
return
|
||||||
@ -344,12 +342,12 @@ class IcingaBot(Icinga2ServiceManager, irc.bot.SingleServerIRCBot):
|
|||||||
if self.args == "all":
|
if self.args == "all":
|
||||||
self.args = None
|
self.args = None
|
||||||
self.recheck_service(self.args)
|
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):
|
def do_mute(self, c, e):
|
||||||
self.muted = True
|
self.muted = True
|
||||||
self.suffix_nick("[zZz]")
|
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):
|
def do_command(self, e, cmd):
|
||||||
nick = e.source.nick
|
nick = e.source.nick
|
||||||
|
Loading…
Reference in New Issue
Block a user