Skip to content

Instantly share code, notes, and snippets.

@serhatcan
Last active July 29, 2016 05:57
Show Gist options
  • Save serhatcan/b20a17b4920c62982e6f95596ddb0d15 to your computer and use it in GitHub Desktop.
Save serhatcan/b20a17b4920c62982e6f95596ddb0d15 to your computer and use it in GitHub Desktop.
OpsGenie Github Integration - Create alert when issue opened
'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