cisco-perfmon 1.3.2 → 1.3.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/main.js +281 -164
- package/package.json +2 -2
- package/test/tests.js +14 -14
package/main.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// fetch-retry can also wrap Node.js's native fetch API implementation:
|
|
2
|
-
const fetch = require(
|
|
2
|
+
const fetch = require("fetch-retry")(global.fetch);
|
|
3
3
|
const util = require("util");
|
|
4
4
|
const parseString = require("xml2js").parseString;
|
|
5
5
|
const stripPrefix = require("xml2js").processors.stripPrefix;
|
|
@@ -100,15 +100,15 @@ var XML_REMOVE_COUNTER_ENVELOPE = `<soapenv:Envelope xmlns:soapenv="http://schem
|
|
|
100
100
|
class perfMonService {
|
|
101
101
|
constructor(host, username, password, options) {
|
|
102
102
|
this._OPTIONS = {
|
|
103
|
-
retries:
|
|
104
|
-
retryDelay:
|
|
103
|
+
retries: process.env.PERFMON_RETRIES ? parseInt(process.env.PERFMON_RETRIES) : 3,
|
|
104
|
+
retryDelay: process.env.PERFMON_RETRY_DELAY ? parseInt(process.env.PERFMON_RETRY_DELAY) : 1000,
|
|
105
105
|
retryOn: [503],
|
|
106
106
|
method: "POST",
|
|
107
107
|
headers: {
|
|
108
108
|
Authorization: "Basic " + Buffer.from(username + ":" + password).toString("base64"),
|
|
109
109
|
"Content-Type": "text/xml;charset=UTF-8",
|
|
110
110
|
Connection: "keep-alive",
|
|
111
|
-
}
|
|
111
|
+
},
|
|
112
112
|
};
|
|
113
113
|
|
|
114
114
|
// Adds additional headers if they are provided. Useful for adding cookies for SSO sessions
|
|
@@ -146,15 +146,15 @@ class perfMonService {
|
|
|
146
146
|
return new Promise((resolve, reject) => {
|
|
147
147
|
// Set up our promise results
|
|
148
148
|
var promiseResults = {
|
|
149
|
-
|
|
150
|
-
|
|
149
|
+
cookie: "",
|
|
150
|
+
results: "",
|
|
151
151
|
};
|
|
152
152
|
// We fetch the API endpoint
|
|
153
153
|
fetch(`https://${server}:8443/perfmonservice2/services/PerfmonService/`, options)
|
|
154
154
|
.then(async (response) => {
|
|
155
155
|
try {
|
|
156
156
|
var data = []; // create an array to save chunked data from server
|
|
157
|
-
promiseResults.
|
|
157
|
+
promiseResults.cookie = response.headers.get("set-cookie") ? response.headers.get("set-cookie") : "";
|
|
158
158
|
// response.body is a ReadableStream
|
|
159
159
|
const reader = response.body.getReader();
|
|
160
160
|
for await (const chunk of readChunks(reader)) {
|
|
@@ -166,72 +166,78 @@ class perfMonService {
|
|
|
166
166
|
// Remove unnecessary keys
|
|
167
167
|
removeKeys(output, "$");
|
|
168
168
|
|
|
169
|
-
if
|
|
170
|
-
|
|
171
|
-
if (
|
|
172
|
-
var
|
|
173
|
-
if (
|
|
174
|
-
newOutput
|
|
175
|
-
|
|
169
|
+
// Let's check if the response contains the key we are looking for. This is the return data.
|
|
170
|
+
if (keyExists(output, "perfmonCollectCounterDataResponse")) {
|
|
171
|
+
if (keyExists(output, "perfmonCollectCounterDataReturn")) {
|
|
172
|
+
var returnResults = output.Body.perfmonCollectCounterDataResponse.perfmonCollectCounterDataReturn;
|
|
173
|
+
if (returnResults) {
|
|
174
|
+
var newOutput;
|
|
175
|
+
if (Array.isArray(returnResults)) {
|
|
176
|
+
newOutput = returnResults.map((item) => {
|
|
177
|
+
let arr = item.Name.split("\\").filter((element) => element);
|
|
178
|
+
|
|
179
|
+
let instanceArr = arr[1].split(/[()]+/).filter(function (e) {
|
|
180
|
+
return e;
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
return {
|
|
184
|
+
host: arr[0],
|
|
185
|
+
object: instanceArr[0],
|
|
186
|
+
instance: instanceArr[1] ? instanceArr[1] : "",
|
|
187
|
+
counter: arr[2],
|
|
188
|
+
value: item.Value,
|
|
189
|
+
cstatus: item.CStatus,
|
|
190
|
+
};
|
|
191
|
+
});
|
|
192
|
+
} else {
|
|
193
|
+
let arr = returnResults.Name.split("\\").filter((element) => element);
|
|
176
194
|
|
|
177
195
|
let instanceArr = arr[1].split(/[()]+/).filter(function (e) {
|
|
178
196
|
return e;
|
|
179
197
|
});
|
|
180
198
|
|
|
181
|
-
|
|
199
|
+
newOutput = {
|
|
182
200
|
host: arr[0],
|
|
183
201
|
object: instanceArr[0],
|
|
184
202
|
instance: instanceArr[1] ? instanceArr[1] : "",
|
|
185
203
|
counter: arr[2],
|
|
186
|
-
value:
|
|
187
|
-
cstatus:
|
|
204
|
+
value: returnResults.Value,
|
|
205
|
+
cstatus: returnResults.CStatus,
|
|
188
206
|
};
|
|
189
|
-
}
|
|
207
|
+
}
|
|
208
|
+
promiseResults.results = clean(newOutput);
|
|
209
|
+
resolve(promiseResults);
|
|
190
210
|
} else {
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
let instanceArr = arr[1].split(/[()]+/).filter(function (e) {
|
|
194
|
-
return e;
|
|
195
|
-
});
|
|
196
|
-
|
|
197
|
-
newOutput = {
|
|
198
|
-
host: arr[0],
|
|
199
|
-
object: instanceArr[0],
|
|
200
|
-
instance: instanceArr[1] ? instanceArr[1] : "",
|
|
201
|
-
counter: arr[2],
|
|
202
|
-
value: returnResults.Value,
|
|
203
|
-
cstatus: returnResults.CStatus,
|
|
204
|
-
};
|
|
211
|
+
promiseResults.results = { response: "empty" };
|
|
212
|
+
resolve(promiseResults);
|
|
205
213
|
}
|
|
206
|
-
promiseResults.Results = clean(newOutput);
|
|
207
|
-
resolve(promiseResults);
|
|
208
214
|
} else {
|
|
209
|
-
promiseResults.
|
|
210
|
-
|
|
215
|
+
promiseResults.results = { response: "empty" };
|
|
216
|
+
resolve(promiseResults);
|
|
211
217
|
}
|
|
212
218
|
} else {
|
|
213
219
|
// Error checking. If the response contains a fault, we return the fault.
|
|
214
220
|
if (keyExists(output, "Fault")) {
|
|
215
221
|
if (output.Body.Fault.faultcode.includes("RateControl")) {
|
|
216
|
-
promiseResults.
|
|
222
|
+
promiseResults.results = { faultcode: "RateControl", faultstring: output.Body.Fault.faultstring };
|
|
217
223
|
} else if (output.Body.Fault.faultcode.includes("generalException")) {
|
|
218
|
-
promiseResults.
|
|
224
|
+
promiseResults.results = { faultcode: "generalException", faultstring: output.Body.Fault.faultstring };
|
|
219
225
|
} else {
|
|
220
|
-
promiseResults.
|
|
226
|
+
promiseResults.results = { faultcode: output.Body.Fault.faultcode, faultstring: output.Body.Fault.faultstring };
|
|
221
227
|
}
|
|
222
228
|
resolve(promiseResults);
|
|
223
229
|
} else {
|
|
224
|
-
// Error unknown.
|
|
230
|
+
// Error unknown. Reject with the response status instead. Most likely a 500 error from the server.
|
|
225
231
|
reject(response.status);
|
|
226
232
|
}
|
|
227
233
|
}
|
|
228
234
|
} catch (e) {
|
|
229
|
-
promiseResults.
|
|
235
|
+
promiseResults.results = e;
|
|
230
236
|
reject(promiseResults);
|
|
231
237
|
}
|
|
232
238
|
})
|
|
233
239
|
.catch((error) => {
|
|
234
|
-
promiseResults.
|
|
240
|
+
promiseResults.results = error;
|
|
235
241
|
reject(promiseResults);
|
|
236
242
|
}); // catches the error and logs it
|
|
237
243
|
});
|
|
@@ -263,15 +269,15 @@ class perfMonService {
|
|
|
263
269
|
return new Promise((resolve, reject) => {
|
|
264
270
|
// Set up our promise results
|
|
265
271
|
var promiseResults = {
|
|
266
|
-
|
|
267
|
-
|
|
272
|
+
cookie: "",
|
|
273
|
+
results: "",
|
|
268
274
|
};
|
|
269
275
|
// We fetch the API endpoint
|
|
270
276
|
fetch(`https://${server}:8443/perfmonservice2/services/PerfmonService/`, options)
|
|
271
277
|
.then(async (response) => {
|
|
272
278
|
try {
|
|
273
279
|
var data = []; // create an array to save chunked data from server
|
|
274
|
-
promiseResults.
|
|
280
|
+
promiseResults.cookie = response.headers.get("set-cookie") ? response.headers.get("set-cookie") : "";
|
|
275
281
|
// response.body is a ReadableStream
|
|
276
282
|
const reader = response.body.getReader();
|
|
277
283
|
for await (const chunk of readChunks(reader)) {
|
|
@@ -283,61 +289,77 @@ class perfMonService {
|
|
|
283
289
|
// Remove unnecessary keys
|
|
284
290
|
removeKeys(output, "$");
|
|
285
291
|
|
|
286
|
-
if (keyExists(output, "
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
292
|
+
if (keyExists(output, "perfmonCollectSessionDataResponse")) {
|
|
293
|
+
if (keyExists(output, "perfmonCollectSessionDataReturn")) {
|
|
294
|
+
var returnResults = output.Body.perfmonCollectSessionDataResponse.perfmonCollectSessionDataReturn;
|
|
295
|
+
if (returnResults) {
|
|
296
|
+
var newOutput;
|
|
297
|
+
if (Array.isArray(returnResults)) {
|
|
298
|
+
newOutput = returnResults.map((item) => {
|
|
299
|
+
let arr = item.Name.split("\\").filter((element) => element);
|
|
300
|
+
|
|
301
|
+
let instanceArr = arr[1].split(/[()]+/).filter(function (e) {
|
|
302
|
+
return e;
|
|
303
|
+
});
|
|
304
|
+
|
|
305
|
+
return {
|
|
306
|
+
host: arr[0],
|
|
307
|
+
object: instanceArr[0],
|
|
308
|
+
instance: instanceArr[1] ? instanceArr[1] : "",
|
|
309
|
+
counter: arr[2],
|
|
310
|
+
value: item.Value,
|
|
311
|
+
cstatus: item.CStatus,
|
|
312
|
+
};
|
|
313
|
+
});
|
|
314
|
+
} else {
|
|
315
|
+
let arr = returnResults.Name.split("\\").filter((element) => element);
|
|
294
316
|
|
|
295
317
|
let instanceArr = arr[1].split(/[()]+/).filter(function (e) {
|
|
296
318
|
return e;
|
|
297
319
|
});
|
|
298
320
|
|
|
299
|
-
|
|
321
|
+
newOutput = {
|
|
300
322
|
host: arr[0],
|
|
301
323
|
object: instanceArr[0],
|
|
302
324
|
instance: instanceArr[1] ? instanceArr[1] : "",
|
|
303
325
|
counter: arr[2],
|
|
304
|
-
value:
|
|
305
|
-
cstatus:
|
|
326
|
+
value: returnResults.Value,
|
|
327
|
+
cstatus: returnResults.CStatus,
|
|
306
328
|
};
|
|
307
|
-
}
|
|
329
|
+
}
|
|
330
|
+
promiseResults.results = clean(newOutput);
|
|
331
|
+
resolve(promiseResults);
|
|
308
332
|
} else {
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
let instanceArr = arr[1].split(/[()]+/).filter(function (e) {
|
|
312
|
-
return e;
|
|
313
|
-
});
|
|
314
|
-
|
|
315
|
-
newOutput = {
|
|
316
|
-
host: arr[0],
|
|
317
|
-
object: instanceArr[0],
|
|
318
|
-
instance: instanceArr[1] ? instanceArr[1] : "",
|
|
319
|
-
counter: arr[2],
|
|
320
|
-
value: returnResults.Value,
|
|
321
|
-
cstatus: returnResults.CStatus,
|
|
322
|
-
};
|
|
333
|
+
promiseResults.results = { response: "empty" };
|
|
334
|
+
resolve(promiseResults);
|
|
323
335
|
}
|
|
324
|
-
promiseResults.Results = clean(newOutput);
|
|
325
|
-
resolve(promiseResults);
|
|
326
336
|
} else {
|
|
327
|
-
promiseResults.
|
|
328
|
-
|
|
337
|
+
promiseResults.results = { response: "empty" };
|
|
338
|
+
resolve(promiseResults);
|
|
329
339
|
}
|
|
330
340
|
} else {
|
|
331
|
-
|
|
332
|
-
|
|
341
|
+
// Error checking. If the response contains a fault, we return the fault.
|
|
342
|
+
if (keyExists(output, "Fault")) {
|
|
343
|
+
if (output.Body.Fault.faultcode.includes("RateControl")) {
|
|
344
|
+
promiseResults.results = { faultcode: "RateControl", faultstring: output.Body.Fault.faultstring };
|
|
345
|
+
} else if (output.Body.Fault.faultcode.includes("generalException")) {
|
|
346
|
+
promiseResults.results = { faultcode: "generalException", faultstring: output.Body.Fault.faultstring };
|
|
347
|
+
} else {
|
|
348
|
+
promiseResults.results = { faultcode: output.Body.Fault.faultcode, faultstring: output.Body.Fault.faultstring };
|
|
349
|
+
}
|
|
350
|
+
resolve(promiseResults);
|
|
351
|
+
} else {
|
|
352
|
+
// Error unknown. Reject with the response status instead. Most likely a 500 error from the server.
|
|
353
|
+
reject(response.status);
|
|
354
|
+
}
|
|
333
355
|
}
|
|
334
356
|
} catch (e) {
|
|
335
|
-
promiseResults.
|
|
357
|
+
promiseResults.results = e;
|
|
336
358
|
reject(promiseResults);
|
|
337
359
|
}
|
|
338
360
|
})
|
|
339
361
|
.catch((error) => {
|
|
340
|
-
promiseResults.
|
|
362
|
+
promiseResults.results = error;
|
|
341
363
|
reject(promiseResults);
|
|
342
364
|
}); // catches the error and logs it
|
|
343
365
|
});
|
|
@@ -369,15 +391,15 @@ class perfMonService {
|
|
|
369
391
|
return new Promise((resolve, reject) => {
|
|
370
392
|
// Set up our promise results
|
|
371
393
|
var promiseResults = {
|
|
372
|
-
|
|
373
|
-
|
|
394
|
+
cookie: "",
|
|
395
|
+
results: "",
|
|
374
396
|
};
|
|
375
397
|
// We fetch the API endpoint
|
|
376
398
|
fetch(`https://${server}:8443/perfmonservice2/services/PerfmonService/`, options)
|
|
377
399
|
.then(async (response) => {
|
|
378
400
|
try {
|
|
379
401
|
var data = []; // create an array to save chunked data from server
|
|
380
|
-
promiseResults.
|
|
402
|
+
promiseResults.cookie = response.headers.get("set-cookie") ? response.headers.get("set-cookie") : "";
|
|
381
403
|
// response.body is a ReadableStream
|
|
382
404
|
const reader = response.body.getReader();
|
|
383
405
|
for await (const chunk of readChunks(reader)) {
|
|
@@ -389,27 +411,43 @@ class perfMonService {
|
|
|
389
411
|
// Remove unnecessary keys
|
|
390
412
|
removeKeys(output, "$");
|
|
391
413
|
|
|
392
|
-
if (keyExists(output, "
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
414
|
+
if (keyExists(output, "perfmonListCounterResponse")) {
|
|
415
|
+
if (keyExists(output, "perfmonListCounterReturn")) {
|
|
416
|
+
var returnResults = output.Body.perfmonListCounterResponse.perfmonListCounterReturn;
|
|
417
|
+
if (returnResults) {
|
|
418
|
+
promiseResults.results = clean(returnResults);
|
|
419
|
+
resolve(promiseResults);
|
|
420
|
+
} else {
|
|
421
|
+
promiseResults.results = { response: "empty" };
|
|
422
|
+
resolve(promiseResults);
|
|
423
|
+
}
|
|
398
424
|
} else {
|
|
399
|
-
promiseResults.
|
|
400
|
-
|
|
425
|
+
promiseResults.results = { response: "empty" };
|
|
426
|
+
resolve(promiseResults);
|
|
401
427
|
}
|
|
402
428
|
} else {
|
|
403
|
-
|
|
404
|
-
|
|
429
|
+
// Error checking. If the response contains a fault, we return the fault.
|
|
430
|
+
if (keyExists(output, "Fault")) {
|
|
431
|
+
if (output.Body.Fault.faultcode.includes("RateControl")) {
|
|
432
|
+
promiseResults.results = { faultcode: "RateControl", faultstring: output.Body.Fault.faultstring };
|
|
433
|
+
} else if (output.Body.Fault.faultcode.includes("generalException")) {
|
|
434
|
+
promiseResults.results = { faultcode: "generalException", faultstring: output.Body.Fault.faultstring };
|
|
435
|
+
} else {
|
|
436
|
+
promiseResults.results = { faultcode: output.Body.Fault.faultcode, faultstring: output.Body.Fault.faultstring };
|
|
437
|
+
}
|
|
438
|
+
resolve(promiseResults);
|
|
439
|
+
} else {
|
|
440
|
+
// Error unknown. Reject with the response status instead. Most likely a 500 error from the server.
|
|
441
|
+
reject(response.status);
|
|
442
|
+
}
|
|
405
443
|
}
|
|
406
444
|
} catch (e) {
|
|
407
|
-
promiseResults.
|
|
445
|
+
promiseResults.results = e;
|
|
408
446
|
reject(promiseResults);
|
|
409
447
|
}
|
|
410
448
|
})
|
|
411
449
|
.catch((error) => {
|
|
412
|
-
promiseResults.
|
|
450
|
+
promiseResults.results = error;
|
|
413
451
|
reject(promiseResults);
|
|
414
452
|
}); // catches the error and logs it
|
|
415
453
|
});
|
|
@@ -442,15 +480,15 @@ class perfMonService {
|
|
|
442
480
|
return new Promise((resolve, reject) => {
|
|
443
481
|
// Set up our promise results
|
|
444
482
|
var promiseResults = {
|
|
445
|
-
|
|
446
|
-
|
|
483
|
+
cookie: "",
|
|
484
|
+
results: "",
|
|
447
485
|
};
|
|
448
486
|
// We fetch the API endpoint
|
|
449
487
|
fetch(`https://${server}:8443/perfmonservice2/services/PerfmonService/`, options)
|
|
450
488
|
.then(async (response) => {
|
|
451
489
|
try {
|
|
452
490
|
var data = []; // create an array to save chunked data from server
|
|
453
|
-
promiseResults.
|
|
491
|
+
promiseResults.cookie = response.headers.get("set-cookie") ? response.headers.get("set-cookie") : "";
|
|
454
492
|
// response.body is a ReadableStream
|
|
455
493
|
const reader = response.body.getReader();
|
|
456
494
|
for await (const chunk of readChunks(reader)) {
|
|
@@ -462,27 +500,43 @@ class perfMonService {
|
|
|
462
500
|
// Remove unnecessary keys
|
|
463
501
|
removeKeys(output, "$");
|
|
464
502
|
|
|
465
|
-
if (keyExists(output, "
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
503
|
+
if (keyExists(output, "perfmonListInstanceResponse")) {
|
|
504
|
+
if (keyExists(output, "perfmonListInstanceReturn")) {
|
|
505
|
+
var returnResults = output.Body.perfmonListInstanceResponse.perfmonListInstanceReturn;
|
|
506
|
+
if (returnResults) {
|
|
507
|
+
promiseResults.results = clean(returnResults);
|
|
508
|
+
resolve(promiseResults);
|
|
509
|
+
} else {
|
|
510
|
+
promiseResults.results = { response: "empty" };
|
|
511
|
+
resolve(promiseResults);
|
|
512
|
+
}
|
|
471
513
|
} else {
|
|
472
|
-
promiseResults.
|
|
473
|
-
|
|
514
|
+
promiseResults.results = { response: "empty" };
|
|
515
|
+
resolve(promiseResults);
|
|
474
516
|
}
|
|
475
517
|
} else {
|
|
476
|
-
|
|
477
|
-
|
|
518
|
+
// Error checking. If the response contains a fault, we return the fault.
|
|
519
|
+
if (keyExists(output, "Fault")) {
|
|
520
|
+
if (output.Body.Fault.faultcode.includes("RateControl")) {
|
|
521
|
+
promiseResults.results = { faultcode: "RateControl", faultstring: output.Body.Fault.faultstring };
|
|
522
|
+
} else if (output.Body.Fault.faultcode.includes("generalException")) {
|
|
523
|
+
promiseResults.results = { faultcode: "generalException", faultstring: output.Body.Fault.faultstring };
|
|
524
|
+
} else {
|
|
525
|
+
promiseResults.results = { faultcode: output.Body.Fault.faultcode, faultstring: output.Body.Fault.faultstring };
|
|
526
|
+
}
|
|
527
|
+
resolve(promiseResults);
|
|
528
|
+
} else {
|
|
529
|
+
// Error unknown. Reject with the response status instead. Most likely a 500 error from the server.
|
|
530
|
+
reject(response.status);
|
|
531
|
+
}
|
|
478
532
|
}
|
|
479
533
|
} catch (e) {
|
|
480
|
-
promiseResults.
|
|
534
|
+
promiseResults.results = e;
|
|
481
535
|
reject(promiseResults);
|
|
482
536
|
}
|
|
483
537
|
})
|
|
484
538
|
.catch((error) => {
|
|
485
|
-
promiseResults.
|
|
539
|
+
promiseResults.results = error;
|
|
486
540
|
reject(promiseResults);
|
|
487
541
|
}); // catches the error and logs it
|
|
488
542
|
});
|
|
@@ -512,15 +566,15 @@ class perfMonService {
|
|
|
512
566
|
return new Promise((resolve, reject) => {
|
|
513
567
|
// Set up our promise results
|
|
514
568
|
var promiseResults = {
|
|
515
|
-
|
|
516
|
-
|
|
569
|
+
cookie: "",
|
|
570
|
+
results: "",
|
|
517
571
|
};
|
|
518
572
|
// We fetch the API endpoint
|
|
519
573
|
fetch(`https://${server}:8443/perfmonservice2/services/PerfmonService/`, options)
|
|
520
574
|
.then(async (response) => {
|
|
521
575
|
try {
|
|
522
576
|
var data = []; // create an array to save chunked data from server
|
|
523
|
-
promiseResults.
|
|
577
|
+
promiseResults.cookie = response.headers.get("set-cookie") ? response.headers.get("set-cookie") : "";
|
|
524
578
|
// response.body is a ReadableStream
|
|
525
579
|
const reader = response.body.getReader();
|
|
526
580
|
for await (const chunk of readChunks(reader)) {
|
|
@@ -532,27 +586,43 @@ class perfMonService {
|
|
|
532
586
|
// Remove unnecessary keys
|
|
533
587
|
removeKeys(output, "$");
|
|
534
588
|
|
|
535
|
-
if (keyExists(output, "
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
589
|
+
if (keyExists(output, "perfmonOpenSessionResponse")) {
|
|
590
|
+
if (keyExists(output, "perfmonOpenSessionReturn")) {
|
|
591
|
+
var returnResults = output.Body.perfmonOpenSessionResponse.perfmonOpenSessionReturn;
|
|
592
|
+
if (returnResults) {
|
|
593
|
+
promiseResults.results = clean(returnResults);
|
|
594
|
+
resolve(promiseResults);
|
|
595
|
+
} else {
|
|
596
|
+
promiseResults.results = { response: "empty" };
|
|
597
|
+
resolve(promiseResults);
|
|
598
|
+
}
|
|
541
599
|
} else {
|
|
542
|
-
promiseResults.
|
|
543
|
-
|
|
600
|
+
promiseResults.results = { response: "empty" };
|
|
601
|
+
resolve(promiseResults);
|
|
544
602
|
}
|
|
545
603
|
} else {
|
|
546
|
-
|
|
547
|
-
|
|
604
|
+
// Error checking. If the response contains a fault, we return the fault.
|
|
605
|
+
if (keyExists(output, "Fault")) {
|
|
606
|
+
if (output.Body.Fault.faultcode.includes("RateControl")) {
|
|
607
|
+
promiseResults.results = { faultcode: "RateControl", faultstring: output.Body.Fault.faultstring };
|
|
608
|
+
} else if (output.Body.Fault.faultcode.includes("generalException")) {
|
|
609
|
+
promiseResults.results = { faultcode: "generalException", faultstring: output.Body.Fault.faultstring };
|
|
610
|
+
} else {
|
|
611
|
+
promiseResults.results = { faultcode: output.Body.Fault.faultcode, faultstring: output.Body.Fault.faultstring };
|
|
612
|
+
}
|
|
613
|
+
resolve(promiseResults);
|
|
614
|
+
} else {
|
|
615
|
+
// Error unknown. Reject with the response status instead. Most likely a 500 error from the server.
|
|
616
|
+
reject(response.status);
|
|
617
|
+
}
|
|
548
618
|
}
|
|
549
619
|
} catch (e) {
|
|
550
|
-
promiseResults.
|
|
620
|
+
promiseResults.results = e;
|
|
551
621
|
reject(promiseResults);
|
|
552
622
|
}
|
|
553
623
|
})
|
|
554
624
|
.catch((error) => {
|
|
555
|
-
promiseResults.
|
|
625
|
+
promiseResults.results = error;
|
|
556
626
|
reject(promiseResults);
|
|
557
627
|
}); // catches the error and logs it
|
|
558
628
|
});
|
|
@@ -583,15 +653,15 @@ class perfMonService {
|
|
|
583
653
|
return new Promise((resolve, reject) => {
|
|
584
654
|
// Set up our promise results
|
|
585
655
|
var promiseResults = {
|
|
586
|
-
|
|
587
|
-
|
|
656
|
+
cookie: "",
|
|
657
|
+
results: "",
|
|
588
658
|
};
|
|
589
659
|
// We fetch the API endpoint
|
|
590
660
|
fetch(`https://${server}:8443/perfmonservice2/services/PerfmonService/`, options)
|
|
591
661
|
.then(async (response) => {
|
|
592
662
|
try {
|
|
593
663
|
var data = []; // create an array to save chunked data from server
|
|
594
|
-
promiseResults.
|
|
664
|
+
promiseResults.cookie = response.headers.get("set-cookie") ? response.headers.get("set-cookie") : "";
|
|
595
665
|
// response.body is a ReadableStream
|
|
596
666
|
const reader = response.body.getReader();
|
|
597
667
|
for await (const chunk of readChunks(reader)) {
|
|
@@ -606,23 +676,35 @@ class perfMonService {
|
|
|
606
676
|
if (keyExists(output, "perfmonCloseSessionResponse")) {
|
|
607
677
|
var returnResults = output.Body.perfmonCloseSessionResponse;
|
|
608
678
|
if (returnResults) {
|
|
609
|
-
promiseResults.
|
|
679
|
+
promiseResults.results = { response: "success" };
|
|
610
680
|
resolve(promiseResults);
|
|
611
681
|
} else {
|
|
612
|
-
promiseResults.
|
|
682
|
+
promiseResults.results = { response: "unknow" };
|
|
613
683
|
reject(promiseResults);
|
|
614
684
|
}
|
|
615
685
|
} else {
|
|
616
|
-
|
|
617
|
-
|
|
686
|
+
// Error checking. If the response contains a fault, we return the fault.
|
|
687
|
+
if (keyExists(output, "Fault")) {
|
|
688
|
+
if (output.Body.Fault.faultcode.includes("RateControl")) {
|
|
689
|
+
promiseResults.results = { faultcode: "RateControl", faultstring: output.Body.Fault.faultstring };
|
|
690
|
+
} else if (output.Body.Fault.faultcode.includes("generalException")) {
|
|
691
|
+
promiseResults.results = { faultcode: "generalException", faultstring: output.Body.Fault.faultstring };
|
|
692
|
+
} else {
|
|
693
|
+
promiseResults.results = { faultcode: output.Body.Fault.faultcode, faultstring: output.Body.Fault.faultstring };
|
|
694
|
+
}
|
|
695
|
+
resolve(promiseResults);
|
|
696
|
+
} else {
|
|
697
|
+
// Error unknown. Reject with the response status instead. Most likely a 500 error from the server.
|
|
698
|
+
reject(response.status);
|
|
699
|
+
}
|
|
618
700
|
}
|
|
619
701
|
} catch (e) {
|
|
620
|
-
promiseResults.
|
|
702
|
+
promiseResults.results = e;
|
|
621
703
|
reject(promiseResults);
|
|
622
704
|
}
|
|
623
705
|
})
|
|
624
706
|
.catch((error) => {
|
|
625
|
-
promiseResults.
|
|
707
|
+
promiseResults.results = error;
|
|
626
708
|
reject(promiseResults);
|
|
627
709
|
}); // catches the error and logs it
|
|
628
710
|
});
|
|
@@ -682,25 +764,31 @@ class perfMonService {
|
|
|
682
764
|
removeKeys(output, "$");
|
|
683
765
|
|
|
684
766
|
if (keyExists(output, "perfmonAddCounterResponse")) {
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
767
|
+
promiseResults.results = { response: "success" };
|
|
768
|
+
resolve(promiseResults);
|
|
769
|
+
} else {
|
|
770
|
+
// Error checking. If the response contains a fault, we return the fault.
|
|
771
|
+
if (keyExists(output, "Fault")) {
|
|
772
|
+
if (output.Body.Fault.faultcode.includes("RateControl")) {
|
|
773
|
+
promiseResults.results = { faultcode: "RateControl", faultstring: output.Body.Fault.faultstring };
|
|
774
|
+
} else if (output.Body.Fault.faultcode.includes("generalException")) {
|
|
775
|
+
promiseResults.results = { faultcode: "generalException", faultstring: output.Body.Fault.faultstring };
|
|
776
|
+
} else {
|
|
777
|
+
promiseResults.results = { faultcode: output.Body.Fault.faultcode, faultstring: output.Body.Fault.faultstring };
|
|
778
|
+
}
|
|
688
779
|
resolve(promiseResults);
|
|
689
780
|
} else {
|
|
690
|
-
|
|
691
|
-
reject(
|
|
781
|
+
// Error unknown. Reject with the response status instead. Most likely a 500 error from the server.
|
|
782
|
+
reject(response.status);
|
|
692
783
|
}
|
|
693
|
-
} else {
|
|
694
|
-
promiseResults.Results = { response: "empty" };
|
|
695
|
-
resolve(promiseResults);
|
|
696
784
|
}
|
|
697
785
|
} catch (e) {
|
|
698
|
-
promiseResults.
|
|
786
|
+
promiseResults.results = e;
|
|
699
787
|
reject(promiseResults);
|
|
700
788
|
}
|
|
701
789
|
})
|
|
702
790
|
.catch((error) => {
|
|
703
|
-
promiseResults.
|
|
791
|
+
promiseResults.results = error;
|
|
704
792
|
reject(promiseResults);
|
|
705
793
|
}); // catches the error and logs it
|
|
706
794
|
});
|
|
@@ -762,23 +850,35 @@ class perfMonService {
|
|
|
762
850
|
if (keyExists(output, "perfmonRemoveCounterResponse")) {
|
|
763
851
|
var returnResults = output.Body.perfmonRemoveCounterResponse;
|
|
764
852
|
if (returnResults) {
|
|
765
|
-
promiseResults.
|
|
853
|
+
promiseResults.results = { response: "success" };
|
|
766
854
|
resolve(promiseResults);
|
|
767
855
|
} else {
|
|
768
|
-
promiseResults.
|
|
769
|
-
|
|
856
|
+
promiseResults.results = { response: "unknown" };
|
|
857
|
+
resolve(promiseResults);
|
|
770
858
|
}
|
|
771
859
|
} else {
|
|
772
|
-
|
|
773
|
-
|
|
860
|
+
// Error checking. If the response contains a fault, we return the fault.
|
|
861
|
+
if (keyExists(output, "Fault")) {
|
|
862
|
+
if (output.Body.Fault.faultcode.includes("RateControl")) {
|
|
863
|
+
promiseResults.results = { faultcode: "RateControl", faultstring: output.Body.Fault.faultstring };
|
|
864
|
+
} else if (output.Body.Fault.faultcode.includes("generalException")) {
|
|
865
|
+
promiseResults.results = { faultcode: "generalException", faultstring: output.Body.Fault.faultstring };
|
|
866
|
+
} else {
|
|
867
|
+
promiseResults.results = { faultcode: output.Body.Fault.faultcode, faultstring: output.Body.Fault.faultstring };
|
|
868
|
+
}
|
|
869
|
+
resolve(promiseResults);
|
|
870
|
+
} else {
|
|
871
|
+
// Error unknown. Reject with the response status instead. Most likely a 500 error from the server.
|
|
872
|
+
reject(response.status);
|
|
873
|
+
}
|
|
774
874
|
}
|
|
775
875
|
} catch (e) {
|
|
776
|
-
promiseResults.
|
|
876
|
+
promiseResults.results = e;
|
|
777
877
|
reject(promiseResults);
|
|
778
878
|
}
|
|
779
879
|
})
|
|
780
880
|
.catch((error) => {
|
|
781
|
-
promiseResults.
|
|
881
|
+
promiseResults.results = error;
|
|
782
882
|
reject(promiseResults);
|
|
783
883
|
}); // catches the error and logs it
|
|
784
884
|
});
|
|
@@ -812,15 +912,15 @@ class perfMonService {
|
|
|
812
912
|
return new Promise((resolve, reject) => {
|
|
813
913
|
// Set up our promise results
|
|
814
914
|
var promiseResults = {
|
|
815
|
-
|
|
816
|
-
|
|
915
|
+
cookie: "",
|
|
916
|
+
results: "",
|
|
817
917
|
};
|
|
818
918
|
// We fetch the API endpoint
|
|
819
919
|
fetch(`https://${server}:8443/perfmonservice2/services/PerfmonService/`, options)
|
|
820
920
|
.then(async (response) => {
|
|
821
921
|
try {
|
|
822
922
|
var data = []; // create an array to save chunked data from server
|
|
823
|
-
promiseResults.
|
|
923
|
+
promiseResults.cookie = response.headers.get("set-cookie") ? response.headers.get("set-cookie") : "";
|
|
824
924
|
// response.body is a ReadableStream
|
|
825
925
|
const reader = response.body.getReader();
|
|
826
926
|
for await (const chunk of readChunks(reader)) {
|
|
@@ -833,26 +933,43 @@ class perfMonService {
|
|
|
833
933
|
// Remove unnecessary keys
|
|
834
934
|
removeKeys(output, "$");
|
|
835
935
|
|
|
836
|
-
if (keyExists(output, "
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
936
|
+
if (keyExists(output, "perfmonQueryCounterDescriptionResponse")) {
|
|
937
|
+
if (keyExists(output, "perfmonQueryCounterDescriptionReturn")) {
|
|
938
|
+
var returnResults = output.Body.perfmonQueryCounterDescriptionResponse.perfmonQueryCounterDescriptionReturn;
|
|
939
|
+
if (returnResults) {
|
|
940
|
+
promiseResults.results = clean(returnResults);
|
|
941
|
+
resolve(promiseResults);
|
|
942
|
+
} else {
|
|
943
|
+
promiseResults.results = { response: "empty" };
|
|
944
|
+
resolve(promiseResults);
|
|
945
|
+
}
|
|
841
946
|
} else {
|
|
842
|
-
promiseResults.
|
|
843
|
-
|
|
947
|
+
promiseResults.results = { response: "empty" };
|
|
948
|
+
resolve(promiseResults);
|
|
844
949
|
}
|
|
845
950
|
} else {
|
|
846
|
-
|
|
847
|
-
|
|
951
|
+
// Error checking. If the response contains a fault, we return the fault.
|
|
952
|
+
if (keyExists(output, "Fault")) {
|
|
953
|
+
if (output.Body.Fault.faultcode.includes("RateControl")) {
|
|
954
|
+
promiseResults.results = { faultcode: "RateControl", faultstring: output.Body.Fault.faultstring };
|
|
955
|
+
} else if (output.Body.Fault.faultcode.includes("generalException")) {
|
|
956
|
+
promiseResults.results = { faultcode: "generalException", faultstring: output.Body.Fault.faultstring };
|
|
957
|
+
} else {
|
|
958
|
+
promiseResults.results = { faultcode: output.Body.Fault.faultcode, faultstring: output.Body.Fault.faultstring };
|
|
959
|
+
}
|
|
960
|
+
resolve(promiseResults);
|
|
961
|
+
} else {
|
|
962
|
+
// Error unknown. Reject with the response status instead. Most likely a 500 error from the server.
|
|
963
|
+
reject(response.status);
|
|
964
|
+
}
|
|
848
965
|
}
|
|
849
966
|
} catch (e) {
|
|
850
|
-
promiseResults.
|
|
967
|
+
promiseResults.results = e;
|
|
851
968
|
reject(promiseResults);
|
|
852
969
|
}
|
|
853
970
|
})
|
|
854
971
|
.catch((error) => {
|
|
855
|
-
promiseResults.
|
|
972
|
+
promiseResults.results = error;
|
|
856
973
|
reject(promiseResults);
|
|
857
974
|
}); // catches the error and logs it
|
|
858
975
|
});
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cisco-perfmon",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.4",
|
|
4
4
|
"description": "A library to pull Perfmon data from Cisco VOS applications via SOAP",
|
|
5
5
|
"main": "main.js",
|
|
6
6
|
"scripts": {
|
|
7
|
-
"test": "NODE_OPTIONS=--experimental-vm-modules NODE_NO_WARNINGS=1 NODE_TLS_REJECT_UNAUTHORIZED=0 NODE_ENV=
|
|
7
|
+
"test": "NODE_OPTIONS=--experimental-vm-modules NODE_NO_WARNINGS=1 NODE_TLS_REJECT_UNAUTHORIZED=0 NODE_ENV=development node ./test/tests.js",
|
|
8
8
|
"development": "NODE_OPTIONS=--experimental-vm-modules NODE_NO_WARNINGS=1 NODE_TLS_REJECT_UNAUTHORIZED=0 NODE_ENV=development node ./test/tests.js"
|
|
9
9
|
},
|
|
10
10
|
"repository": {
|
package/test/tests.js
CHANGED
|
@@ -30,14 +30,14 @@ var cucmServerName = env.CUCM_SERVER_NAME;
|
|
|
30
30
|
var SessionID;
|
|
31
31
|
var counterObj = {
|
|
32
32
|
host: cucmServerName,
|
|
33
|
-
object: "
|
|
34
|
-
counter: "%
|
|
33
|
+
object: "Memory",
|
|
34
|
+
counter: "% Mem Used",
|
|
35
35
|
};
|
|
36
36
|
|
|
37
37
|
var serviceSSO = "";
|
|
38
38
|
|
|
39
39
|
(async () => {
|
|
40
|
-
console.log("Let's get a description of our counter.");
|
|
40
|
+
console.log("Let's get a description of our counter. We will also retrieve a cookie to use for the rest of the session.");
|
|
41
41
|
await service
|
|
42
42
|
.queryCounterDescription(counterObj)
|
|
43
43
|
.then((results) => {
|
|
@@ -50,12 +50,22 @@ var serviceSSO = "";
|
|
|
50
50
|
console.log(error);
|
|
51
51
|
});
|
|
52
52
|
|
|
53
|
+
console.log("Let's collect some non session counter data.");
|
|
54
|
+
await serviceSSO
|
|
55
|
+
.collectCounterData(cucmServerName, "Cisco CallManager")
|
|
56
|
+
.then((results) => {
|
|
57
|
+
console.log("collectCounterData", results.Results);
|
|
58
|
+
})
|
|
59
|
+
.catch((error) => {
|
|
60
|
+
console.log(error);
|
|
61
|
+
});
|
|
62
|
+
|
|
53
63
|
console.log("Let's open a session, add a counter, wait 30 seconds, collect the session data, remove the counter and finally close the session");
|
|
54
64
|
await serviceSSO
|
|
55
65
|
.openSession()
|
|
56
66
|
.then(async (results) => {
|
|
57
67
|
console.log("SessionID", results.Results);
|
|
58
|
-
SessionID = results;
|
|
68
|
+
SessionID = results.Results;
|
|
59
69
|
await serviceSSO
|
|
60
70
|
.addCounter(SessionID, counterObj)
|
|
61
71
|
.then(async (results) => {
|
|
@@ -96,16 +106,6 @@ var serviceSSO = "";
|
|
|
96
106
|
console.log(error);
|
|
97
107
|
});
|
|
98
108
|
|
|
99
|
-
console.log("Let's collect some non session counter data.");
|
|
100
|
-
await serviceSSO
|
|
101
|
-
.collectCounterData(cucmServerName, "Cisco CallManager")
|
|
102
|
-
.then((results) => {
|
|
103
|
-
console.log("collectCounterData", results.Results);
|
|
104
|
-
})
|
|
105
|
-
.catch((error) => {
|
|
106
|
-
console.log(error);
|
|
107
|
-
});
|
|
108
|
-
|
|
109
109
|
console.log("Let's returns the list of available PerfMon objects and counters on a particular host");
|
|
110
110
|
await serviceSSO
|
|
111
111
|
.listCounter(cucmServerName)
|