cisco-perfmon 1.3.2 → 1.3.3
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 +237 -120
- package/package.json +1 -1
- 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
|
|
@@ -166,48 +166,54 @@ 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.Results =
|
|
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.
|
|
@@ -221,7 +227,7 @@ class perfMonService {
|
|
|
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
|
}
|
|
@@ -283,53 +289,69 @@ 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.Results =
|
|
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
357
|
promiseResults.Results = e;
|
|
@@ -389,19 +411,35 @@ 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.Results =
|
|
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
445
|
promiseResults.Results = e;
|
|
@@ -462,19 +500,35 @@ 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.Results =
|
|
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
534
|
promiseResults.Results = e;
|
|
@@ -532,19 +586,35 @@ 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.Results =
|
|
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
620
|
promiseResults.Results = e;
|
|
@@ -609,12 +679,24 @@ class perfMonService {
|
|
|
609
679
|
promiseResults.Results = { response: "success" };
|
|
610
680
|
resolve(promiseResults);
|
|
611
681
|
} else {
|
|
612
|
-
promiseResults.Results =
|
|
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
702
|
promiseResults.Results = e;
|
|
@@ -682,17 +764,23 @@ 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
786
|
promiseResults.Results = e;
|
|
@@ -765,12 +853,24 @@ class perfMonService {
|
|
|
765
853
|
promiseResults.Results = { response: "success" };
|
|
766
854
|
resolve(promiseResults);
|
|
767
855
|
} else {
|
|
768
|
-
promiseResults.Results =
|
|
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
876
|
promiseResults.Results = e;
|
|
@@ -833,18 +933,35 @@ 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.Results =
|
|
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
967
|
promiseResults.Results = e;
|
package/package.json
CHANGED
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)
|