fix(fetch): évite le spammer trop le chan en cas d innacessibilité de l api
This commit is contained in:
parent
a96e4fc8c6
commit
c24e52a788
@ -85,6 +85,7 @@ else:
|
|||||||
|
|
||||||
class Icinga2ServiceManager:
|
class Icinga2ServiceManager:
|
||||||
ko_services = []
|
ko_services = []
|
||||||
|
error_counter = 0
|
||||||
|
|
||||||
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
|
||||||
@ -123,6 +124,7 @@ class Icinga2ServiceManager:
|
|||||||
data=json.dumps(data),
|
data=json.dumps(data),
|
||||||
verify=settings["icinga2ca"],
|
verify=settings["icinga2ca"],
|
||||||
)
|
)
|
||||||
|
self.error_counter = 0
|
||||||
if r.status_code == 200:
|
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 = [
|
news = [
|
||||||
@ -138,7 +140,9 @@ class Icinga2ServiceManager:
|
|||||||
self.ko_services = new_ko_services
|
self.ko_services = new_ko_services
|
||||||
return (lost, news)
|
return (lost, news)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
if self.error_counter < 10:
|
||||||
self.send("Unable to fetch from Icinga2: {}".format(e))
|
self.send("Unable to fetch from Icinga2: {}".format(e))
|
||||||
|
self.error_counter += 1
|
||||||
return (False, False)
|
return (False, False)
|
||||||
|
|
||||||
def post_on_services(self, pattern, uri, data={}):
|
def post_on_services(self, pattern, uri, data={}):
|
||||||
|
Loading…
Reference in New Issue
Block a user