fix(fetch): évite le spammer trop le chan en cas d innacessibilité de l api

This commit is contained in:
François Poulain 2021-01-16 11:24:02 +01:00 committed by Cliss XXI - dev
parent a96e4fc8c6
commit c24e52a788
1 changed files with 5 additions and 1 deletions

View File

@ -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={}):