ensure no error is generated if we try to send an alert without an instance label via telegram

This commit is contained in:
nd 2020-11-20 23:38:05 +01:00
parent c1636d0afe
commit 8df5f497d8
No known key found for this signature in database
GPG key ID: 21B5CD4DEE3670E9

View file

@ -22,9 +22,9 @@ def postAlertmanager(chatID):
for alert in content['alerts']: for alert in content['alerts']:
message = "Status: "+alert['status']+"\n" message = "Status: "+alert['status']+"\n"
if 'name' in alert['labels']: if 'name' in alert['labels']:
message += "Instance: "+alert['labels']['instance']+"("+alert['labels']['name']+")\n" message += "Instance: "+alert['labels'].get('instance', 'unknown')+"("+alert['labels']['name']+")\n"
else: else:
message += "Instance: "+alert['labels']['instance']+"\n" message += "Instance: "+alert['labels'].get('instance', 'unknown')+"\n"
if 'info' in alert['annotations']: if 'info' in alert['annotations']:
message += "Info: "+alert['annotations']['info']+"\n" message += "Info: "+alert['annotations']['info']+"\n"
if 'summary' in alert['annotations']: if 'summary' in alert['annotations']: