2016-02-03 18:52:24 +00:00
|
|
|
"use strict";
|
|
|
|
|
2016-02-04 10:33:04 +00:00
|
|
|
var https = require("https");
|
2016-02-03 18:52:24 +00:00
|
|
|
|
|
|
|
var DATADOG_API_KEY = '64e56d39dfdd7f2bbf06f09100d51a18';
|
2016-02-04 10:33:04 +00:00
|
|
|
var DATADOG_API_URL = 'https://app.datadoghq.com';
|
2016-02-03 18:52:24 +00:00
|
|
|
|
|
|
|
module.exports = releaseEvent;
|
|
|
|
|
|
|
|
if (!module.parent) {
|
|
|
|
var argv = process.argv;
|
2016-02-04 10:33:04 +00:00
|
|
|
releaseEvent(argv[2], argv[3], argv[4], argv[5], function(err) {
|
|
|
|
if (err) {
|
|
|
|
console.error("Error posting release event to datadog" + err.message);
|
|
|
|
process.exit(1);
|
|
|
|
}
|
|
|
|
process.exit(0);
|
|
|
|
});
|
2016-02-03 18:52:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function datadogEvent(msg, callback) {
|
2016-02-04 10:33:04 +00:00
|
|
|
|
|
|
|
var payload = JSON.stringify(msg);
|
|
|
|
|
|
|
|
var req = https.request({
|
|
|
|
hostname: "app.datadoghq.com",
|
|
|
|
port: 443,
|
|
|
|
path: "/api/v1/events?api_key=" + encodeURIComponent(DATADOG_API_KEY),
|
|
|
|
method: "POST",
|
|
|
|
headers: {
|
|
|
|
"Accept": "application/json",
|
|
|
|
"Content-Type": "application/json",
|
|
|
|
"Content-Length": payload.length
|
|
|
|
}
|
|
|
|
}, function(res) {
|
|
|
|
if (res.statusCode >= 400)
|
|
|
|
return callback(new Error("request failed with status code " + res.statusCode));
|
|
|
|
|
|
|
|
callback();
|
|
|
|
});
|
|
|
|
|
|
|
|
req.on("error", function(e) {
|
|
|
|
callback(e);
|
|
|
|
});
|
|
|
|
|
|
|
|
req.write(payload);
|
|
|
|
req.end();
|
2016-02-03 18:52:24 +00:00
|
|
|
}
|
|
|
|
|
2016-02-04 10:33:04 +00:00
|
|
|
function releaseEvent(application, mode, version, pattern, callback) {
|
2016-02-03 18:52:24 +00:00
|
|
|
datadogEvent({
|
|
|
|
title: 'Release: ' + application + ' version ' + version + ' to "' + pattern + '"',
|
|
|
|
tags: [
|
|
|
|
'release',
|
|
|
|
'application:' + application,
|
|
|
|
'mode:' + mode,
|
|
|
|
'version:' + version,
|
|
|
|
'pattern:' + pattern
|
|
|
|
]
|
2016-02-04 10:33:04 +00:00
|
|
|
}, callback);
|
2016-02-03 18:52:24 +00:00
|
|
|
}
|