-
Notifications
You must be signed in to change notification settings - Fork 117
PagerDuty incident resolution support #131
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| import json | ||
| import hashlib | ||
|
|
||
| from tornado import gen, httpclient as hc | ||
|
|
||
|
|
@@ -30,27 +31,47 @@ def notify(self, level, alert, value, target=None, ntype=None, rule=None): | |
| LOGGER.debug("Handler (%s) %s", self.name, level) | ||
| message = self.get_short(level, alert, value, target=target, ntype=ntype, rule=rule) | ||
| LOGGER.debug('message1:%s', message) | ||
| if level == 'normal': | ||
| event_type = 'resolve' | ||
|
|
||
| # Extract unique alert identifiers | ||
| alert_name = message[message.find("<")+1:message.find(">")] | ||
| alert_metric = message[message.find("(")+1:message.find(")")] | ||
|
|
||
| # Generate hash | ||
| h = hashlib.md5() | ||
| h.update(alert_name) | ||
| h.update(alert_metric) | ||
|
|
||
| # Use hash as incident key to support resolution | ||
| incident_key = h.hexdigest() | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there any benefit to |
||
|
|
||
| if level == 'critical': | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like this logic has has been lost, can you re-add it? |
||
| event_type = "trigger" | ||
| elif level == 'warning': | ||
| event_type = "trigger" | ||
| elif level == 'normal': | ||
| event_type = "resolve" | ||
| else: | ||
| event_type = 'trigger' | ||
| return | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a reason you're changing this? |
||
|
|
||
| headers = { | ||
| "Content-type": "application/json", | ||
| } | ||
|
|
||
| data = { | ||
| data = { | ||
| "incident_key": incident_key, | ||
| "service_key": self.service_key, | ||
| "description": message, | ||
| "event_type": event_type, | ||
| "description": message, | ||
| "details": message, | ||
| "incident_key": rule['raw'] if rule is not None else 'graphite connect error', | ||
| "client": 'graphite-beacon', | ||
| "client_url": None | ||
| } | ||
|
|
||
| yield self.client.fetch( | ||
| "https://events.pagerduty.com/generic/2010-04-15/create_event.json", | ||
| body=json.dumps(data), | ||
| headers=headers, | ||
| method='POST' | ||
| ) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you use the context passed into the function for the alert name and metric name instead of pulling it out of the
message?