Skip to content

Commit 8c34fff

Browse files
Merge pull request #28 from opsgenie/Heartbeat_API
Heartbeat API support in NodeJS SDK
2 parents 31dfc65 + a75bc8a commit 8c34fff

File tree

10 files changed

+174
-2
lines changed

10 files changed

+174
-2
lines changed

lib/heartbeat/Heartbeat.js

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
"use strict";
2+
3+
const restApi = require('../restApi');
4+
var operations = require('../operations');
5+
6+
function heartbeat() {
7+
let baseURL = '/v2/heartbeats/';
8+
let ops = {
9+
baseURL: baseURL,
10+
/**
11+
* @param data
12+
* @param config
13+
* @param cb
14+
*/
15+
create: function (data, config, cb) {
16+
restApi.post(baseURL ,data, config, cb);
17+
},
18+
list: function (data, config, cb) {
19+
restApi.get(baseURL, config, cb);
20+
},
21+
delete: function (data, config, cb) {
22+
let path = restApi.getPath(baseURL, data, null);
23+
restApi.delete(path, config, cb);
24+
},
25+
get: function (data, config, cb) {
26+
let path = restApi.getPath(baseURL, data, null);
27+
restApi.get(path, config, cb);
28+
},
29+
update: function (identifier, data, config, cb) {
30+
let path = restApi.getPath(this.baseURL, identifier, null);
31+
restApi.patch(path, data, config, cb)
32+
},
33+
ping: function (identifier, data, config, cb) {
34+
let path = restApi.getPath(this.baseURL, identifier, "/ping");
35+
restApi.get(path, data, config, cb)
36+
},
37+
enable: function (identifier, config, cb) {
38+
let path = restApi.getPath(this.baseURL, identifier, "/enable");
39+
restApi.post(path,null, config, cb)
40+
},
41+
disable: function (identifier, config, cb) {
42+
let path = restApi.getPath(this.baseURL, identifier, "/disable");
43+
restApi.post(path, null, config, cb)
44+
},
45+
};
46+
return ops;
47+
}
48+
49+
module.exports = heartbeat;

lib/opsgenie.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ module.exports = function () {
2121
user: require('./resources/User')(),
2222
group: require('./resources/Group')(),
2323
team: require('./resources/Team')(),
24-
incident: require('./incident/Incident')()
24+
incident: require('./incident/Incident')(),
25+
heartbeat: require('./heartbeat/Heartbeat')()
2526
};
2627
};

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "opsgenie-sdk",
3-
"version": "0.4.7",
3+
"version": "0.4.8",
44
"description": "OpsGenie Node.js SDK",
55
"main": "./index.js",
66
"scripts": {

samples/heartbeat/create.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
"use strict";
2+
3+
require('../configure');
4+
var opsgenie = require('../../');
5+
6+
var get_heartbeat_identifier = {
7+
name : "HeartbeatName",
8+
description: "Sample heartbeat description",
9+
intervalUnit : "minutes",
10+
interval : 10,
11+
enabled : true,
12+
ownerTeam: {
13+
name:"Team 1"
14+
}
15+
};
16+
17+
opsgenie.heartbeat.create(get_heartbeat_identifier, function (error, heartbeat) {
18+
if (error) {
19+
console.error(error);
20+
} else {
21+
console.log("heartbeat created");
22+
console.log(JSON.stringify(heartbeat));
23+
}
24+
});

samples/heartbeat/delete.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
"use strict";
2+
3+
require('../configure');
4+
var opsgenie = require('../../');
5+
6+
let identifier = {
7+
identifier: "HeartbeatName", // should be custom to your created incident
8+
};
9+
10+
opsgenie.heartbeat.delete(identifier, function (error, heartbeat) {
11+
if (error) {
12+
console.error(error);
13+
} else {
14+
console.log("heartbeat deleted");
15+
console.log(JSON.stringify(heartbeat));
16+
}
17+
});

samples/heartbeat/disable.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
"use strict";
2+
3+
require('../configure');
4+
var opsgenie = require('../../');
5+
6+
let identifier = {
7+
identifier: "HeartbeatName", // should be custom to your created incident
8+
};
9+
10+
opsgenie.heartbeat.disable(identifier, function (error, heartbeat) {
11+
if (error) {
12+
console.error(error);
13+
} else {
14+
console.log("heartbeat disabled");
15+
console.log(heartbeat);
16+
}
17+
});

samples/heartbeat/enable.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
"use strict";
2+
3+
require('../configure');
4+
var opsgenie = require('../../');
5+
6+
let identifier = {
7+
identifier: "HeartbeatName", // should be custom to your created incident
8+
};
9+
10+
opsgenie.heartbeat.enable(identifier, function (error, heartbeat) {
11+
if (error) {
12+
console.error(error);
13+
} else {
14+
console.log("heartbeat enabled");
15+
console.log(heartbeat);
16+
}
17+
});

samples/heartbeat/get.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
"use strict";
2+
3+
require('../configure');
4+
var opsgenie = require('../../');
5+
6+
let identifier = {
7+
identifier: "HeartbeatName", // should be custom to your created incident
8+
};
9+
10+
opsgenie.heartbeat.get(identifier, function (error, heartbeat) {
11+
if (error) {
12+
console.error(error);
13+
} else {
14+
console.log("heartbeat information");
15+
console.log(heartbeat);
16+
}
17+
});

samples/heartbeat/list.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
"use strict";
2+
3+
require('../configure');
4+
var opsgenie = require('../../');
5+
6+
opsgenie.heartbeat.list(null, function (error, heartbeat) {
7+
if (error) {
8+
console.error(error);
9+
} else {
10+
console.log("heartbeat list");
11+
console.log(JSON.stringify(heartbeat));
12+
}
13+
});

samples/heartbeat/ping.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
"use strict";
2+
3+
require('../configure');
4+
var opsgenie = require('../../');
5+
6+
let identifier = {
7+
identifier: "HeartbeatName", // should be custom to your created incident
8+
};
9+
10+
opsgenie.heartbeat.ping(identifier, function (error, heartbeat) {
11+
if (error) {
12+
console.error(error);
13+
} else {
14+
console.log("heartbeat pinged");
15+
console.log(heartbeat);
16+
}
17+
});

0 commit comments

Comments
 (0)