-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/5_forwardingApi' into 0.0.7
- Loading branch information
Showing
8 changed files
with
202 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
"use strict"; | ||
|
||
const api = require('./../restApi'); | ||
|
||
/** | ||
* https://docs.opsgenie.com/docs/forwarding-rule-api | ||
* | ||
* @returns {{get: get, create: create, list: list, delete: delete, updateRule: updateRule}} | ||
*/ | ||
function forwardingV2() { | ||
let baseURL = '/v2/forwarding-rules/'; | ||
|
||
return { | ||
/** | ||
* https://docs.opsgenie.com/docs/forwarding-rule-api | ||
* Also, you can check /samples/forwardingV2/create.js for a complete example. | ||
* | ||
* @param data | ||
* @param config | ||
* @param cb | ||
*/ | ||
create: function (data, config, cb) { | ||
api.post(baseURL, data, config, cb) | ||
}, | ||
|
||
/** | ||
* Get forwarding rule by identifier | ||
* https://docs.opsgenie.com/docs/forwarding-rule-api#section--get-forwarding-rule- | ||
* One of id, tinyId or alias parameters should be specified with get alert request as identifier. | ||
* Alias option can only be used for open alerts | ||
* example identifier objects: | ||
* {identifier : "123", identifierType : "tiny"} | ||
* {identifier : "123-23-123", identifierType : "id"} | ||
* {identifier : "alertAlias", identifierType : "alias"} | ||
* | ||
* @param identifier | ||
* @param config | ||
* @param cb | ||
*/ | ||
get: function (identifier, config, cb) { | ||
let path = api.getPath(baseURL, identifier, null); | ||
api.get(path, config, cb) | ||
}, | ||
|
||
/** | ||
* Delete a forwarding rule | ||
* https://docs.opsgenie.com/docs/forwarding-rule-api#section--delete-forwarding-rule- | ||
* | ||
* @param identifier | ||
* @param config | ||
* @param cb | ||
*/ | ||
delete: function (identifier, config, cb) { | ||
let path = api.getPath(baseURL, identifier, null); | ||
api.delete(path, config, cb) | ||
}, | ||
|
||
/** | ||
* https://docs.opsgenie.com/docs/forwarding-rule-api#section--list-forwarding-rules- | ||
* | ||
* @param params | ||
* @param config | ||
* @param cb | ||
*/ | ||
list: function (params, config, cb) { | ||
let path = api.getPathWithListParams(baseURL, params); | ||
api.get(path, config, cb) | ||
}, | ||
|
||
/** | ||
* https://docs.opsgenie.com/docs/forwarding-rule-api#section--delete-forwarding-rule- | ||
* @param identifier | ||
* @param data | ||
* @param config | ||
* @param cb | ||
*/ | ||
updateRule: function (identifier, data, config, cb) { | ||
let path = api.getPath(baseURL, identifier, null); | ||
api.put(path, data, config, cb); | ||
}, | ||
}; | ||
} | ||
|
||
module.exports = forwardingV2; |
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
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,30 @@ | ||
"use strict"; | ||
|
||
let opsgenie = require('../../'); | ||
require('../configure'); | ||
|
||
let todaysDate = new Date(); | ||
todaysDate.setDate(todaysDate.getDate() + 1); | ||
let startDate = todaysDate.toISOString(); | ||
todaysDate.setDate(todaysDate.getDate() + 5); | ||
let endDate = todaysDate.toISOString(); | ||
|
||
let create_rule_json = { | ||
fromUser: { | ||
id: 'c1754eea-7f80-4126-8a64-a55c42439947' | ||
}, | ||
toUser: { | ||
id: '830e4738-fc50-4bd0-b789-00fc0db76418' | ||
}, | ||
startDate: startDate, | ||
endDate: endDate | ||
}; | ||
|
||
opsgenie.forwardingV2.create(create_rule_json, function (error, alert) { | ||
if (error) { | ||
console.error(error); | ||
} else { | ||
console.log("Create Forwarding Rule Response:"); | ||
console.log(alert); | ||
} | ||
}); |
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,18 @@ | ||
"use strict"; | ||
|
||
let opsgenie = require('../../'); | ||
require('../configure'); | ||
|
||
let delete_rule_identifier = { | ||
identifier: "7b55b16e-3de7-44b1-8c04-31e5966a7a31", | ||
identifierType : "id" | ||
}; | ||
|
||
opsgenie.forwardingV2.delete(delete_rule_identifier, function (error, result) { | ||
if (error) { | ||
console.error(error); | ||
} else { | ||
console.log("Delete Forwarding Rule Response:"); | ||
console.log(result); | ||
} | ||
}); |
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,18 @@ | ||
"use strict"; | ||
|
||
let opsgenie = require('../../'); | ||
require('../configure'); | ||
|
||
let get_rule_identifier = { | ||
identifier: "ebb3c4e0-b9b9-4b6d-89d8-6b10032719db", | ||
identifierType : "id" | ||
}; | ||
|
||
opsgenie.forwardingV2.get(get_rule_identifier, function (error, rule) { | ||
if (error) { | ||
console.error(error); | ||
} else { | ||
console.log("Get Rule Response for id: "); | ||
console.log(rule); | ||
} | ||
}); |
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,17 @@ | ||
"use strict"; | ||
|
||
let opsgenie = require('../../'); | ||
require('../configure'); | ||
|
||
let list_params = { | ||
order : "desc" | ||
}; | ||
|
||
opsgenie.forwardingV2.list(list_params, function (error, rules) { | ||
if (error) { | ||
console.error(error); | ||
} else { | ||
console.log("List Rules Response"); | ||
console.log(rules); | ||
} | ||
}); |
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,30 @@ | ||
"use strict"; | ||
|
||
let opsgenie = require('../../'); | ||
require('../configure'); | ||
|
||
let todaysDate = new Date(); | ||
todaysDate.setDate(todaysDate.getDate() + 1); | ||
let startDate = todaysDate.toISOString(); | ||
todaysDate.setDate(todaysDate.getDate() + 14); | ||
let endDate = todaysDate.toISOString(); | ||
|
||
let update_rule_json = { | ||
fromUser: { | ||
id: 'c1754eea-7f80-4126-8a64-a55c42439947' | ||
}, | ||
toUser: { | ||
id: '830e4738-fc50-4bd0-b789-00fc0db76418' | ||
}, | ||
startDate: startDate, | ||
endDate: endDate | ||
}; | ||
|
||
opsgenie.forwardingV2.updateRule("ebb3c4e0-b9b9-4b6d-89d8-6b10032719db", update_rule_json, function (error, rule) { | ||
if (error) { | ||
console.error(error); | ||
} else { | ||
console.log("Update Rule Response"); | ||
console.log(rule); | ||
} | ||
}); |