From a296cfc1aaabda3a2e14ed59ab5f9c60c43e9a85 Mon Sep 17 00:00:00 2001 From: mazhead Date: Thu, 4 Apr 2019 17:44:34 +0200 Subject: [PATCH] Dont update if same (#64) * Return status as integer During the first start the if statement on line 237 does not get evaluated correctly and will not "return" Therefore by any restart the first evaluation triggers a update even if the original status is same. * Prevent unecessery push By a case where allowed_fails > 0 and one failure is received the url monitor pushes a unnecessary update as the component state was not changed, resulting in a notification of "component is operational", but in fact the component was still operation before the update. This creates another api call (get) towards the cachet, but it is a better trade-off to prevent unnecessary notifications for end-users. --- cachet_url_monitor/configuration.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/cachet_url_monitor/configuration.py b/cachet_url_monitor/configuration.py index afd8b75..d03b015 100644 --- a/cachet_url_monitor/configuration.py +++ b/cachet_url_monitor/configuration.py @@ -241,6 +241,11 @@ class Configuration(object): if not self.trigger_update: return + self.api_component_status = get_current_status(self.api_url, self.component_id, self.headers) + + if self.status == self.api_component_status: + return + params = {'id': self.component_id, 'status': self.status} component_request = requests.put('%s/components/%d' % (self.api_url, self.component_id), params=params, headers=self.headers)