Added configuration for incident visibility

This commit is contained in:
Jacek Szubert
2017-03-03 15:57:13 +11:00
parent cfd0ddcb2b
commit f7381aa2bc
3 changed files with 8 additions and 2 deletions

View File

@@ -36,6 +36,7 @@ cachet:
action: action:
- CREATE_INCIDENT - CREATE_INCIDENT
- UPDATE_STATUS - UPDATE_STATUS
public_incidents: true
frequency: 30 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. - **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. - **CREATE_INCIDENT**, we will create an incident when the expectation fails.
- **UPDATE_STATUS**, updates the component status - **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. - **frequency**, how often we'll send a request to the given URL. The unit is in seconds.
## Setting up ## Setting up

View File

@@ -84,6 +84,9 @@ class Configuration(object):
# We need the current status so we monitor the status changes. This is necessary for creating incidents. # 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) 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.logger.info('Monitoring URL: %s %s' % (self.endpoint_method, self.endpoint_url))
self.expectations = [Expectaction.create(expectation) for expectation in self.data['endpoint']['expectation']] self.expectations = [Expectaction.create(expectation) for expectation in self.data['endpoint']['expectation']]
for expectation in self.expectations: for expectation in self.expectations:
@@ -220,7 +223,7 @@ class Configuration(object):
""" """
if hasattr(self, 'incident_id') and self.status == st.COMPONENT_STATUS_OPERATIONAL: 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. # 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} 'notify': True}
incident_request = requests.put('%s/incidents/%d' % (self.api_url, self.incident_id), params=params, incident_request = requests.put('%s/incidents/%d' % (self.api_url, self.incident_id), params=params,
@@ -236,7 +239,7 @@ class Configuration(object):
incident_request.status_code, self.message)) incident_request.status_code, self.message))
elif not hasattr(self, 'incident_id') and self.status != st.COMPONENT_STATUS_OPERATIONAL: elif not hasattr(self, 'incident_id') and self.status != st.COMPONENT_STATUS_OPERATIONAL:
# This is the first time the incident is being created. # 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} '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) incident_request = requests.post('%s/incidents' % (self.api_url,), params=params, headers=self.headers)
if incident_request.ok: if incident_request.ok:

View File

@@ -17,4 +17,5 @@ cachet:
action: action:
- CREATE_INCIDENT - CREATE_INCIDENT
- UPDATE_STATUS - UPDATE_STATUS
public_incidents: true
frequency: 30 frequency: 30