Skip to content

Commit

Permalink
Reopen closed alerts not just if trend indication is more severe
Browse files Browse the repository at this point in the history
  • Loading branch information
satterly committed Feb 21, 2016
1 parent ef9c0ba commit ffc7097
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
2 changes: 1 addition & 1 deletion alerta/app/severity_code.py
Expand Up @@ -128,7 +128,7 @@ def trend(previous, current):
def status_from_severity(previous_severity, current_severity, current_status=None):
if current_severity in [NORMAL, CLEARED, OK]:
return status_code.CLOSED
if current_status == status_code.EXPIRED:
if current_status in [status_code.CLOSED, status_code.EXPIRED]:
return status_code.OPEN
if trend(previous_severity, current_severity) == MORE_SEVERE:
return status_code.OPEN
Expand Down
30 changes: 30 additions & 0 deletions tests/test_alerts.py
Expand Up @@ -278,6 +278,36 @@ def test_expired_alerts(self):
data = json.loads(response.data.decode('utf-8'))
self.assertEqual(data['alert']['status'], 'closed')

# severity == warning -> status=open
response = self.app.post('/alert', data=json.dumps(self.warn_alert), headers=self.headers)
self.assertEqual(response.status_code, 201)
data = json.loads(response.data.decode('utf-8'))
self.assertEqual(data['alert']['status'], 'open')

def test_duplicate_status(self):

# create alert
response = self.app.post('/alert', data=json.dumps(self.fatal_alert), headers=self.headers)
self.assertEqual(response.status_code, 201)
data = json.loads(response.data.decode('utf-8'))
self.assertEqual(data['alert']['duplicateCount'], 0)

alert_id = data['id']

# close alert
response = self.app.post('/alert/' + alert_id + '/status', data=json.dumps({'status': 'closed'}), headers=self.headers)
self.assertEqual(response.status_code, 200)
response = self.app.get('/alert/' + alert_id)
self.assertEqual(response.status_code, 200)
data = json.loads(response.data.decode('utf-8'))
self.assertEqual(data['alert']['status'], "closed")

# duplicate alert -> status=open
response = self.app.post('/alert', data=json.dumps(self.fatal_alert), headers=self.headers)
self.assertEqual(response.status_code, 201)
data = json.loads(response.data.decode('utf-8'))
self.assertEqual(data['alert']['status'], 'open')

def test_alert_tagging(self):

# create alert
Expand Down

0 comments on commit ffc7097

Please sign in to comment.