cisco-perfmon 1.3.3 → 1.4.0
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 +165 -172
- package/package.json +1 -1
- package/test/tests.js +30 -30
package/main.js
CHANGED
|
@@ -85,6 +85,17 @@ var XML_REMOVE_COUNTER_ENVELOPE = `<soapenv:Envelope xmlns:soapenv="http://schem
|
|
|
85
85
|
</soapenv:Body>
|
|
86
86
|
</soapenv:Envelope>`;
|
|
87
87
|
|
|
88
|
+
// Set up our promise results
|
|
89
|
+
var promiseResults = {
|
|
90
|
+
cookie: "",
|
|
91
|
+
results: "",
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
// Set up our error results
|
|
95
|
+
var errorResults = {
|
|
96
|
+
message: "",
|
|
97
|
+
};
|
|
98
|
+
|
|
88
99
|
/**
|
|
89
100
|
* Cisco Perfmon Service
|
|
90
101
|
* This is a service class that uses fetch and promises to pull Perfmon data from Cisco CUCM
|
|
@@ -130,7 +141,7 @@ class perfMonService {
|
|
|
130
141
|
* @memberof perfMonService
|
|
131
142
|
* @param {string} host - The host to collect data from
|
|
132
143
|
* @param {string} object - The object to collect data about. Example: Cisco CallManager
|
|
133
|
-
* @returns {object} returns JSON via a Promise. JSON contains
|
|
144
|
+
* @returns {object} returns JSON via a Promise. JSON contains cookie and results if successful, otherwise it returns an error object.
|
|
134
145
|
*/
|
|
135
146
|
collectCounterData(host, object) {
|
|
136
147
|
var XML;
|
|
@@ -144,17 +155,12 @@ class perfMonService {
|
|
|
144
155
|
options.body = soapBody;
|
|
145
156
|
|
|
146
157
|
return new Promise((resolve, reject) => {
|
|
147
|
-
// Set up our promise results
|
|
148
|
-
var promiseResults = {
|
|
149
|
-
Cookie: "",
|
|
150
|
-
Results: "",
|
|
151
|
-
};
|
|
152
158
|
// We fetch the API endpoint
|
|
153
159
|
fetch(`https://${server}:8443/perfmonservice2/services/PerfmonService/`, options)
|
|
154
160
|
.then(async (response) => {
|
|
155
161
|
try {
|
|
156
162
|
var data = []; // create an array to save chunked data from server
|
|
157
|
-
promiseResults.
|
|
163
|
+
promiseResults.cookie = response.headers.get("set-cookie") ? response.headers.get("set-cookie") : "";
|
|
158
164
|
// response.body is a ReadableStream
|
|
159
165
|
const reader = response.body.getReader();
|
|
160
166
|
for await (const chunk of readChunks(reader)) {
|
|
@@ -205,40 +211,43 @@ class perfMonService {
|
|
|
205
211
|
cstatus: returnResults.CStatus,
|
|
206
212
|
};
|
|
207
213
|
}
|
|
208
|
-
promiseResults.
|
|
214
|
+
promiseResults.results = clean(newOutput);
|
|
209
215
|
resolve(promiseResults);
|
|
210
216
|
} else {
|
|
211
|
-
|
|
212
|
-
|
|
217
|
+
// We expected results but got none. This is an error.
|
|
218
|
+
errorResults.message = "No results found";
|
|
219
|
+
reject(errorResults);
|
|
213
220
|
}
|
|
214
221
|
} else {
|
|
215
|
-
|
|
216
|
-
|
|
222
|
+
// We expected results but got none. This is an error.
|
|
223
|
+
errorResults.message = "No results found";
|
|
224
|
+
reject(errorResults);
|
|
217
225
|
}
|
|
218
226
|
} else {
|
|
219
227
|
// Error checking. If the response contains a fault, we return the fault.
|
|
220
228
|
if (keyExists(output, "Fault")) {
|
|
221
229
|
if (output.Body.Fault.faultcode.includes("RateControl")) {
|
|
222
|
-
|
|
230
|
+
errorResults.message = { faultcode: "RateControl", faultstring: output.Body.Fault.faultstring };
|
|
223
231
|
} else if (output.Body.Fault.faultcode.includes("generalException")) {
|
|
224
|
-
|
|
232
|
+
errorResults.message = { faultcode: "generalException", faultstring: output.Body.Fault.faultstring };
|
|
225
233
|
} else {
|
|
226
|
-
|
|
234
|
+
errorResults.message = { faultcode: output.Body.Fault.faultcode, faultstring: output.Body.Fault.faultstring };
|
|
227
235
|
}
|
|
228
|
-
|
|
236
|
+
reject(errorResults);
|
|
229
237
|
} else {
|
|
230
238
|
// Error unknown. Reject with the response status instead. Most likely a 500 error from the server.
|
|
231
|
-
|
|
239
|
+
errorResults.message = response.status;
|
|
240
|
+
reject(errorResults);
|
|
232
241
|
}
|
|
233
242
|
}
|
|
234
243
|
} catch (e) {
|
|
235
|
-
|
|
236
|
-
reject(
|
|
244
|
+
errorResults.message = e;
|
|
245
|
+
reject(errorResults);
|
|
237
246
|
}
|
|
238
247
|
})
|
|
239
248
|
.catch((error) => {
|
|
240
|
-
|
|
241
|
-
reject(
|
|
249
|
+
errorResults.message = error;
|
|
250
|
+
reject(errorResults);
|
|
242
251
|
}); // catches the error and logs it
|
|
243
252
|
});
|
|
244
253
|
}
|
|
@@ -267,17 +276,12 @@ class perfMonService {
|
|
|
267
276
|
options.body = soapBody;
|
|
268
277
|
|
|
269
278
|
return new Promise((resolve, reject) => {
|
|
270
|
-
// Set up our promise results
|
|
271
|
-
var promiseResults = {
|
|
272
|
-
Cookie: "",
|
|
273
|
-
Results: "",
|
|
274
|
-
};
|
|
275
279
|
// We fetch the API endpoint
|
|
276
280
|
fetch(`https://${server}:8443/perfmonservice2/services/PerfmonService/`, options)
|
|
277
281
|
.then(async (response) => {
|
|
278
282
|
try {
|
|
279
283
|
var data = []; // create an array to save chunked data from server
|
|
280
|
-
promiseResults.
|
|
284
|
+
promiseResults.cookie = response.headers.get("set-cookie") ? response.headers.get("set-cookie") : "";
|
|
281
285
|
// response.body is a ReadableStream
|
|
282
286
|
const reader = response.body.getReader();
|
|
283
287
|
for await (const chunk of readChunks(reader)) {
|
|
@@ -327,40 +331,43 @@ class perfMonService {
|
|
|
327
331
|
cstatus: returnResults.CStatus,
|
|
328
332
|
};
|
|
329
333
|
}
|
|
330
|
-
promiseResults.
|
|
334
|
+
promiseResults.results = clean(newOutput);
|
|
331
335
|
resolve(promiseResults);
|
|
332
336
|
} else {
|
|
333
|
-
|
|
334
|
-
|
|
337
|
+
// We expected results but got none. This is an error.
|
|
338
|
+
errorResults.message = "No results found";
|
|
339
|
+
reject(errorResults);
|
|
335
340
|
}
|
|
336
341
|
} else {
|
|
337
|
-
|
|
338
|
-
|
|
342
|
+
// We expected results but got none. This is an error.
|
|
343
|
+
errorResults.message = "No results found";
|
|
344
|
+
reject(errorResults);
|
|
339
345
|
}
|
|
340
346
|
} else {
|
|
341
347
|
// Error checking. If the response contains a fault, we return the fault.
|
|
342
348
|
if (keyExists(output, "Fault")) {
|
|
343
349
|
if (output.Body.Fault.faultcode.includes("RateControl")) {
|
|
344
|
-
|
|
350
|
+
errorResults.message = { faultcode: "RateControl", faultstring: output.Body.Fault.faultstring };
|
|
345
351
|
} else if (output.Body.Fault.faultcode.includes("generalException")) {
|
|
346
|
-
|
|
352
|
+
errorResults.message = { faultcode: "generalException", faultstring: output.Body.Fault.faultstring };
|
|
347
353
|
} else {
|
|
348
|
-
|
|
354
|
+
errorResults.message = { faultcode: output.Body.Fault.faultcode, faultstring: output.Body.Fault.faultstring };
|
|
349
355
|
}
|
|
350
|
-
|
|
356
|
+
reject(errorResults);
|
|
351
357
|
} else {
|
|
352
358
|
// Error unknown. Reject with the response status instead. Most likely a 500 error from the server.
|
|
353
|
-
|
|
359
|
+
errorResults.message = response.status;
|
|
360
|
+
reject(errorResults);
|
|
354
361
|
}
|
|
355
362
|
}
|
|
356
363
|
} catch (e) {
|
|
357
|
-
|
|
358
|
-
reject(
|
|
364
|
+
errorResults.message = e;
|
|
365
|
+
reject(errorResults);
|
|
359
366
|
}
|
|
360
367
|
})
|
|
361
368
|
.catch((error) => {
|
|
362
|
-
|
|
363
|
-
reject(
|
|
369
|
+
errorResults.message = error;
|
|
370
|
+
reject(errorResults);
|
|
364
371
|
}); // catches the error and logs it
|
|
365
372
|
});
|
|
366
373
|
}
|
|
@@ -389,17 +396,12 @@ class perfMonService {
|
|
|
389
396
|
options.body = soapBody;
|
|
390
397
|
|
|
391
398
|
return new Promise((resolve, reject) => {
|
|
392
|
-
// Set up our promise results
|
|
393
|
-
var promiseResults = {
|
|
394
|
-
Cookie: "",
|
|
395
|
-
Results: "",
|
|
396
|
-
};
|
|
397
399
|
// We fetch the API endpoint
|
|
398
400
|
fetch(`https://${server}:8443/perfmonservice2/services/PerfmonService/`, options)
|
|
399
401
|
.then(async (response) => {
|
|
400
402
|
try {
|
|
401
403
|
var data = []; // create an array to save chunked data from server
|
|
402
|
-
promiseResults.
|
|
404
|
+
promiseResults.cookie = response.headers.get("set-cookie") ? response.headers.get("set-cookie") : "";
|
|
403
405
|
// response.body is a ReadableStream
|
|
404
406
|
const reader = response.body.getReader();
|
|
405
407
|
for await (const chunk of readChunks(reader)) {
|
|
@@ -415,40 +417,43 @@ class perfMonService {
|
|
|
415
417
|
if (keyExists(output, "perfmonListCounterReturn")) {
|
|
416
418
|
var returnResults = output.Body.perfmonListCounterResponse.perfmonListCounterReturn;
|
|
417
419
|
if (returnResults) {
|
|
418
|
-
promiseResults.
|
|
420
|
+
promiseResults.results = clean(returnResults);
|
|
419
421
|
resolve(promiseResults);
|
|
420
422
|
} else {
|
|
421
|
-
|
|
422
|
-
|
|
423
|
+
// We expected results but got none. This is an error.
|
|
424
|
+
errorResults.message = "No results found";
|
|
425
|
+
reject(errorResults);
|
|
423
426
|
}
|
|
424
427
|
} else {
|
|
425
|
-
|
|
426
|
-
|
|
428
|
+
// We expected results but got none. This is an error.
|
|
429
|
+
errorResults.message = "No results found";
|
|
430
|
+
reject(errorResults);
|
|
427
431
|
}
|
|
428
432
|
} else {
|
|
429
433
|
// Error checking. If the response contains a fault, we return the fault.
|
|
430
434
|
if (keyExists(output, "Fault")) {
|
|
431
435
|
if (output.Body.Fault.faultcode.includes("RateControl")) {
|
|
432
|
-
|
|
436
|
+
errorResults.message = { faultcode: "RateControl", faultstring: output.Body.Fault.faultstring };
|
|
433
437
|
} else if (output.Body.Fault.faultcode.includes("generalException")) {
|
|
434
|
-
|
|
438
|
+
errorResults.message = { faultcode: "generalException", faultstring: output.Body.Fault.faultstring };
|
|
435
439
|
} else {
|
|
436
|
-
|
|
440
|
+
errorResults.message = { faultcode: output.Body.Fault.faultcode, faultstring: output.Body.Fault.faultstring };
|
|
437
441
|
}
|
|
438
|
-
|
|
442
|
+
reject(errorResults);
|
|
439
443
|
} else {
|
|
440
444
|
// Error unknown. Reject with the response status instead. Most likely a 500 error from the server.
|
|
441
|
-
|
|
445
|
+
errorResults.message = response.status;
|
|
446
|
+
reject(errorResults);
|
|
442
447
|
}
|
|
443
448
|
}
|
|
444
449
|
} catch (e) {
|
|
445
|
-
|
|
446
|
-
reject(
|
|
450
|
+
errorResults.message = e;
|
|
451
|
+
reject(errorResults);
|
|
447
452
|
}
|
|
448
453
|
})
|
|
449
454
|
.catch((error) => {
|
|
450
|
-
|
|
451
|
-
reject(
|
|
455
|
+
errorResults.message = error;
|
|
456
|
+
reject(errorResults);
|
|
452
457
|
}); // catches the error and logs it
|
|
453
458
|
});
|
|
454
459
|
}
|
|
@@ -478,17 +483,12 @@ class perfMonService {
|
|
|
478
483
|
options.body = soapBody;
|
|
479
484
|
|
|
480
485
|
return new Promise((resolve, reject) => {
|
|
481
|
-
// Set up our promise results
|
|
482
|
-
var promiseResults = {
|
|
483
|
-
Cookie: "",
|
|
484
|
-
Results: "",
|
|
485
|
-
};
|
|
486
486
|
// We fetch the API endpoint
|
|
487
487
|
fetch(`https://${server}:8443/perfmonservice2/services/PerfmonService/`, options)
|
|
488
488
|
.then(async (response) => {
|
|
489
489
|
try {
|
|
490
490
|
var data = []; // create an array to save chunked data from server
|
|
491
|
-
promiseResults.
|
|
491
|
+
promiseResults.cookie = response.headers.get("set-cookie") ? response.headers.get("set-cookie") : "";
|
|
492
492
|
// response.body is a ReadableStream
|
|
493
493
|
const reader = response.body.getReader();
|
|
494
494
|
for await (const chunk of readChunks(reader)) {
|
|
@@ -504,40 +504,43 @@ class perfMonService {
|
|
|
504
504
|
if (keyExists(output, "perfmonListInstanceReturn")) {
|
|
505
505
|
var returnResults = output.Body.perfmonListInstanceResponse.perfmonListInstanceReturn;
|
|
506
506
|
if (returnResults) {
|
|
507
|
-
promiseResults.
|
|
507
|
+
promiseResults.results = clean(returnResults);
|
|
508
508
|
resolve(promiseResults);
|
|
509
509
|
} else {
|
|
510
|
-
|
|
511
|
-
|
|
510
|
+
// We expected results but got none. This is an error.
|
|
511
|
+
errorResults.message = "No results found";
|
|
512
|
+
reject(errorResults);
|
|
512
513
|
}
|
|
513
514
|
} else {
|
|
514
|
-
|
|
515
|
-
|
|
515
|
+
// We expected results but got none. This is an error.
|
|
516
|
+
errorResults.message = "No results found";
|
|
517
|
+
reject(errorResults);
|
|
516
518
|
}
|
|
517
519
|
} else {
|
|
518
520
|
// Error checking. If the response contains a fault, we return the fault.
|
|
519
521
|
if (keyExists(output, "Fault")) {
|
|
520
522
|
if (output.Body.Fault.faultcode.includes("RateControl")) {
|
|
521
|
-
|
|
523
|
+
errorResults.message = { faultcode: "RateControl", faultstring: output.Body.Fault.faultstring };
|
|
522
524
|
} else if (output.Body.Fault.faultcode.includes("generalException")) {
|
|
523
|
-
|
|
525
|
+
errorResults.message = { faultcode: "generalException", faultstring: output.Body.Fault.faultstring };
|
|
524
526
|
} else {
|
|
525
|
-
|
|
527
|
+
errorResults.message = { faultcode: output.Body.Fault.faultcode, faultstring: output.Body.Fault.faultstring };
|
|
526
528
|
}
|
|
527
|
-
|
|
529
|
+
reject(errorResults);
|
|
528
530
|
} else {
|
|
529
531
|
// Error unknown. Reject with the response status instead. Most likely a 500 error from the server.
|
|
530
|
-
|
|
532
|
+
errorResults.message = response.status;
|
|
533
|
+
reject(errorResults);
|
|
531
534
|
}
|
|
532
535
|
}
|
|
533
536
|
} catch (e) {
|
|
534
|
-
|
|
535
|
-
reject(
|
|
537
|
+
errorResults.message = e;
|
|
538
|
+
reject(errorResults);
|
|
536
539
|
}
|
|
537
540
|
})
|
|
538
541
|
.catch((error) => {
|
|
539
|
-
|
|
540
|
-
reject(
|
|
542
|
+
errorResults.message = error;
|
|
543
|
+
reject(errorResults);
|
|
541
544
|
}); // catches the error and logs it
|
|
542
545
|
});
|
|
543
546
|
}
|
|
@@ -564,17 +567,12 @@ class perfMonService {
|
|
|
564
567
|
options.body = soapBody;
|
|
565
568
|
|
|
566
569
|
return new Promise((resolve, reject) => {
|
|
567
|
-
// Set up our promise results
|
|
568
|
-
var promiseResults = {
|
|
569
|
-
Cookie: "",
|
|
570
|
-
Results: "",
|
|
571
|
-
};
|
|
572
570
|
// We fetch the API endpoint
|
|
573
571
|
fetch(`https://${server}:8443/perfmonservice2/services/PerfmonService/`, options)
|
|
574
572
|
.then(async (response) => {
|
|
575
573
|
try {
|
|
576
574
|
var data = []; // create an array to save chunked data from server
|
|
577
|
-
promiseResults.
|
|
575
|
+
promiseResults.cookie = response.headers.get("set-cookie") ? response.headers.get("set-cookie") : "";
|
|
578
576
|
// response.body is a ReadableStream
|
|
579
577
|
const reader = response.body.getReader();
|
|
580
578
|
for await (const chunk of readChunks(reader)) {
|
|
@@ -590,40 +588,43 @@ class perfMonService {
|
|
|
590
588
|
if (keyExists(output, "perfmonOpenSessionReturn")) {
|
|
591
589
|
var returnResults = output.Body.perfmonOpenSessionResponse.perfmonOpenSessionReturn;
|
|
592
590
|
if (returnResults) {
|
|
593
|
-
promiseResults.
|
|
591
|
+
promiseResults.results = clean(returnResults);
|
|
594
592
|
resolve(promiseResults);
|
|
595
593
|
} else {
|
|
596
|
-
|
|
597
|
-
|
|
594
|
+
// We expected results but got none. This is an error.
|
|
595
|
+
errorResults.message = "No results found";
|
|
596
|
+
reject(errorResults);
|
|
598
597
|
}
|
|
599
598
|
} else {
|
|
600
|
-
|
|
601
|
-
|
|
599
|
+
// We expected results but got none. This is an error.
|
|
600
|
+
errorResults.message = "No results found";
|
|
601
|
+
reject(errorResults);
|
|
602
602
|
}
|
|
603
603
|
} else {
|
|
604
604
|
// Error checking. If the response contains a fault, we return the fault.
|
|
605
605
|
if (keyExists(output, "Fault")) {
|
|
606
606
|
if (output.Body.Fault.faultcode.includes("RateControl")) {
|
|
607
|
-
|
|
607
|
+
errorResults.message = { faultcode: "RateControl", faultstring: output.Body.Fault.faultstring };
|
|
608
608
|
} else if (output.Body.Fault.faultcode.includes("generalException")) {
|
|
609
|
-
|
|
609
|
+
errorResults.message = { faultcode: "generalException", faultstring: output.Body.Fault.faultstring };
|
|
610
610
|
} else {
|
|
611
|
-
|
|
611
|
+
errorResults.message = { faultcode: output.Body.Fault.faultcode, faultstring: output.Body.Fault.faultstring };
|
|
612
612
|
}
|
|
613
|
-
|
|
613
|
+
reject(errorResults);
|
|
614
614
|
} else {
|
|
615
615
|
// Error unknown. Reject with the response status instead. Most likely a 500 error from the server.
|
|
616
|
-
|
|
616
|
+
errorResults.message = response.status;
|
|
617
|
+
reject(errorResults);
|
|
617
618
|
}
|
|
618
619
|
}
|
|
619
620
|
} catch (e) {
|
|
620
|
-
|
|
621
|
-
reject(
|
|
621
|
+
errorResults.message = e;
|
|
622
|
+
reject(errorResults);
|
|
622
623
|
}
|
|
623
624
|
})
|
|
624
625
|
.catch((error) => {
|
|
625
|
-
|
|
626
|
-
reject(
|
|
626
|
+
errorResults.message = error;
|
|
627
|
+
reject(errorResults);
|
|
627
628
|
}); // catches the error and logs it
|
|
628
629
|
});
|
|
629
630
|
}
|
|
@@ -651,17 +652,12 @@ class perfMonService {
|
|
|
651
652
|
options.body = soapBody;
|
|
652
653
|
|
|
653
654
|
return new Promise((resolve, reject) => {
|
|
654
|
-
// Set up our promise results
|
|
655
|
-
var promiseResults = {
|
|
656
|
-
Cookie: "",
|
|
657
|
-
Results: "",
|
|
658
|
-
};
|
|
659
655
|
// We fetch the API endpoint
|
|
660
656
|
fetch(`https://${server}:8443/perfmonservice2/services/PerfmonService/`, options)
|
|
661
657
|
.then(async (response) => {
|
|
662
658
|
try {
|
|
663
659
|
var data = []; // create an array to save chunked data from server
|
|
664
|
-
promiseResults.
|
|
660
|
+
promiseResults.cookie = response.headers.get("set-cookie") ? response.headers.get("set-cookie") : "";
|
|
665
661
|
// response.body is a ReadableStream
|
|
666
662
|
const reader = response.body.getReader();
|
|
667
663
|
for await (const chunk of readChunks(reader)) {
|
|
@@ -676,36 +672,37 @@ class perfMonService {
|
|
|
676
672
|
if (keyExists(output, "perfmonCloseSessionResponse")) {
|
|
677
673
|
var returnResults = output.Body.perfmonCloseSessionResponse;
|
|
678
674
|
if (returnResults) {
|
|
679
|
-
promiseResults.
|
|
675
|
+
promiseResults.results = "success";
|
|
680
676
|
resolve(promiseResults);
|
|
681
677
|
} else {
|
|
682
|
-
|
|
683
|
-
reject(
|
|
678
|
+
errorResults.message = "unknown";
|
|
679
|
+
reject(errorResults);
|
|
684
680
|
}
|
|
685
681
|
} else {
|
|
686
682
|
// Error checking. If the response contains a fault, we return the fault.
|
|
687
683
|
if (keyExists(output, "Fault")) {
|
|
688
684
|
if (output.Body.Fault.faultcode.includes("RateControl")) {
|
|
689
|
-
|
|
685
|
+
errorResults.message = { faultcode: "RateControl", faultstring: output.Body.Fault.faultstring };
|
|
690
686
|
} else if (output.Body.Fault.faultcode.includes("generalException")) {
|
|
691
|
-
|
|
687
|
+
errorResults.message = { faultcode: "generalException", faultstring: output.Body.Fault.faultstring };
|
|
692
688
|
} else {
|
|
693
|
-
|
|
689
|
+
errorResults.message = { faultcode: output.Body.Fault.faultcode, faultstring: output.Body.Fault.faultstring };
|
|
694
690
|
}
|
|
695
|
-
|
|
691
|
+
reject(errorResults);
|
|
696
692
|
} else {
|
|
697
693
|
// Error unknown. Reject with the response status instead. Most likely a 500 error from the server.
|
|
698
|
-
|
|
694
|
+
errorResults.message = response.status;
|
|
695
|
+
reject(errorResults);
|
|
699
696
|
}
|
|
700
697
|
}
|
|
701
698
|
} catch (e) {
|
|
702
|
-
|
|
703
|
-
reject(
|
|
699
|
+
errorResults.message = e;
|
|
700
|
+
reject(errorResults);
|
|
704
701
|
}
|
|
705
702
|
})
|
|
706
703
|
.catch((error) => {
|
|
707
|
-
|
|
708
|
-
reject(
|
|
704
|
+
errorResults.message = error;
|
|
705
|
+
reject(errorResults);
|
|
709
706
|
}); // catches the error and logs it
|
|
710
707
|
});
|
|
711
708
|
}
|
|
@@ -742,11 +739,6 @@ class perfMonService {
|
|
|
742
739
|
options.body = soapBody;
|
|
743
740
|
|
|
744
741
|
return new Promise((resolve, reject) => {
|
|
745
|
-
// Set up our promise results
|
|
746
|
-
var promiseResults = {
|
|
747
|
-
Cookie: "",
|
|
748
|
-
Results: "",
|
|
749
|
-
};
|
|
750
742
|
// We fetch the API endpoint
|
|
751
743
|
fetch(`https://${server}:8443/perfmonservice2/services/PerfmonService/`, options)
|
|
752
744
|
.then(async (response) => {
|
|
@@ -764,32 +756,39 @@ class perfMonService {
|
|
|
764
756
|
removeKeys(output, "$");
|
|
765
757
|
|
|
766
758
|
if (keyExists(output, "perfmonAddCounterResponse")) {
|
|
767
|
-
|
|
768
|
-
|
|
759
|
+
var returnResults = output.Body.perfmonAddCounterResponse;
|
|
760
|
+
if (returnResults) {
|
|
761
|
+
promiseResults.results = "success";
|
|
762
|
+
resolve(promiseResults);
|
|
763
|
+
} else {
|
|
764
|
+
errorResults.message = "unknown";
|
|
765
|
+
reject(errorResults);
|
|
766
|
+
}
|
|
769
767
|
} else {
|
|
770
768
|
// Error checking. If the response contains a fault, we return the fault.
|
|
771
769
|
if (keyExists(output, "Fault")) {
|
|
772
770
|
if (output.Body.Fault.faultcode.includes("RateControl")) {
|
|
773
|
-
|
|
771
|
+
errorResults.message = { faultcode: "RateControl", faultstring: output.Body.Fault.faultstring };
|
|
774
772
|
} else if (output.Body.Fault.faultcode.includes("generalException")) {
|
|
775
|
-
|
|
773
|
+
errorResults.message = { faultcode: "generalException", faultstring: output.Body.Fault.faultstring };
|
|
776
774
|
} else {
|
|
777
|
-
|
|
775
|
+
errorResults.message = { faultcode: output.Body.Fault.faultcode, faultstring: output.Body.Fault.faultstring };
|
|
778
776
|
}
|
|
779
|
-
|
|
777
|
+
reject(errorResults);
|
|
780
778
|
} else {
|
|
781
779
|
// Error unknown. Reject with the response status instead. Most likely a 500 error from the server.
|
|
782
|
-
|
|
780
|
+
errorResults.message = response.status;
|
|
781
|
+
reject(errorResults);
|
|
783
782
|
}
|
|
784
783
|
}
|
|
785
784
|
} catch (e) {
|
|
786
|
-
|
|
787
|
-
reject(
|
|
785
|
+
errorResults.message = e;
|
|
786
|
+
reject(errorResults);
|
|
788
787
|
}
|
|
789
788
|
})
|
|
790
789
|
.catch((error) => {
|
|
791
|
-
|
|
792
|
-
reject(
|
|
790
|
+
errorResults.message = error;
|
|
791
|
+
reject(errorResults);
|
|
793
792
|
}); // catches the error and logs it
|
|
794
793
|
});
|
|
795
794
|
}
|
|
@@ -826,11 +825,6 @@ class perfMonService {
|
|
|
826
825
|
options.body = soapBody;
|
|
827
826
|
|
|
828
827
|
return new Promise((resolve, reject) => {
|
|
829
|
-
// Set up our promise results
|
|
830
|
-
var promiseResults = {
|
|
831
|
-
Cookie: "",
|
|
832
|
-
Results: "",
|
|
833
|
-
};
|
|
834
828
|
// We fetch the API endpoint
|
|
835
829
|
fetch(`https://${server}:8443/perfmonservice2/services/PerfmonService/`, options)
|
|
836
830
|
.then(async (response) => {
|
|
@@ -850,36 +844,37 @@ class perfMonService {
|
|
|
850
844
|
if (keyExists(output, "perfmonRemoveCounterResponse")) {
|
|
851
845
|
var returnResults = output.Body.perfmonRemoveCounterResponse;
|
|
852
846
|
if (returnResults) {
|
|
853
|
-
promiseResults.
|
|
847
|
+
promiseResults.results = "success";
|
|
854
848
|
resolve(promiseResults);
|
|
855
849
|
} else {
|
|
856
|
-
|
|
857
|
-
|
|
850
|
+
errorResults.message = "unknown";
|
|
851
|
+
reject(errorResults);
|
|
858
852
|
}
|
|
859
853
|
} else {
|
|
860
854
|
// Error checking. If the response contains a fault, we return the fault.
|
|
861
855
|
if (keyExists(output, "Fault")) {
|
|
862
856
|
if (output.Body.Fault.faultcode.includes("RateControl")) {
|
|
863
|
-
|
|
857
|
+
errorResults.message = { faultcode: "RateControl", faultstring: output.Body.Fault.faultstring };
|
|
864
858
|
} else if (output.Body.Fault.faultcode.includes("generalException")) {
|
|
865
|
-
|
|
859
|
+
errorResults.message = { faultcode: "generalException", faultstring: output.Body.Fault.faultstring };
|
|
866
860
|
} else {
|
|
867
|
-
|
|
861
|
+
errorResults.message = { faultcode: output.Body.Fault.faultcode, faultstring: output.Body.Fault.faultstring };
|
|
868
862
|
}
|
|
869
|
-
|
|
863
|
+
reject(errorResults);
|
|
870
864
|
} else {
|
|
871
865
|
// Error unknown. Reject with the response status instead. Most likely a 500 error from the server.
|
|
872
|
-
|
|
866
|
+
errorResults.message = response.status;
|
|
867
|
+
reject(errorResults);
|
|
873
868
|
}
|
|
874
869
|
}
|
|
875
870
|
} catch (e) {
|
|
876
|
-
|
|
877
|
-
reject(
|
|
871
|
+
errorResults.message = e;
|
|
872
|
+
reject(errorResults);
|
|
878
873
|
}
|
|
879
874
|
})
|
|
880
875
|
.catch((error) => {
|
|
881
|
-
|
|
882
|
-
reject(
|
|
876
|
+
errorResults.message = error;
|
|
877
|
+
reject(errorResults);
|
|
883
878
|
}); // catches the error and logs it
|
|
884
879
|
});
|
|
885
880
|
}
|
|
@@ -910,17 +905,12 @@ class perfMonService {
|
|
|
910
905
|
options.body = soapBody;
|
|
911
906
|
|
|
912
907
|
return new Promise((resolve, reject) => {
|
|
913
|
-
// Set up our promise results
|
|
914
|
-
var promiseResults = {
|
|
915
|
-
Cookie: "",
|
|
916
|
-
Results: "",
|
|
917
|
-
};
|
|
918
908
|
// We fetch the API endpoint
|
|
919
909
|
fetch(`https://${server}:8443/perfmonservice2/services/PerfmonService/`, options)
|
|
920
910
|
.then(async (response) => {
|
|
921
911
|
try {
|
|
922
912
|
var data = []; // create an array to save chunked data from server
|
|
923
|
-
promiseResults.
|
|
913
|
+
promiseResults.cookie = response.headers.get("set-cookie") ? response.headers.get("set-cookie") : "";
|
|
924
914
|
// response.body is a ReadableStream
|
|
925
915
|
const reader = response.body.getReader();
|
|
926
916
|
for await (const chunk of readChunks(reader)) {
|
|
@@ -937,40 +927,43 @@ class perfMonService {
|
|
|
937
927
|
if (keyExists(output, "perfmonQueryCounterDescriptionReturn")) {
|
|
938
928
|
var returnResults = output.Body.perfmonQueryCounterDescriptionResponse.perfmonQueryCounterDescriptionReturn;
|
|
939
929
|
if (returnResults) {
|
|
940
|
-
promiseResults.
|
|
930
|
+
promiseResults.results = clean(returnResults);
|
|
941
931
|
resolve(promiseResults);
|
|
942
932
|
} else {
|
|
943
|
-
|
|
944
|
-
|
|
933
|
+
// We expected results but got none. This is an error.
|
|
934
|
+
errorResults.message = "No results found";
|
|
935
|
+
reject(errorResults);
|
|
945
936
|
}
|
|
946
937
|
} else {
|
|
947
|
-
|
|
948
|
-
|
|
938
|
+
// We expected results but got none. This is an error.
|
|
939
|
+
errorResults.message = "No results found";
|
|
940
|
+
reject(errorResults);
|
|
949
941
|
}
|
|
950
942
|
} else {
|
|
951
943
|
// Error checking. If the response contains a fault, we return the fault.
|
|
952
944
|
if (keyExists(output, "Fault")) {
|
|
953
945
|
if (output.Body.Fault.faultcode.includes("RateControl")) {
|
|
954
|
-
|
|
946
|
+
errorResults.message = { faultcode: "RateControl", faultstring: output.Body.Fault.faultstring };
|
|
955
947
|
} else if (output.Body.Fault.faultcode.includes("generalException")) {
|
|
956
|
-
|
|
948
|
+
errorResults.message = { faultcode: "generalException", faultstring: output.Body.Fault.faultstring };
|
|
957
949
|
} else {
|
|
958
|
-
|
|
950
|
+
errorResults.message = { faultcode: output.Body.Fault.faultcode, faultstring: output.Body.Fault.faultstring };
|
|
959
951
|
}
|
|
960
|
-
|
|
952
|
+
reject(errorResults);
|
|
961
953
|
} else {
|
|
962
954
|
// Error unknown. Reject with the response status instead. Most likely a 500 error from the server.
|
|
963
|
-
|
|
955
|
+
errorResults.message = response.status;
|
|
956
|
+
reject(errorResults);
|
|
964
957
|
}
|
|
965
958
|
}
|
|
966
959
|
} catch (e) {
|
|
967
|
-
|
|
968
|
-
reject(
|
|
960
|
+
errorResults.message = e;
|
|
961
|
+
reject(errorResults);
|
|
969
962
|
}
|
|
970
963
|
})
|
|
971
964
|
.catch((error) => {
|
|
972
|
-
|
|
973
|
-
reject(
|
|
965
|
+
errorResults.message = error;
|
|
966
|
+
reject(errorResults);
|
|
974
967
|
}); // catches the error and logs it
|
|
975
968
|
});
|
|
976
969
|
}
|
package/package.json
CHANGED
package/test/tests.js
CHANGED
|
@@ -40,89 +40,89 @@ var serviceSSO = "";
|
|
|
40
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
|
-
.then((
|
|
44
|
-
console.log("queryCounterDescription: ", results
|
|
45
|
-
if (
|
|
46
|
-
serviceSSO = new perfMonService(env.CUCM_HOSTNAME, "", "", { Cookie:
|
|
43
|
+
.then((response) => {
|
|
44
|
+
console.log("queryCounterDescription: ", response.results);
|
|
45
|
+
if (response.cookie) {
|
|
46
|
+
serviceSSO = new perfMonService(env.CUCM_HOSTNAME, "", "", { Cookie: response.cookie });
|
|
47
47
|
}
|
|
48
48
|
})
|
|
49
49
|
.catch((error) => {
|
|
50
|
-
console.log(error);
|
|
50
|
+
console.log(error.message);
|
|
51
51
|
});
|
|
52
52
|
|
|
53
53
|
console.log("Let's collect some non session counter data.");
|
|
54
54
|
await serviceSSO
|
|
55
55
|
.collectCounterData(cucmServerName, "Cisco CallManager")
|
|
56
|
-
.then((
|
|
57
|
-
console.log("collectCounterData", results
|
|
56
|
+
.then((response) => {
|
|
57
|
+
console.log("collectCounterData", response.results);
|
|
58
58
|
})
|
|
59
59
|
.catch((error) => {
|
|
60
|
-
console.log(error);
|
|
60
|
+
console.log(error.message);
|
|
61
61
|
});
|
|
62
62
|
|
|
63
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");
|
|
64
64
|
await serviceSSO
|
|
65
65
|
.openSession()
|
|
66
|
-
.then(async (
|
|
67
|
-
console.log("SessionID", results
|
|
68
|
-
SessionID = results
|
|
66
|
+
.then(async (response) => {
|
|
67
|
+
console.log("SessionID", response.results);
|
|
68
|
+
SessionID = response.results;
|
|
69
69
|
await serviceSSO
|
|
70
70
|
.addCounter(SessionID, counterObj)
|
|
71
|
-
.then(async (
|
|
72
|
-
console.log("addCounter", results
|
|
71
|
+
.then(async (response) => {
|
|
72
|
+
console.log("addCounter", response.results);
|
|
73
73
|
const delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
74
74
|
console.log("Wait 30 seconds");
|
|
75
75
|
await delay(30000); /// waiting 30 second.
|
|
76
76
|
await serviceSSO
|
|
77
77
|
.collectSessionData(SessionID)
|
|
78
|
-
.then(async (
|
|
79
|
-
console.log("collectSessionData", results
|
|
78
|
+
.then(async (response) => {
|
|
79
|
+
console.log("collectSessionData", response.results);
|
|
80
80
|
await serviceSSO
|
|
81
|
-
.removeCounter(SessionID, results
|
|
82
|
-
.then(async (
|
|
83
|
-
console.log("removeCounter", results
|
|
81
|
+
.removeCounter(SessionID, response.results)
|
|
82
|
+
.then(async (response) => {
|
|
83
|
+
console.log("removeCounter", response.results);
|
|
84
84
|
await serviceSSO
|
|
85
85
|
.closeSession(SessionID)
|
|
86
|
-
.then((
|
|
87
|
-
console.log("closeSession", results
|
|
86
|
+
.then((response) => {
|
|
87
|
+
console.log("closeSession", response.results);
|
|
88
88
|
})
|
|
89
89
|
.catch((error) => {
|
|
90
|
-
console.log(error);
|
|
90
|
+
console.log(error.message);
|
|
91
91
|
});
|
|
92
92
|
})
|
|
93
93
|
.catch((error) => {
|
|
94
|
-
console.log(error);
|
|
94
|
+
console.log(error.message);
|
|
95
95
|
});
|
|
96
96
|
})
|
|
97
97
|
.catch((error) => {
|
|
98
|
-
console.log(error);
|
|
98
|
+
console.log(error.message);
|
|
99
99
|
});
|
|
100
100
|
})
|
|
101
101
|
.catch((error) => {
|
|
102
|
-
console.log(error);
|
|
102
|
+
console.log(error.message);
|
|
103
103
|
});
|
|
104
104
|
})
|
|
105
105
|
.catch((error) => {
|
|
106
|
-
console.log(error);
|
|
106
|
+
console.log(error.message);
|
|
107
107
|
});
|
|
108
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)
|
|
112
|
-
.then((
|
|
113
|
-
console.log("listCounter", results
|
|
112
|
+
.then((response) => {
|
|
113
|
+
console.log("listCounter", response.results);
|
|
114
114
|
})
|
|
115
115
|
.catch((error) => {
|
|
116
|
-
console.log(error);
|
|
116
|
+
console.log(error.message);
|
|
117
117
|
});
|
|
118
118
|
|
|
119
119
|
console.log("Let's return a list of instances of a PerfMon object on a particular host. Instances of an object can dynamically change. This operation returns the most recent list.");
|
|
120
120
|
await serviceSSO
|
|
121
121
|
.listInstance(cucmServerName, "Processor")
|
|
122
122
|
.then((results) => {
|
|
123
|
-
console.log("listInstance", results.
|
|
123
|
+
console.log("listInstance", results.results);
|
|
124
124
|
})
|
|
125
125
|
.catch((error) => {
|
|
126
|
-
console.log(error);
|
|
126
|
+
console.log(error.message);
|
|
127
127
|
});
|
|
128
128
|
})();
|