0
0
Fork 0
mirror of https://github.com/alerta/alerta-contrib.git synced 2025-03-15 21:14:44 +00:00

plugin/alerta-prometheus: fix 500 error when response is not as expected ()

* plugin/alerta-prometheus: fix 500 error when response is not as expected

Alertmanager Api may respond with empty set of silenceIds, which may cause exception

"alerta.exceptions.ApiError: Alertmanager: ERROR - list indices must
 be integers or slices, not str"

This error is seen from the client, and the Alert can not be ACK-ed

* plugin/alerta-prometheus: minor code improvement
This commit is contained in:
Ky-Anh Huynh 2020-02-20 12:42:10 +01:00 committed by GitHub
parent 4d0961a003
commit 58023cc05d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -90,8 +90,12 @@ class AlertmanagerSilence(PluginBase):
# example r={"status":"success","data":{"silenceId":8}}
try:
silenceId = r.json()['data']['silenceId']
alert.attributes['silenceId'] = silenceId
data = r.json().get('data', [])
if data:
silenceId = data['silenceId']
alert.attributes['silenceId'] = silenceId
else:
silenceId = alert.attributes.get('silenceId', "unknown")
text = text + ' (silenced in Alertmanager)'
except Exception as e:
raise RuntimeError("Alertmanager: ERROR - %s" % e)