Skip to content

Commit 7c16aac

Browse files
committed
Support different alerts format
1 parent 4603834 commit 7c16aac

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

local_plugins/alerrtmanagerr-webex/alerrtmanagerr.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,26 +10,34 @@ class AlerrtmanagerrWebex(BotPlugin):
1010
def alerrt(self, data, recipient, server):
1111
identifier = self.build_identifier(recipient + "@" + server)
1212
for alert in data['alerts']:
13+
if 'description' in alert['annotations']:
14+
title = alert['annotations']['description']
15+
else:
16+
title = alert['annotations']['message']
1317
self.send_card(
1418
to=identifier,
1519
summary='[{}] {}'.format(
1620
data['status'].upper(),
17-
data['commonLabels']['alertname']
21+
alert['labels']['alertname']
1822
),
19-
title=alert['annotations']['description'],
23+
title=title,
2024
)
2125

2226
@webhook('/alerrt-webex-room/<room>/')
2327
def alerrtt(self, data, room):
2428
identifier = self.query_room(room)
2529
for alert in data['alerts']:
30+
if 'description' in alert['annotations']:
31+
title = alert['annotations']['description']
32+
else:
33+
title = alert['annotations']['message']
2634
self.send_card(
2735
to=identifier,
2836
summary='[{}] {}'.format(
2937
data['status'].upper(),
30-
data['commonLabels']['alertname']
38+
alert['labels']['alertname']
3139
),
32-
title=alert['annotations']['description'],
40+
title=title,
3341
)
3442

3543
# Alertmanager sends this JSON per https://prometheus.io/docs/alerting/configuration/#webhook_config

0 commit comments

Comments
 (0)