-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
36 lines (30 loc) · 1.01 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
var request = require('request');
var Hoek = require('hoek');
var apiKey = process.env.OPSGENIE_API_KEY;
var apiUrl = process.env.OPSGENIE_API_URL || 'https://api.opsgenie.com';
var policy = process.env.OPSGENIE_POLICY;
Hoek.assert(apiKey, 'Opsgenie api key (env OPSGENIE_API_KEY) is required');
Hoek.assert(policy, 'Opsgenie policy name (env OPSGENIE_POLICY) is required');
module.exports = {
trigger: function (mute) {
var operation = mute ? 'enable' : 'disable';
var muted = mute ? 'muted' : 'unmuted';
var req = {
method: 'POST',
url: apiUrl + '/v1/json/alert/policy/' + operation,
body: {
apiKey: apiKey,
name: policy
},
json: true
};
request(req, function (error, response, resp) {
if (!error && response.statusCode === 200 && resp.status === 'success') {
console.log('Alerting', muted, 'successfully');
process.exit(0);
}
console.error('Cannot', operation, 'alerting.', error || resp);
process.exit(1);
});
}
};