-
Notifications
You must be signed in to change notification settings - Fork 2
/
ServiceNowIncidentHandler.js
55 lines (50 loc) · 1.39 KB
/
ServiceNowIncidentHandler.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/**
*
* main() will be run when you invoke this action
*
* @param Cloud Functions actions accept a single parameter, which must be a JSON object.
*
* @return The output of this action, which must be a JSON object.
*
*/
var request = require("request");
function main(params) {
var action_name = process.env.__OW_ACTION_NAME;
if(!params.error) {
return {message: 'input is not an error.'}
}
console.log(params.error);
/*
incidentError = {
"action_name": process.env.__OW_ACTION_NAME,
"raised_time": new Date(),
"code" : '1234',
"message": "there is an error"
}
*/
var options = {
url: "https://cms3prod.service-now.com/api/now/table/incident",
body: {
short_description: "this is incident automatically generated for "+ params.error.action_name,
description: params.error.action_name + " : [" + params.error.code + "] : " + params.error.message
},
method: 'POST',
auth: {
user: '[email protected]',
pass: 's3rv3rL3ss'
},
json: true
};
return new Promise(function(resolve, reject) {
request(options, function(err, resp) {
if (err) {
reject({
error: err
})
}
resolve({
payload: resp
});
});
});
};