cisco-perfmon 1.3.1 → 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 +238 -116
- package/package.json +2 -1
- package/test/tests.js +14 -14
package/main.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
// fetch-retry can also wrap Node.js's native fetch API implementation:
|
|
2
|
+
const fetch = require("fetch-retry")(global.fetch);
|
|
1
3
|
const util = require("util");
|
|
2
4
|
const parseString = require("xml2js").parseString;
|
|
3
5
|
const stripPrefix = require("xml2js").processors.stripPrefix;
|
|
@@ -98,6 +100,9 @@ var XML_REMOVE_COUNTER_ENVELOPE = `<soapenv:Envelope xmlns:soapenv="http://schem
|
|
|
98
100
|
class perfMonService {
|
|
99
101
|
constructor(host, username, password, options) {
|
|
100
102
|
this._OPTIONS = {
|
|
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
|
+
retryOn: [503],
|
|
101
106
|
method: "POST",
|
|
102
107
|
headers: {
|
|
103
108
|
Authorization: "Basic " + Buffer.from(username + ":" + password).toString("base64"),
|
|
@@ -161,48 +166,54 @@ class perfMonService {
|
|
|
161
166
|
// Remove unnecessary keys
|
|
162
167
|
removeKeys(output, "$");
|
|
163
168
|
|
|
164
|
-
if
|
|
165
|
-
|
|
166
|
-
if (
|
|
167
|
-
var
|
|
168
|
-
if (
|
|
169
|
-
newOutput
|
|
170
|
-
|
|
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);
|
|
171
194
|
|
|
172
195
|
let instanceArr = arr[1].split(/[()]+/).filter(function (e) {
|
|
173
196
|
return e;
|
|
174
197
|
});
|
|
175
198
|
|
|
176
|
-
|
|
199
|
+
newOutput = {
|
|
177
200
|
host: arr[0],
|
|
178
201
|
object: instanceArr[0],
|
|
179
202
|
instance: instanceArr[1] ? instanceArr[1] : "",
|
|
180
203
|
counter: arr[2],
|
|
181
|
-
value:
|
|
182
|
-
cstatus:
|
|
204
|
+
value: returnResults.Value,
|
|
205
|
+
cstatus: returnResults.CStatus,
|
|
183
206
|
};
|
|
184
|
-
}
|
|
207
|
+
}
|
|
208
|
+
promiseResults.Results = clean(newOutput);
|
|
209
|
+
resolve(promiseResults);
|
|
185
210
|
} else {
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
let instanceArr = arr[1].split(/[()]+/).filter(function (e) {
|
|
189
|
-
return e;
|
|
190
|
-
});
|
|
191
|
-
|
|
192
|
-
newOutput = {
|
|
193
|
-
host: arr[0],
|
|
194
|
-
object: instanceArr[0],
|
|
195
|
-
instance: instanceArr[1] ? instanceArr[1] : "",
|
|
196
|
-
counter: arr[2],
|
|
197
|
-
value: returnResults.Value,
|
|
198
|
-
cstatus: returnResults.CStatus,
|
|
199
|
-
};
|
|
211
|
+
promiseResults.Results = { response: "empty" };
|
|
212
|
+
resolve(promiseResults);
|
|
200
213
|
}
|
|
201
|
-
promiseResults.Results = clean(newOutput);
|
|
202
|
-
resolve(promiseResults);
|
|
203
214
|
} else {
|
|
204
|
-
promiseResults.Results =
|
|
205
|
-
|
|
215
|
+
promiseResults.Results = { response: "empty" };
|
|
216
|
+
resolve(promiseResults);
|
|
206
217
|
}
|
|
207
218
|
} else {
|
|
208
219
|
// Error checking. If the response contains a fault, we return the fault.
|
|
@@ -216,7 +227,7 @@ class perfMonService {
|
|
|
216
227
|
}
|
|
217
228
|
resolve(promiseResults);
|
|
218
229
|
} else {
|
|
219
|
-
// Error unknown.
|
|
230
|
+
// Error unknown. Reject with the response status instead. Most likely a 500 error from the server.
|
|
220
231
|
reject(response.status);
|
|
221
232
|
}
|
|
222
233
|
}
|
|
@@ -278,53 +289,69 @@ class perfMonService {
|
|
|
278
289
|
// Remove unnecessary keys
|
|
279
290
|
removeKeys(output, "$");
|
|
280
291
|
|
|
281
|
-
if (keyExists(output, "
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
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);
|
|
289
316
|
|
|
290
317
|
let instanceArr = arr[1].split(/[()]+/).filter(function (e) {
|
|
291
318
|
return e;
|
|
292
319
|
});
|
|
293
320
|
|
|
294
|
-
|
|
321
|
+
newOutput = {
|
|
295
322
|
host: arr[0],
|
|
296
323
|
object: instanceArr[0],
|
|
297
324
|
instance: instanceArr[1] ? instanceArr[1] : "",
|
|
298
325
|
counter: arr[2],
|
|
299
|
-
value:
|
|
300
|
-
cstatus:
|
|
326
|
+
value: returnResults.Value,
|
|
327
|
+
cstatus: returnResults.CStatus,
|
|
301
328
|
};
|
|
302
|
-
}
|
|
329
|
+
}
|
|
330
|
+
promiseResults.Results = clean(newOutput);
|
|
331
|
+
resolve(promiseResults);
|
|
303
332
|
} else {
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
let instanceArr = arr[1].split(/[()]+/).filter(function (e) {
|
|
307
|
-
return e;
|
|
308
|
-
});
|
|
309
|
-
|
|
310
|
-
newOutput = {
|
|
311
|
-
host: arr[0],
|
|
312
|
-
object: instanceArr[0],
|
|
313
|
-
instance: instanceArr[1] ? instanceArr[1] : "",
|
|
314
|
-
counter: arr[2],
|
|
315
|
-
value: returnResults.Value,
|
|
316
|
-
cstatus: returnResults.CStatus,
|
|
317
|
-
};
|
|
333
|
+
promiseResults.Results = { response: "empty" };
|
|
334
|
+
resolve(promiseResults);
|
|
318
335
|
}
|
|
319
|
-
promiseResults.Results = clean(newOutput);
|
|
320
|
-
resolve(promiseResults);
|
|
321
336
|
} else {
|
|
322
|
-
promiseResults.Results =
|
|
323
|
-
|
|
337
|
+
promiseResults.Results = { response: "empty" };
|
|
338
|
+
resolve(promiseResults);
|
|
324
339
|
}
|
|
325
340
|
} else {
|
|
326
|
-
|
|
327
|
-
|
|
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
|
+
}
|
|
328
355
|
}
|
|
329
356
|
} catch (e) {
|
|
330
357
|
promiseResults.Results = e;
|
|
@@ -384,19 +411,35 @@ class perfMonService {
|
|
|
384
411
|
// Remove unnecessary keys
|
|
385
412
|
removeKeys(output, "$");
|
|
386
413
|
|
|
387
|
-
if (keyExists(output, "
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
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
|
+
}
|
|
393
424
|
} else {
|
|
394
|
-
promiseResults.Results =
|
|
395
|
-
|
|
425
|
+
promiseResults.Results = { response: "empty" };
|
|
426
|
+
resolve(promiseResults);
|
|
396
427
|
}
|
|
397
428
|
} else {
|
|
398
|
-
|
|
399
|
-
|
|
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
|
+
}
|
|
400
443
|
}
|
|
401
444
|
} catch (e) {
|
|
402
445
|
promiseResults.Results = e;
|
|
@@ -457,19 +500,35 @@ class perfMonService {
|
|
|
457
500
|
// Remove unnecessary keys
|
|
458
501
|
removeKeys(output, "$");
|
|
459
502
|
|
|
460
|
-
if (keyExists(output, "
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
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
|
+
}
|
|
466
513
|
} else {
|
|
467
|
-
promiseResults.Results =
|
|
468
|
-
|
|
514
|
+
promiseResults.Results = { response: "empty" };
|
|
515
|
+
resolve(promiseResults);
|
|
469
516
|
}
|
|
470
517
|
} else {
|
|
471
|
-
|
|
472
|
-
|
|
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
|
+
}
|
|
473
532
|
}
|
|
474
533
|
} catch (e) {
|
|
475
534
|
promiseResults.Results = e;
|
|
@@ -527,19 +586,35 @@ class perfMonService {
|
|
|
527
586
|
// Remove unnecessary keys
|
|
528
587
|
removeKeys(output, "$");
|
|
529
588
|
|
|
530
|
-
if (keyExists(output, "
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
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
|
+
}
|
|
536
599
|
} else {
|
|
537
|
-
promiseResults.Results =
|
|
538
|
-
|
|
600
|
+
promiseResults.Results = { response: "empty" };
|
|
601
|
+
resolve(promiseResults);
|
|
539
602
|
}
|
|
540
603
|
} else {
|
|
541
|
-
|
|
542
|
-
|
|
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
|
+
}
|
|
543
618
|
}
|
|
544
619
|
} catch (e) {
|
|
545
620
|
promiseResults.Results = e;
|
|
@@ -604,12 +679,24 @@ class perfMonService {
|
|
|
604
679
|
promiseResults.Results = { response: "success" };
|
|
605
680
|
resolve(promiseResults);
|
|
606
681
|
} else {
|
|
607
|
-
promiseResults.Results =
|
|
682
|
+
promiseResults.Results = { response: "unknow" };
|
|
608
683
|
reject(promiseResults);
|
|
609
684
|
}
|
|
610
685
|
} else {
|
|
611
|
-
|
|
612
|
-
|
|
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
|
+
}
|
|
613
700
|
}
|
|
614
701
|
} catch (e) {
|
|
615
702
|
promiseResults.Results = e;
|
|
@@ -677,17 +764,23 @@ class perfMonService {
|
|
|
677
764
|
removeKeys(output, "$");
|
|
678
765
|
|
|
679
766
|
if (keyExists(output, "perfmonAddCounterResponse")) {
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
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
|
+
}
|
|
683
779
|
resolve(promiseResults);
|
|
684
780
|
} else {
|
|
685
|
-
|
|
686
|
-
reject(
|
|
781
|
+
// Error unknown. Reject with the response status instead. Most likely a 500 error from the server.
|
|
782
|
+
reject(response.status);
|
|
687
783
|
}
|
|
688
|
-
} else {
|
|
689
|
-
promiseResults.Results = { response: "empty" };
|
|
690
|
-
resolve(promiseResults);
|
|
691
784
|
}
|
|
692
785
|
} catch (e) {
|
|
693
786
|
promiseResults.Results = e;
|
|
@@ -760,12 +853,24 @@ class perfMonService {
|
|
|
760
853
|
promiseResults.Results = { response: "success" };
|
|
761
854
|
resolve(promiseResults);
|
|
762
855
|
} else {
|
|
763
|
-
promiseResults.Results =
|
|
764
|
-
|
|
856
|
+
promiseResults.Results = { response: "unknown" };
|
|
857
|
+
resolve(promiseResults);
|
|
765
858
|
}
|
|
766
859
|
} else {
|
|
767
|
-
|
|
768
|
-
|
|
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
|
+
}
|
|
769
874
|
}
|
|
770
875
|
} catch (e) {
|
|
771
876
|
promiseResults.Results = e;
|
|
@@ -828,18 +933,35 @@ class perfMonService {
|
|
|
828
933
|
// Remove unnecessary keys
|
|
829
934
|
removeKeys(output, "$");
|
|
830
935
|
|
|
831
|
-
if (keyExists(output, "
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
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
|
+
}
|
|
836
946
|
} else {
|
|
837
|
-
promiseResults.Results =
|
|
838
|
-
|
|
947
|
+
promiseResults.Results = { response: "empty" };
|
|
948
|
+
resolve(promiseResults);
|
|
839
949
|
}
|
|
840
950
|
} else {
|
|
841
|
-
|
|
842
|
-
|
|
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
|
+
}
|
|
843
965
|
}
|
|
844
966
|
} catch (e) {
|
|
845
967
|
promiseResults.Results = e;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cisco-perfmon",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.3",
|
|
4
4
|
"description": "A library to pull Perfmon data from Cisco VOS applications via SOAP",
|
|
5
5
|
"main": "main.js",
|
|
6
6
|
"scripts": {
|
|
@@ -25,6 +25,7 @@
|
|
|
25
25
|
},
|
|
26
26
|
"homepage": "https://github.com/sieteunoseis/cisco-perfmon#readme",
|
|
27
27
|
"dependencies": {
|
|
28
|
+
"fetch-retry": "^6.0.0",
|
|
28
29
|
"util": "*",
|
|
29
30
|
"xml2js": "*"
|
|
30
31
|
},
|
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)
|