-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19 from votdev/improve_notification_parsing
Various improvements
- Loading branch information
Showing
5 changed files
with
49 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,35 @@ | |
|
||
def parse_notification(config, notification): | ||
""" | ||
Parse the Alertmanager notification. | ||
Example: | ||
{ | ||
"receiver": "storage", | ||
"status": "firing", | ||
"alerts": [ | ||
{ | ||
"status": "firing", | ||
"labels": { | ||
"alertname": "OSD down", | ||
"monitor": "ses", | ||
"oid": "1.3.6.1.4.1.50495.15.1.2.4.2", | ||
"severity": "warning", | ||
"type": "ceph_default" | ||
}, | ||
"annotations": { | ||
"description": "One or more OSDs down for more than 15 minutes." | ||
}, | ||
"startsAt": "2020-03-24T10:25:29.689078708-04:00", | ||
"endsAt": "0001-01-01T00:00:00Z", | ||
"generatorURL": "http://xxxx:9090/graph?g0.expr=..." | ||
} | ||
], | ||
... | ||
} | ||
See https://prometheus.io/docs/alerting/configuration/#webhook_config | ||
:param config: The configuration data. | ||
:type config: dict | ||
:param notification: | ||
|
@@ -54,9 +83,10 @@ def parse_notification(config, notification): | |
config['trap_default_oid']), | ||
'alertname': alertname, | ||
'status': alert['status'], | ||
'severity': labels.pop('severity'), | ||
'severity': labels.pop('severity', | ||
config['trap_default_severity']), | ||
'instance': labels.pop('instance', None), | ||
'job': labels.pop('job'), | ||
'job': labels.pop('job', None), | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
votdev
Author
Member
|
||
'description': summary or description, | ||
'labels': labels, | ||
'timestamp': timestamp, | ||
|
@@ -184,6 +214,7 @@ def defaults(): | |
'alert_oid_label': 'oid', | ||
'trap_oid_prefix': '1.3.6.1.4.1.50495.15', | ||
'trap_default_oid': '1.3.6.1.4.1.50495.15.1.2.1', | ||
'trap_default_severity': '', | ||
'host': '0.0.0.0', | ||
'port': 9099, | ||
'metrics': False | ||
|
I faced an issue where alertmanager json didn't contain "job" in one of alert for a kubernetes container. So ultimately it i received error like Key error. So i would like to understand use of 'None' parameter over here