diff --git a/README.md b/README.md index dca65d3..02b034b 100644 --- a/README.md +++ b/README.md @@ -36,6 +36,7 @@ cachet: action: - CREATE_INCIDENT - UPDATE_STATUS + public_incidents: true frequency: 30 ``` @@ -55,6 +56,7 @@ frequency: 30 - **action**, the action to be done when one of the expectations fails. This is optional and if left blank, nothing will be done to the component. - **CREATE_INCIDENT**, we will create an incident when the expectation fails. - **UPDATE_STATUS**, updates the component status + - **public_incidents**, boolean to decide if created incidents should be visible to everyone or only to logged in users. Important only if `CREATE_INCIDENT` or `UPDATE_STATUS` are set. - **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 847f1c1..8860c9a 100644 --- a/cachet_url_monitor/configuration.py +++ b/cachet_url_monitor/configuration.py @@ -84,6 +84,9 @@ class Configuration(object): # We need the current status so we monitor the status changes. This is necessary for creating incidents. self.status = get_current_status(self.api_url, self.component_id, self.headers) + # Get remaining settings + self.public_incidents = int(os.environ.get('CACHET_PUBLIC_INCIDENTS') or self.data['cachet']['public_incidents']) + self.logger.info('Monitoring URL: %s %s' % (self.endpoint_method, self.endpoint_url)) self.expectations = [Expectaction.create(expectation) for expectation in self.data['endpoint']['expectation']] for expectation in self.expectations: @@ -208,7 +211,7 @@ class Configuration(object): """ if hasattr(self, 'incident_id') and self.status == st.COMPONENT_STATUS_OPERATIONAL: # If the incident already exists, it means it was unhealthy but now it's healthy again. - params = {'status': 4, 'visible': 1, 'component_id': self.component_id, 'component_status': self.status, + params = {'status': 4, 'visible': self.public_incidents, 'component_id': self.component_id, 'component_status': self.status, 'notify': True} incident_request = requests.put('%s/incidents/%d' % (self.api_url, self.incident_id), params=params, @@ -224,7 +227,7 @@ class Configuration(object): incident_request.status_code, self.message)) elif not hasattr(self, 'incident_id') and self.status != st.COMPONENT_STATUS_OPERATIONAL: # This is the first time the incident is being created. - params = {'name': 'URL unavailable', 'message': self.message, 'status': 1, 'visible': 1, + params = {'name': 'URL unavailable', 'message': self.message, 'status': 1, 'visible': self.public_incidents, 'component_id': self.component_id, 'component_status': self.status, 'notify': True} incident_request = requests.post('%s/incidents' % (self.api_url,), params=params, headers=self.headers) if incident_request.ok: diff --git a/config.yml b/config.yml index 1c68a99..5015d57 100644 --- a/config.yml +++ b/config.yml @@ -17,4 +17,5 @@ cachet: action: - CREATE_INCIDENT - UPDATE_STATUS + public_incidents: true frequency: 30