-
Notifications
You must be signed in to change notification settings - Fork 5
/
monitor.js
146 lines (109 loc) · 3.99 KB
/
monitor.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
/*
* webMethods.io CLI
* Copyright 2022 Software AG
* Apache-2.0
*/
const request = require('./rest-fetch.js');
var domainName, username, password, timeout;
var prettyprint = false;
var url;
function debug(message) {
logger.debug("<MONITOR> " + message);
}
function help() {
return `
\x1b[4mMonitor\x1b[0m
\x1b[32mRetrieve Monitor Summary:\x1b[0m
$ node wmiocli.js
-d tenant.int-aws-us.webmethods.io
-u user
-p password
monitor from count startDate endDate projectsList workflowsList executionStatus
e.g.
monitor 1 10 2023-01-01 2023-01-10 myProject workflow1,workflow2 failed,timeout,stopped
monitor 11 10 2023-01-01 2023-01-10 myProject workflow1,workflow2 failed,timeout,stopped
monitor
\x1b[32mView an Execution Log:\x1b[0m
$ node wmiocli.js
-d tenant.int-aws-us.webmethods.io
-u user
-p password
monitor-workflow-log billUid
`;
}
function init(inDomainName, inUsername, inPassword, inTimeout, inPrettyprint) {
domainName = inDomainName;
username = inUsername;
password = inPassword;
timeout = inTimeout;
prettyprint = inPrettyprint;
url = "https://" + domainName + "/apis/v1/rest/monitor";
debug("Username [" + username + "]");
debug("URL [" + url + "]");
debug("Timeout [" + timeout + "]");
}
/**
* Call back function to process REST response
* @param {return data from REST request} data
* @param {status} status
*/
function processResponse(restEndPointUrl, err, data, response) {
let status = response.status;
if (prettyprint == true) {
console.log(JSON.stringify(data, null, 4));
}
else {
console.log(JSON.stringify(data));
}
if (status != 0) {
process.exit(status);
}
}
/* Monitor */
function list(startDate,endDate,projectsList,workflowsList,executionStatusList) {
url +="/summary";
//debug("################### Get Monitor Summary " + "[" + startDate + "," + endDate + "," + projectsList +"," + workflowsList +"," + executionStatusList +"]");
var start_date = startDate;
var end_date = endDate;
var projects = [];
var workflows = [];
var execution_status=[];
if(end_date===undefined)
{
var now = new Date();
var month = now.getMonth()+1;
if(month.toString().length==1)month = "0" + month.toString();
end_date=now.getFullYear() + "-" + month + "-" + now.getDate();
now.setDate(now.getDate()-30);
month = now.getMonth()+1;
if(month.toString().length==1)month = "0" + '' + month;
start_date=now.getFullYear() + "-" + month + "-" + now.getDate();
}
debug("***** START POSITION: " + returnStart);
debug("***** COUNT : " + returnCount);
debug("***** START_DATE: " + start_date);
debug("***** END_DATE: " + end_date);
if(projectsList!== undefined && projectsList!==null)projects = projectsList.split(",");
if(workflowsList!== undefined && workflowsList!==null)workflows = workflowsList.split(",");
if(executionStatusList!== undefined && executionStatusList!==null)execution_status = executionStatusList.split(",");
var data={};
data.start_date=start_date;
data.end_date=end_date;
if(projects.length>0)data.projects=projects;
if(workflows.length>0)data.workflows=workflows;
if(execution_status.length>0)data.execution_status=execution_status;
//var data = { "start_date": start_date, "end_date": end_date, "projects": projects, "workflows": workflows, "execution_status":execution_status };
if(returnStart!==undefined && returnCount !==undefined)
{
url+="?skip="+returnStart + "&limit=" + returnCount;
}
request.post(url, username, password, timeout,data, processResponse);
}
function logDetail(billUid) {
url +="/workflow-execution/logs/" + billUid;
debug("############################ getLog Detail");
request.get(url, username, password, timeout, processResponse);
}
module.exports = {
help, init, list, logDetail
};