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 (#311)
* 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:
parent
4d0961a003
commit
58023cc05d
1 changed files with 6 additions and 2 deletions
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue