From c24e52a7887ae841bdc68e4aa934c8699ae22269 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Poulain?= Date: Sat, 16 Jan 2021 11:24:02 +0100 Subject: [PATCH] =?UTF-8?q?fix(fetch):=20=C3=A9vite=20le=20spammer=20trop?= =?UTF-8?q?=20le=20chan=20en=20cas=20d=20innacessibilit=C3=A9=20de=20l=20a?= =?UTF-8?q?pi?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- icingabot.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/icingabot.py b/icingabot.py index cb55d6e..be5c0d5 100755 --- a/icingabot.py +++ b/icingabot.py @@ -85,6 +85,7 @@ else: class Icinga2ServiceManager: ko_services = [] + error_counter = 0 def build_request_url(self, uri, params={}): # Since icinga2 wants « URL-encoded strings » but requests @@ -123,6 +124,7 @@ class Icinga2ServiceManager: data=json.dumps(data), verify=settings["icinga2ca"], ) + self.error_counter = 0 if r.status_code == 200: new_ko_services = [n for n in r.json()["results"] if n is not None] news = [ @@ -138,7 +140,9 @@ class Icinga2ServiceManager: self.ko_services = new_ko_services return (lost, news) except Exception as e: - self.send("Unable to fetch from Icinga2: {}".format(e)) + if self.error_counter < 10: + self.send("Unable to fetch from Icinga2: {}".format(e)) + self.error_counter += 1 return (False, False) def post_on_services(self, pattern, uri, data={}):