style(lint): passage de black

This commit is contained in:
François Poulain 2021-01-16 11:10:33 +01:00 committed by Cliss XXI - dev
parent 4952036fc9
commit a96e4fc8c6

View File

@ -107,7 +107,12 @@ class Icinga2ServiceManager:
"X-HTTP-Method-Override": "GET",
}
data = {
"attrs": ["last_check_result", "display_name", "host_name", "acknowledgement"],
"attrs": [
"last_check_result",
"display_name",
"host_name",
"acknowledgement",
],
"filter": "service.state!=ServiceOK",
}
try:
@ -119,9 +124,7 @@ class Icinga2ServiceManager:
verify=settings["icinga2ca"],
)
if r.status_code == 200:
new_ko_services = [
n for n in r.json()["results"] if n is not None
]
new_ko_services = [n for n in r.json()["results"] if n is not None]
news = [
n
for n in new_ko_services
@ -143,10 +146,7 @@ class Icinga2ServiceManager:
"Accept": "application/json",
"X-HTTP-Method-Override": "POST",
}
params = {
"type": "Service",
"filter": "service.state!=ServiceOK"
}
params = {"type": "Service", "filter": "service.state!=ServiceOK"}
if pattern:
params['filter'] += '&& match("*{}*", service.__name)'.format(pattern)
try:
@ -167,7 +167,7 @@ class Icinga2ServiceManager:
def ack_service(self, pattern, comment, nick):
data = {
"author": nick,
"comment": comment or " ", # never "" !
"comment": comment or " ", # never "" !
}
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:])
return
a = e.arguments[0].split(":", 1)
if (
len(a) > 1
and a[0].lower() == self.connection.get_nickname().lower()
):
if len(a) > 1 and a[0].lower() == self.connection.get_nickname().lower():
self.do_command(e, a[1].strip())
return
@ -280,7 +277,8 @@ class IcingaBot(Icinga2ServiceManager, irc.bot.SingleServerIRCBot):
return [
(group, [service["attrs"]["host_name"] for service in services])
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:
self.send(
"Acknowledged ({}): {}".format(
len(acknowledged),
', '.join({s["attrs"]["display_name"] for s in acknowledged})
', '.join({s["attrs"]["display_name"] for s in acknowledged}),
)
)
else:
@ -315,9 +315,7 @@ class IcingaBot(Icinga2ServiceManager, irc.bot.SingleServerIRCBot):
def do_ack(self, c, e):
if self.args is None:
self.send(
e.source.nick + ": usage: !ack <pattern or all> [: comment]"
)
self.send(e.source.nick + ": usage: !ack <pattern or all> [: comment]")
return
tokens = self.args.split(":", 1)
pattern, comment = tokens[0].strip(), ""