forked from alerta/alerta-contrib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathalerta_mailgun.py
39 lines (33 loc) · 1.04 KB
/
alerta_mailgun.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
from alerta.models.alert import Alert
from alerta.webhooks import WebhookBase
import json
import datetime
class MailgunWebhook(WebhookBase):
def incoming(self, query_string, payload):
# Load variables from querystring
try:
environment = query_string['environment']
except:
environment = 'Production'
try:
severity = query_string['severity']
except:
severity = 'major'
try:
group = query_string['group']
except:
group = 'Email'
return Alert(
resource=payload['sender'],
type='Email Alert',
event=payload['subject'],
environment=environment,
severity=severity,
service=['Email'],
group=group,
text=payload['stripped-text'] or payload['body-plain'],
tags=[],
attributes={},
origin='Mailgun/{}'.format(payload['recipient']),
raw_data=json.dumps(payload, indent=4)
)