Last active
July 29, 2016 05:57
-
-
Save serhatcan/b20a17b4920c62982e6f95596ddb0d15 to your computer and use it in GitHub Desktop.
OpsGenie Github Integration - Create alert when issue opened
This file contains hidden or 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
'use strict'; | |
console.log('Loading function'); | |
let opsgenie = require('opsgenie-sdk'); | |
opsgenie.configure({ | |
'api_key': 'e18d30fb-9bfd-41f6-a6b9-e0a940ec8ce4' | |
}); | |
exports.handler = (event, context, callback) => { | |
console.log('Received event:', event); | |
const action = event.action; | |
switch (action) { | |
case 'opened': | |
var create_alert_json = { | |
"message": event.issue.title | |
}; | |
opsgenie.alert.create(create_alert_json, function (error, alert) { | |
if (error) { | |
callback(new Error(error)); | |
} else { | |
callback(null, "Alert created with id: " + alert.id); | |
} | |
}); | |
break; | |
default: | |
callback(new Error('Unrecognized action "${action}"')); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment