From 740f726b48ca7512b49529925df8b8a2e3e4a29d Mon Sep 17 00:00:00 2001 From: Jacek Szubert Date: Fri, 10 Feb 2017 14:50:07 +1100 Subject: [PATCH] Make update status optional --- README.md | 2 ++ cachet_url_monitor/configuration.py | 6 ++++++ cachet_url_monitor/scheduler.py | 4 +++- config.yml | 1 + 4 files changed, 12 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index ccd3d15..2a171fc 100644 --- a/README.md +++ b/README.md @@ -33,6 +33,7 @@ cachet: token: my_token component_id: 1 metric_id: 1 + update_status: true frequency: 30 ``` @@ -49,6 +50,7 @@ frequency: 30 - **token**, the API token. - **component_id**, the id of the component we're monitoring. This will be used to update the status of the component. - **metric_id**, this will be used to store the latency of the API. If this is not set, it will be ignored. + - **update_status**, boolean to decide if the component status should be changed in case of a check failure. - **frequency**, how often we'll send a request to the given URL. The unit is in seconds. ## Setting up diff --git a/cachet_url_monitor/configuration.py b/cachet_url_monitor/configuration.py index 4216a71..cce6c4d 100644 --- a/cachet_url_monitor/configuration.py +++ b/cachet_url_monitor/configuration.py @@ -94,6 +94,12 @@ class Configuration(object): """ return 'create_incident' in self.data['cachet'] and self.data['cachet']['create_incident'] + def is_update_status(self): + """Will verify if the configuration is set to update status or not. + :return True if the configuration is set to update status or False it otherwise. + """ + return 'update_status' in self.data['cachet'] and self.data['cachet']['update_status'] + def validate(self): """Validates the configuration by verifying the mandatory fields are present and in the correct format. If the validation fails, a diff --git a/cachet_url_monitor/scheduler.py b/cachet_url_monitor/scheduler.py index 37c6bb1..cd8bb10 100644 --- a/cachet_url_monitor/scheduler.py +++ b/cachet_url_monitor/scheduler.py @@ -51,8 +51,10 @@ class Scheduler(object): if self.configuration.is_create_incident(): self.agent = CreateIncidentAgent(self.configuration) - else: + elif self.configuration.is_update_status(): self.agent = UpdateStatusAgent(self.configuration) + else: + self.agent = Agent(self.configuration) self.stop = False diff --git a/config.yml b/config.yml index 5ba9817..8282ed0 100644 --- a/config.yml +++ b/config.yml @@ -15,4 +15,5 @@ cachet: component_id: 1 #metric_id: 1 create_incident: true + update_status: true frequency: 30