Skip to content

Commit

Permalink
Merge pull request #28 from opsgenie/Heartbeat_API
Browse files Browse the repository at this point in the history
Heartbeat API support in NodeJS SDK
  • Loading branch information
prakhar-mudaiya authored May 4, 2021
2 parents 31dfc65 + a75bc8a commit 8c34fff
Show file tree
Hide file tree
Showing 10 changed files with 174 additions and 2 deletions.
49 changes: 49 additions & 0 deletions lib/heartbeat/Heartbeat.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
"use strict";

const restApi = require('../restApi');
var operations = require('../operations');

function heartbeat() {
let baseURL = '/v2/heartbeats/';
let ops = {
baseURL: baseURL,
/**
* @param data
* @param config
* @param cb
*/
create: function (data, config, cb) {
restApi.post(baseURL ,data, config, cb);
},
list: function (data, config, cb) {
restApi.get(baseURL, config, cb);
},
delete: function (data, config, cb) {
let path = restApi.getPath(baseURL, data, null);
restApi.delete(path, config, cb);
},
get: function (data, config, cb) {
let path = restApi.getPath(baseURL, data, null);
restApi.get(path, config, cb);
},
update: function (identifier, data, config, cb) {
let path = restApi.getPath(this.baseURL, identifier, null);
restApi.patch(path, data, config, cb)
},
ping: function (identifier, data, config, cb) {
let path = restApi.getPath(this.baseURL, identifier, "/ping");
restApi.get(path, data, config, cb)
},
enable: function (identifier, config, cb) {
let path = restApi.getPath(this.baseURL, identifier, "/enable");
restApi.post(path,null, config, cb)
},
disable: function (identifier, config, cb) {
let path = restApi.getPath(this.baseURL, identifier, "/disable");
restApi.post(path, null, config, cb)
},
};
return ops;
}

module.exports = heartbeat;
3 changes: 2 additions & 1 deletion lib/opsgenie.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ module.exports = function () {
user: require('./resources/User')(),
group: require('./resources/Group')(),
team: require('./resources/Team')(),
incident: require('./incident/Incident')()
incident: require('./incident/Incident')(),
heartbeat: require('./heartbeat/Heartbeat')()
};
};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "opsgenie-sdk",
"version": "0.4.7",
"version": "0.4.8",
"description": "OpsGenie Node.js SDK",
"main": "./index.js",
"scripts": {
Expand Down
24 changes: 24 additions & 0 deletions samples/heartbeat/create.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
"use strict";

require('../configure');
var opsgenie = require('../../');

var get_heartbeat_identifier = {
name : "HeartbeatName",
description: "Sample heartbeat description",
intervalUnit : "minutes",
interval : 10,
enabled : true,
ownerTeam: {
name:"Team 1"
}
};

opsgenie.heartbeat.create(get_heartbeat_identifier, function (error, heartbeat) {
if (error) {
console.error(error);
} else {
console.log("heartbeat created");
console.log(JSON.stringify(heartbeat));
}
});
17 changes: 17 additions & 0 deletions samples/heartbeat/delete.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
"use strict";

require('../configure');
var opsgenie = require('../../');

let identifier = {
identifier: "HeartbeatName", // should be custom to your created incident
};

opsgenie.heartbeat.delete(identifier, function (error, heartbeat) {
if (error) {
console.error(error);
} else {
console.log("heartbeat deleted");
console.log(JSON.stringify(heartbeat));
}
});
17 changes: 17 additions & 0 deletions samples/heartbeat/disable.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
"use strict";

require('../configure');
var opsgenie = require('../../');

let identifier = {
identifier: "HeartbeatName", // should be custom to your created incident
};

opsgenie.heartbeat.disable(identifier, function (error, heartbeat) {
if (error) {
console.error(error);
} else {
console.log("heartbeat disabled");
console.log(heartbeat);
}
});
17 changes: 17 additions & 0 deletions samples/heartbeat/enable.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
"use strict";

require('../configure');
var opsgenie = require('../../');

let identifier = {
identifier: "HeartbeatName", // should be custom to your created incident
};

opsgenie.heartbeat.enable(identifier, function (error, heartbeat) {
if (error) {
console.error(error);
} else {
console.log("heartbeat enabled");
console.log(heartbeat);
}
});
17 changes: 17 additions & 0 deletions samples/heartbeat/get.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
"use strict";

require('../configure');
var opsgenie = require('../../');

let identifier = {
identifier: "HeartbeatName", // should be custom to your created incident
};

opsgenie.heartbeat.get(identifier, function (error, heartbeat) {
if (error) {
console.error(error);
} else {
console.log("heartbeat information");
console.log(heartbeat);
}
});
13 changes: 13 additions & 0 deletions samples/heartbeat/list.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
"use strict";

require('../configure');
var opsgenie = require('../../');

opsgenie.heartbeat.list(null, function (error, heartbeat) {
if (error) {
console.error(error);
} else {
console.log("heartbeat list");
console.log(JSON.stringify(heartbeat));
}
});
17 changes: 17 additions & 0 deletions samples/heartbeat/ping.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
"use strict";

require('../configure');
var opsgenie = require('../../');

let identifier = {
identifier: "HeartbeatName", // should be custom to your created incident
};

opsgenie.heartbeat.ping(identifier, function (error, heartbeat) {
if (error) {
console.error(error);
} else {
console.log("heartbeat pinged");
console.log(heartbeat);
}
});

0 comments on commit 8c34fff

Please sign in to comment.