Skip to content

Instantly share code, notes, and snippets.

@mpurzynski
Last active March 21, 2017 00:01
Show Gist options
  • Select an option

  • Save mpurzynski/761cbfe160f3a15c21e95adeede513e9 to your computer and use it in GitHub Desktop.

Select an option

Save mpurzynski/761cbfe160f3a15c21e95adeede513e9 to your computer and use it in GitHub Desktop.
def onMessage(self, message):
# here is where you do something with the incoming alert message
if 'summary' in message.keys() :
headers = {
'Content-type': 'application/json',
}
payload = json.dumps({
"service_key": "{0}".format(self.options.serviceKey),
"incident_key": "Possible Intrusion",
"event_type": "trigger",
"description": "{0}".format(message['summary']),
"client": "mozdef",
"client_url": "https://mozdef.private.scl3.mozilla.com/alert/{0}".format(message['events'][0]['documentsource']['alerts'][0]['id']),
"details": message['events'],
"contexts": [
{
"type": "link",
"href": "{0}".format(self.options.docs[message['category']]),
"text": "View runbook on mana"
}
]
})
r = requests.post(
'https://events.pagerduty.com/generic/2010-04-15/create_event.json',
headers=headers,
data=payload,
)
print r.status_code
print r.text
# you can modify the message if needed
# plugins registered with lower (>2) priority
# will receive the message and can also act on it
# but even if not modified, you must return it
return message
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment