Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 26 additions & 5 deletions graphite_beacon/handlers/pagerduty.py
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

Expand Down Expand Up @@ -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(">")]
Copy link
Copy Markdown
Collaborator

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?

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()
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any benefit to md5ing these? Why not just do "{alert_name:alert_metric}"?


if level == 'critical':
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if level in ['critical', 'warning']:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The 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
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The 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'
)