Created
December 20, 2016 21:45
-
-
Save sunnygleason/681b2eba0be409dedaad96e2457ae6cf to your computer and use it in GitHub Desktop.
PubNub DevOps BLOCK w/ PagerDuty
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
export default (request) => { | |
const xhr = require('xhr'); | |
const integrationKey = 'YOUR_INTEGRATION_KEY'; | |
const apiUrl = 'https://events.pagerduty.com/generic/2010-04-15/create_event.json'; | |
const description = request.message.description; | |
const httpOptions = { | |
method: 'POST', | |
body: JSON.stringify({ | |
service_key: integrationKey, | |
event_type: 'trigger', | |
incident_key: "incident_" + parseInt(Math.random() * 10000), | |
description: description | |
}) | |
}; | |
return xhr.fetch(apiUrl, httpOptions) | |
.then((response) => { | |
console.log(response); | |
request.message.result = response; | |
return request.ok(); | |
}) | |
.catch((e) => { | |
console.error(e); | |
return request.ok(); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment