style(lint): passage de black
This commit is contained in:
parent
4952036fc9
commit
a96e4fc8c6
36
icingabot.py
36
icingabot.py
@ -107,7 +107,12 @@ class Icinga2ServiceManager:
|
|||||||
"X-HTTP-Method-Override": "GET",
|
"X-HTTP-Method-Override": "GET",
|
||||||
}
|
}
|
||||||
data = {
|
data = {
|
||||||
"attrs": ["last_check_result", "display_name", "host_name", "acknowledgement"],
|
"attrs": [
|
||||||
|
"last_check_result",
|
||||||
|
"display_name",
|
||||||
|
"host_name",
|
||||||
|
"acknowledgement",
|
||||||
|
],
|
||||||
"filter": "service.state!=ServiceOK",
|
"filter": "service.state!=ServiceOK",
|
||||||
}
|
}
|
||||||
try:
|
try:
|
||||||
@ -119,9 +124,7 @@ class Icinga2ServiceManager:
|
|||||||
verify=settings["icinga2ca"],
|
verify=settings["icinga2ca"],
|
||||||
)
|
)
|
||||||
if r.status_code == 200:
|
if r.status_code == 200:
|
||||||
new_ko_services = [
|
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_ko_services
|
for n in new_ko_services
|
||||||
@ -143,10 +146,7 @@ class Icinga2ServiceManager:
|
|||||||
"Accept": "application/json",
|
"Accept": "application/json",
|
||||||
"X-HTTP-Method-Override": "POST",
|
"X-HTTP-Method-Override": "POST",
|
||||||
}
|
}
|
||||||
params = {
|
params = {"type": "Service", "filter": "service.state!=ServiceOK"}
|
||||||
"type": "Service",
|
|
||||||
"filter": "service.state!=ServiceOK"
|
|
||||||
}
|
|
||||||
if pattern:
|
if pattern:
|
||||||
params['filter'] += '&& match("*{}*", service.__name)'.format(pattern)
|
params['filter'] += '&& match("*{}*", service.__name)'.format(pattern)
|
||||||
try:
|
try:
|
||||||
@ -167,7 +167,7 @@ class Icinga2ServiceManager:
|
|||||||
def ack_service(self, pattern, comment, nick):
|
def ack_service(self, pattern, comment, nick):
|
||||||
data = {
|
data = {
|
||||||
"author": nick,
|
"author": nick,
|
||||||
"comment": comment or " ", # never "" !
|
"comment": comment or " ", # never "" !
|
||||||
}
|
}
|
||||||
self.post_on_services(pattern, '/v1/actions/acknowledge-problem', data)
|
self.post_on_services(pattern, '/v1/actions/acknowledge-problem', data)
|
||||||
|
|
||||||
@ -234,10 +234,7 @@ class IcingaBot(Icinga2ServiceManager, irc.bot.SingleServerIRCBot):
|
|||||||
self.do_command(e, e.arguments[0][1:])
|
self.do_command(e, e.arguments[0][1:])
|
||||||
return
|
return
|
||||||
a = e.arguments[0].split(":", 1)
|
a = e.arguments[0].split(":", 1)
|
||||||
if (
|
if len(a) > 1 and a[0].lower() == self.connection.get_nickname().lower():
|
||||||
len(a) > 1
|
|
||||||
and a[0].lower() == self.connection.get_nickname().lower()
|
|
||||||
):
|
|
||||||
self.do_command(e, a[1].strip())
|
self.do_command(e, a[1].strip())
|
||||||
return
|
return
|
||||||
|
|
||||||
@ -280,7 +277,8 @@ 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.get_unack_ko_services(), key=regroup_key), regroup_key
|
sorted(self.get_unack_ko_services(), key=regroup_key),
|
||||||
|
regroup_key,
|
||||||
)
|
)
|
||||||
]
|
]
|
||||||
|
|
||||||
@ -302,12 +300,14 @@ class IcingaBot(Icinga2ServiceManager, irc.bot.SingleServerIRCBot):
|
|||||||
]
|
]
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
acknowledged = [s for s in self.ko_services if s["attrs"]["acknowledgement"]]
|
acknowledged = [
|
||||||
|
s for s in self.ko_services if s["attrs"]["acknowledgement"]
|
||||||
|
]
|
||||||
if acknowledged:
|
if acknowledged:
|
||||||
self.send(
|
self.send(
|
||||||
"Acknowledged ({}): {}".format(
|
"Acknowledged ({}): {}".format(
|
||||||
len(acknowledged),
|
len(acknowledged),
|
||||||
', '.join({s["attrs"]["display_name"] for s in acknowledged})
|
', '.join({s["attrs"]["display_name"] for s in acknowledged}),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
@ -315,9 +315,7 @@ class IcingaBot(Icinga2ServiceManager, irc.bot.SingleServerIRCBot):
|
|||||||
|
|
||||||
def do_ack(self, c, e):
|
def do_ack(self, c, e):
|
||||||
if self.args is None:
|
if self.args is None:
|
||||||
self.send(
|
self.send(e.source.nick + ": usage: !ack <pattern or all> [: comment]")
|
||||||
e.source.nick + ": usage: !ack <pattern or all> [: comment]"
|
|
||||||
)
|
|
||||||
return
|
return
|
||||||
tokens = self.args.split(":", 1)
|
tokens = self.args.split(":", 1)
|
||||||
pattern, comment = tokens[0].strip(), ""
|
pattern, comment = tokens[0].strip(), ""
|
||||||
|
Loading…
Reference in New Issue
Block a user