-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add new Opsgenie Alert API as AlertV2 and add new samples that uses t…
…his.
- Loading branch information
1 parent
89294b2
commit 30d8bb3
Showing
32 changed files
with
1,371 additions
and
13 deletions.
There are no files selected for viewing
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
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
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,62 +20,82 @@ function alert() { | |
* One of id or alias parameters should be specified with close alert request. | ||
* Alias option can only be used for open alerts | ||
* example data: {id: 'id1'} or {alias: 'alias1'} etc. | ||
* | ||
* @deprecated | ||
*/ | ||
close: function (data, config, cb) { | ||
api.post(this.baseURL + 'close', data, config, cb); | ||
}, | ||
/** | ||
* Count alerts request is used to counts alerts in OpsGenie | ||
* | ||
* @deprecated | ||
*/ | ||
count: function (data, config, cb) { | ||
api.get(this.baseURL + 'count', data, config, cb); | ||
}, | ||
/** | ||
* data should be either {id: 'id1'} or {alias: 'alias1'} | ||
* | ||
* @deprecated | ||
*/ | ||
listAlertNotes: function (data, config, cb) { | ||
api.get(this.baseURL + 'note', data, config, cb); | ||
}, | ||
/** | ||
* data should be either {id: 'id1'} or {alias: 'alias1'} | ||
* | ||
* @deprecated | ||
*/ | ||
listAlertLogs: function (data, config, cb) { | ||
api.get(this.baseURL + 'log', data, config, cb); | ||
}, | ||
/** | ||
* data should be either {id: 'id1'} or {alias: 'alias1'} | ||
* | ||
* @deprecated | ||
*/ | ||
listAlertRecipients: function (data, config, cb) { | ||
api.get(this.baseURL + 'recipient', data, config, cb); | ||
}, | ||
/** | ||
* data should be either {id: 'id1'} or {alias: 'alias1'} | ||
* | ||
* @deprecated | ||
*/ | ||
acknowledge: function (data, config, cb) { | ||
api.post(this.baseURL + 'acknowledge', data, config, cb); | ||
}, | ||
/** | ||
* One of id or alias parameters should be specified with snooze alert request. Alias option can only be used for open alerts | ||
* Also, endDate param should be provided - "endDate": ""2016-01-28 08:00"" | ||
* | ||
* @deprecated | ||
*/ | ||
snooze: function (data, config, cb) { | ||
api.post(this.baseURL + 'snooze', data, config, cb); | ||
}, | ||
/** | ||
* data should be either {id: 'id1'} or {alias: 'alias1'} | ||
* | ||
* @deprecated | ||
*/ | ||
renotify: function (data, config, cb) { | ||
api.post(this.baseURL + 'renotify', data, config, cb); | ||
}, | ||
/** | ||
* data should be either {id: 'id1'} or {alias: 'alias1'} | ||
* | ||
* @deprecated | ||
*/ | ||
takeOwnership: function (data, config, cb) { | ||
api.post(this.baseURL + 'takeOwnership', data, config, cb); | ||
}, | ||
/** | ||
* One of id or alias parameters should be specified with assign request. Alias option can only be used for open alerts | ||
* Also, owner param should be provided "owner":"[email protected]" | ||
* | ||
* @deprecated | ||
*/ | ||
assign: function (data, config, cb) { | ||
api.post(this.baseURL + 'assign', data, config, cb); | ||
|
@@ -84,6 +104,8 @@ function alert() { | |
* Add team request is used to add new teams to alerts in OpsGenie. It takes the following parameters | ||
* One of id or alias parameters should be specified with add team request. Alias option can only be used for open alerts | ||
* Also, the new team that will be added should be added to parameters as "team": "operations" | ||
* | ||
* @deprecated | ||
*/ | ||
addTeam: function (data, config, cb) { | ||
api.post(this.baseURL + 'team', data, config, cb); | ||
|
@@ -92,6 +114,8 @@ function alert() { | |
* Add recipient request is used to add new recipients(user or group) to alerts in OpsGenie | ||
* One of id or alias parameters should be specified with add recipient request. Alias option can only be used for open alerts | ||
* Also, the new recipient that will be added as "recipient":"[email protected]" | ||
* | ||
* @deprecated | ||
*/ | ||
addRecipient: function (data, config, cb) { | ||
api.post(this.baseURL + 'recipient', data, config, cb); | ||
|
@@ -100,6 +124,8 @@ function alert() { | |
* Add note request is used to add notes to alerts in OpsGenie | ||
* One of id or alias parameters should be specified with add note request. Alias option can only be used for open alerts | ||
* Also, note param is mandatory as "note": "custom note" | ||
* | ||
* @deprecated | ||
*/ | ||
addNote: function (data, config, cb) { | ||
api.post(this.baseURL + 'note', data, config, cb); | ||
|
@@ -109,6 +135,7 @@ function alert() { | |
* One of id or alias parameters should be specified with add tags request. Alias option can only be used for open alerts | ||
* Also, tags param is mandatory as "tags": "emergency, delay" | ||
* | ||
* @deprecated | ||
*/ | ||
addTags: function (data, config, cb) { | ||
api.post(this.baseURL + 'tags', data, config, cb); | ||
|
@@ -117,6 +144,8 @@ function alert() { | |
* Remove tags request is used to remove tags from alerts in OpsGenie | ||
* One of id or alias parameters should be specified with add tags request. Alias option can only be used for open alerts | ||
* Also, tags param is mandatory as "tags": "emergency, delay" | ||
* | ||
* @deprecated | ||
*/ | ||
removeTags: function (data, config, cb) { | ||
if (data.tags === undefined) { | ||
|
@@ -129,6 +158,7 @@ function alert() { | |
* One of id or alias parameters should be specified with add details request. Alias option can only be used for open alerts | ||
* Also, details param is mandatory as "details": {"prop1" : "val1", "prop2" : "val2"} | ||
* | ||
* @deprecated | ||
*/ | ||
addDetails: function (data, config, cb) { | ||
api.post(this.baseURL + 'details', data, config, cb); | ||
|
@@ -137,6 +167,8 @@ function alert() { | |
* Remove details request is used to remove details from alerts in OpsGenie | ||
* One of id or alias parameters should be specified with add details request. Alias option can only be used for open alerts | ||
* Also, details param is mandatory as "keys" : { "prop1", "prop2" } | ||
* | ||
* @deprecated | ||
*/ | ||
removeDetails: function (data, config, cb) { | ||
if (data.keys === undefined) { | ||
|
@@ -148,18 +180,12 @@ function alert() { | |
* Execute action request is used to execute predefined actions on alerts in OpsGenie | ||
* One of id or alias parameters should be specified with execute action request. Alias option can only be used for open alerts | ||
* Also, action param is mandatory as "action": "acknowledge" | ||
* | ||
* @deprecated | ||
*/ | ||
executeAction: function (data, config, cb) { | ||
api.post(this.baseURL + 'executeAction', data, config, cb); | ||
} | ||
/** | ||
* Attach file request is used to attach files to alerts in OpsGenie. It should be sent as multipart HTTP request | ||
* One of id or alias parameters should be specified with attach file request. Alias option can only be used for open alerts | ||
* TODO: will be implemented | ||
*/ | ||
/*attachFile: function (data, config, cb) { | ||
api.post(this.baseURL + 'attachFile', data, config, cb); | ||
}*/ | ||
}; | ||
ops = operations.attach(ops, defaultOperations); | ||
return ops; | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
"use strict"; | ||
|
||
var utils = require('./utils'); | ||
var configuration = require('./configure'); | ||
var request = require('requestretry'); | ||
var qs = require('querystring'); | ||
|
||
exports.get = function executeGetRequest(path, http_options, cb) { | ||
execute('GET', path, null, http_options, cb); | ||
}; | ||
|
||
exports.post = function executePostRequest(path, data, http_options, cb) { | ||
execute('POST', path, data, http_options, cb); | ||
}; | ||
|
||
exports.delete = function executeDeleteRequest(path, http_options, cb) { | ||
execute('DELETE', path, null, http_options, cb); | ||
}; | ||
|
||
exports.patch = function executePostRequest(path, data, http_options, cb) { | ||
execute('PATCH', path, data, http_options, cb); | ||
}; | ||
|
||
function setRetryPolicy() { | ||
request.defaults({ | ||
json: true, | ||
maxAttempts: configuration.default_options.maxAttempts, | ||
retryDelay: configuration.default_options.retryDelay, | ||
retryStrategy: configuration.default_options.retryStrategy | ||
}); | ||
} | ||
|
||
function getHost() { | ||
return configuration.default_options.host; | ||
} | ||
|
||
function getBasicHttpOptions(http_options) { | ||
var apiKey = configuration.default_options.api_key; | ||
configuration.default_http_options.headers['Authorization'] = 'GenieKey ' + apiKey; | ||
|
||
if (!http_options) { | ||
http_options = configuration.default_http_options; | ||
} else { | ||
http_options = utils.merge(http_options, configuration.default_http_options, true); | ||
} | ||
|
||
http_options.host = getHost(); | ||
return http_options; | ||
} | ||
|
||
function getPathWithIdentifier(path, params, actionPath) { | ||
var pathParams; | ||
var actPath = actionPath ? actionPath : ""; | ||
|
||
if (typeof params !== 'string') { | ||
pathParams = params["identifier"] + actPath; | ||
if (params["identifierType"] != null) { | ||
pathParams += "?identifierType=" + params["identifierType"]; | ||
} | ||
} else { | ||
pathParams = params; | ||
} | ||
|
||
return params ? (path + pathParams) : (path); | ||
} | ||
|
||
exports.getPath = function (path, params, actionPath) { | ||
return getPathWithIdentifier(path, params, actionPath) | ||
}; | ||
|
||
exports.getPathWithData = function (path, params, actionPath, data) { | ||
var pathWithData = getPathWithIdentifier(path, params, actionPath); | ||
var dataParam = ""; | ||
if (typeof data !== 'string') { | ||
dataParam = qs.stringify(data); | ||
} else { | ||
dataParam = data; | ||
} | ||
|
||
return data ? (pathWithData + "&" + dataParam) : pathWithData; | ||
}; | ||
|
||
exports.getPathWithListParams = function (path, params) { | ||
if (typeof params !== 'string') { | ||
params = qs.stringify(params); | ||
} | ||
|
||
return params ? (path + "?" + params) : path; | ||
}; | ||
|
||
function execute(method, path, data, http_options, cb) { | ||
setRetryPolicy(); | ||
if (typeof http_options === "function") { | ||
cb = http_options; | ||
http_options = null; | ||
} | ||
|
||
http_options = getBasicHttpOptions(http_options); | ||
http_options.method = method; | ||
|
||
if (method === 'GET' || method === 'DELETE') { | ||
http_options.uri = http_options.host + path; | ||
http_options.body = null; | ||
} else { | ||
http_options.uri = http_options.host + path; | ||
http_options.body = data; | ||
http_options.json = true | ||
} | ||
request(http_options, function (error, response, body) { | ||
handleResponse(error, response, body, cb) | ||
}); | ||
} | ||
|
||
function handleResponse(error, response, body, cb) { | ||
if (error) { | ||
console.log('Problem with request: ', error); | ||
cb(error, null); | ||
return; | ||
} | ||
|
||
var err = null, res = null; | ||
if (response.statusCode < 200 || response.statusCode >= 300) { | ||
if (process.env.NODE_ENV === 'development') { | ||
err.response_stringified = JSON.stringify(response); | ||
} | ||
err = JSON.parse(body); | ||
err.httpStatusCode = response.statusCode; | ||
response = null; | ||
} else { | ||
var bodyJson = JSON.stringify(body); | ||
res = JSON.parse(bodyJson); | ||
} | ||
|
||
cb(err, res); | ||
} | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
"use strict"; | ||
|
||
require('../configure'); | ||
var opsgenie = require('../../'); | ||
|
||
|
||
|
||
opsgenie.configure({ | ||
'host': 'https://api.opsgenie.com', | ||
'api_key': "yourApiKey" | ||
}); | ||
|
||
var acknowledge_alert_identifier = { | ||
identifier: "5", // should be custom to your created alert | ||
identifierType : "tiny" | ||
}; | ||
|
||
var acknowledge_alert_data = { | ||
note : "some note for acknowledge action", | ||
user : "[email protected]", | ||
source : "source of the acknowledge request" | ||
}; | ||
|
||
opsgenie.alertV2.acknowledge(acknowledge_alert_identifier, acknowledge_alert_data, function (error, result) { | ||
if (error) { | ||
console.error(error); | ||
} else { | ||
console.log("Acknowledge Alert Response"); | ||
console.log(result); | ||
} | ||
}); |
Oops, something went wrong.