cisco-perfmon 1.3.4 → 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.
Files changed (3) hide show
  1. package/main.js +152 -159
  2. package/package.json +2 -2
  3. 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 Session Cookie (If availible) and Results.
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,11 +155,6 @@ 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) => {
@@ -208,37 +214,40 @@ class perfMonService {
208
214
  promiseResults.results = clean(newOutput);
209
215
  resolve(promiseResults);
210
216
  } else {
211
- promiseResults.results = { response: "empty" };
212
- resolve(promiseResults);
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
- promiseResults.results = { response: "empty" };
216
- resolve(promiseResults);
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
- promiseResults.results = { faultcode: "RateControl", faultstring: output.Body.Fault.faultstring };
230
+ errorResults.message = { faultcode: "RateControl", faultstring: output.Body.Fault.faultstring };
223
231
  } else if (output.Body.Fault.faultcode.includes("generalException")) {
224
- promiseResults.results = { faultcode: "generalException", faultstring: output.Body.Fault.faultstring };
232
+ errorResults.message = { faultcode: "generalException", faultstring: output.Body.Fault.faultstring };
225
233
  } else {
226
- promiseResults.results = { faultcode: output.Body.Fault.faultcode, faultstring: output.Body.Fault.faultstring };
234
+ errorResults.message = { faultcode: output.Body.Fault.faultcode, faultstring: output.Body.Fault.faultstring };
227
235
  }
228
- resolve(promiseResults);
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
- reject(response.status);
239
+ errorResults.message = response.status;
240
+ reject(errorResults);
232
241
  }
233
242
  }
234
243
  } catch (e) {
235
- promiseResults.results = e;
236
- reject(promiseResults);
244
+ errorResults.message = e;
245
+ reject(errorResults);
237
246
  }
238
247
  })
239
248
  .catch((error) => {
240
- promiseResults.results = error;
241
- reject(promiseResults);
249
+ errorResults.message = error;
250
+ reject(errorResults);
242
251
  }); // catches the error and logs it
243
252
  });
244
253
  }
@@ -267,11 +276,6 @@ 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) => {
@@ -330,37 +334,40 @@ class perfMonService {
330
334
  promiseResults.results = clean(newOutput);
331
335
  resolve(promiseResults);
332
336
  } else {
333
- promiseResults.results = { response: "empty" };
334
- resolve(promiseResults);
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
- promiseResults.results = { response: "empty" };
338
- resolve(promiseResults);
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
- promiseResults.results = { faultcode: "RateControl", faultstring: output.Body.Fault.faultstring };
350
+ errorResults.message = { faultcode: "RateControl", faultstring: output.Body.Fault.faultstring };
345
351
  } else if (output.Body.Fault.faultcode.includes("generalException")) {
346
- promiseResults.results = { faultcode: "generalException", faultstring: output.Body.Fault.faultstring };
352
+ errorResults.message = { faultcode: "generalException", faultstring: output.Body.Fault.faultstring };
347
353
  } else {
348
- promiseResults.results = { faultcode: output.Body.Fault.faultcode, faultstring: output.Body.Fault.faultstring };
354
+ errorResults.message = { faultcode: output.Body.Fault.faultcode, faultstring: output.Body.Fault.faultstring };
349
355
  }
350
- resolve(promiseResults);
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
- reject(response.status);
359
+ errorResults.message = response.status;
360
+ reject(errorResults);
354
361
  }
355
362
  }
356
363
  } catch (e) {
357
- promiseResults.results = e;
358
- reject(promiseResults);
364
+ errorResults.message = e;
365
+ reject(errorResults);
359
366
  }
360
367
  })
361
368
  .catch((error) => {
362
- promiseResults.results = error;
363
- reject(promiseResults);
369
+ errorResults.message = error;
370
+ reject(errorResults);
364
371
  }); // catches the error and logs it
365
372
  });
366
373
  }
@@ -389,11 +396,6 @@ 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) => {
@@ -418,37 +420,40 @@ class perfMonService {
418
420
  promiseResults.results = clean(returnResults);
419
421
  resolve(promiseResults);
420
422
  } else {
421
- promiseResults.results = { response: "empty" };
422
- resolve(promiseResults);
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
- promiseResults.results = { response: "empty" };
426
- resolve(promiseResults);
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
- promiseResults.results = { faultcode: "RateControl", faultstring: output.Body.Fault.faultstring };
436
+ errorResults.message = { faultcode: "RateControl", faultstring: output.Body.Fault.faultstring };
433
437
  } else if (output.Body.Fault.faultcode.includes("generalException")) {
434
- promiseResults.results = { faultcode: "generalException", faultstring: output.Body.Fault.faultstring };
438
+ errorResults.message = { faultcode: "generalException", faultstring: output.Body.Fault.faultstring };
435
439
  } else {
436
- promiseResults.results = { faultcode: output.Body.Fault.faultcode, faultstring: output.Body.Fault.faultstring };
440
+ errorResults.message = { faultcode: output.Body.Fault.faultcode, faultstring: output.Body.Fault.faultstring };
437
441
  }
438
- resolve(promiseResults);
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
- reject(response.status);
445
+ errorResults.message = response.status;
446
+ reject(errorResults);
442
447
  }
443
448
  }
444
449
  } catch (e) {
445
- promiseResults.results = e;
446
- reject(promiseResults);
450
+ errorResults.message = e;
451
+ reject(errorResults);
447
452
  }
448
453
  })
449
454
  .catch((error) => {
450
- promiseResults.results = error;
451
- reject(promiseResults);
455
+ errorResults.message = error;
456
+ reject(errorResults);
452
457
  }); // catches the error and logs it
453
458
  });
454
459
  }
@@ -478,11 +483,6 @@ 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) => {
@@ -507,37 +507,40 @@ class perfMonService {
507
507
  promiseResults.results = clean(returnResults);
508
508
  resolve(promiseResults);
509
509
  } else {
510
- promiseResults.results = { response: "empty" };
511
- resolve(promiseResults);
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
- promiseResults.results = { response: "empty" };
515
- resolve(promiseResults);
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
- promiseResults.results = { faultcode: "RateControl", faultstring: output.Body.Fault.faultstring };
523
+ errorResults.message = { faultcode: "RateControl", faultstring: output.Body.Fault.faultstring };
522
524
  } else if (output.Body.Fault.faultcode.includes("generalException")) {
523
- promiseResults.results = { faultcode: "generalException", faultstring: output.Body.Fault.faultstring };
525
+ errorResults.message = { faultcode: "generalException", faultstring: output.Body.Fault.faultstring };
524
526
  } else {
525
- promiseResults.results = { faultcode: output.Body.Fault.faultcode, faultstring: output.Body.Fault.faultstring };
527
+ errorResults.message = { faultcode: output.Body.Fault.faultcode, faultstring: output.Body.Fault.faultstring };
526
528
  }
527
- resolve(promiseResults);
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
- reject(response.status);
532
+ errorResults.message = response.status;
533
+ reject(errorResults);
531
534
  }
532
535
  }
533
536
  } catch (e) {
534
- promiseResults.results = e;
535
- reject(promiseResults);
537
+ errorResults.message = e;
538
+ reject(errorResults);
536
539
  }
537
540
  })
538
541
  .catch((error) => {
539
- promiseResults.results = error;
540
- reject(promiseResults);
542
+ errorResults.message = error;
543
+ reject(errorResults);
541
544
  }); // catches the error and logs it
542
545
  });
543
546
  }
@@ -564,11 +567,6 @@ 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) => {
@@ -593,37 +591,40 @@ class perfMonService {
593
591
  promiseResults.results = clean(returnResults);
594
592
  resolve(promiseResults);
595
593
  } else {
596
- promiseResults.results = { response: "empty" };
597
- resolve(promiseResults);
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
- promiseResults.results = { response: "empty" };
601
- resolve(promiseResults);
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
- promiseResults.results = { faultcode: "RateControl", faultstring: output.Body.Fault.faultstring };
607
+ errorResults.message = { faultcode: "RateControl", faultstring: output.Body.Fault.faultstring };
608
608
  } else if (output.Body.Fault.faultcode.includes("generalException")) {
609
- promiseResults.results = { faultcode: "generalException", faultstring: output.Body.Fault.faultstring };
609
+ errorResults.message = { faultcode: "generalException", faultstring: output.Body.Fault.faultstring };
610
610
  } else {
611
- promiseResults.results = { faultcode: output.Body.Fault.faultcode, faultstring: output.Body.Fault.faultstring };
611
+ errorResults.message = { faultcode: output.Body.Fault.faultcode, faultstring: output.Body.Fault.faultstring };
612
612
  }
613
- resolve(promiseResults);
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
- reject(response.status);
616
+ errorResults.message = response.status;
617
+ reject(errorResults);
617
618
  }
618
619
  }
619
620
  } catch (e) {
620
- promiseResults.results = e;
621
- reject(promiseResults);
621
+ errorResults.message = e;
622
+ reject(errorResults);
622
623
  }
623
624
  })
624
625
  .catch((error) => {
625
- promiseResults.results = error;
626
- reject(promiseResults);
626
+ errorResults.message = error;
627
+ reject(errorResults);
627
628
  }); // catches the error and logs it
628
629
  });
629
630
  }
@@ -651,11 +652,6 @@ 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) => {
@@ -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.results = { response: "success" };
675
+ promiseResults.results = "success";
680
676
  resolve(promiseResults);
681
677
  } else {
682
- promiseResults.results = { response: "unknow" };
683
- reject(promiseResults);
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
- promiseResults.results = { faultcode: "RateControl", faultstring: output.Body.Fault.faultstring };
685
+ errorResults.message = { faultcode: "RateControl", faultstring: output.Body.Fault.faultstring };
690
686
  } else if (output.Body.Fault.faultcode.includes("generalException")) {
691
- promiseResults.results = { faultcode: "generalException", faultstring: output.Body.Fault.faultstring };
687
+ errorResults.message = { faultcode: "generalException", faultstring: output.Body.Fault.faultstring };
692
688
  } else {
693
- promiseResults.results = { faultcode: output.Body.Fault.faultcode, faultstring: output.Body.Fault.faultstring };
689
+ errorResults.message = { faultcode: output.Body.Fault.faultcode, faultstring: output.Body.Fault.faultstring };
694
690
  }
695
- resolve(promiseResults);
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
- reject(response.status);
694
+ errorResults.message = response.status;
695
+ reject(errorResults);
699
696
  }
700
697
  }
701
698
  } catch (e) {
702
- promiseResults.results = e;
703
- reject(promiseResults);
699
+ errorResults.message = e;
700
+ reject(errorResults);
704
701
  }
705
702
  })
706
703
  .catch((error) => {
707
- promiseResults.results = error;
708
- reject(promiseResults);
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
- promiseResults.results = { response: "success" };
768
- resolve(promiseResults);
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
- promiseResults.results = { faultcode: "RateControl", faultstring: output.Body.Fault.faultstring };
771
+ errorResults.message = { faultcode: "RateControl", faultstring: output.Body.Fault.faultstring };
774
772
  } else if (output.Body.Fault.faultcode.includes("generalException")) {
775
- promiseResults.results = { faultcode: "generalException", faultstring: output.Body.Fault.faultstring };
773
+ errorResults.message = { faultcode: "generalException", faultstring: output.Body.Fault.faultstring };
776
774
  } else {
777
- promiseResults.results = { faultcode: output.Body.Fault.faultcode, faultstring: output.Body.Fault.faultstring };
775
+ errorResults.message = { faultcode: output.Body.Fault.faultcode, faultstring: output.Body.Fault.faultstring };
778
776
  }
779
- resolve(promiseResults);
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
- reject(response.status);
780
+ errorResults.message = response.status;
781
+ reject(errorResults);
783
782
  }
784
783
  }
785
784
  } catch (e) {
786
- promiseResults.results = e;
787
- reject(promiseResults);
785
+ errorResults.message = e;
786
+ reject(errorResults);
788
787
  }
789
788
  })
790
789
  .catch((error) => {
791
- promiseResults.results = error;
792
- reject(promiseResults);
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.results = { response: "success" };
847
+ promiseResults.results = "success";
854
848
  resolve(promiseResults);
855
849
  } else {
856
- promiseResults.results = { response: "unknown" };
857
- resolve(promiseResults);
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
- promiseResults.results = { faultcode: "RateControl", faultstring: output.Body.Fault.faultstring };
857
+ errorResults.message = { faultcode: "RateControl", faultstring: output.Body.Fault.faultstring };
864
858
  } else if (output.Body.Fault.faultcode.includes("generalException")) {
865
- promiseResults.results = { faultcode: "generalException", faultstring: output.Body.Fault.faultstring };
859
+ errorResults.message = { faultcode: "generalException", faultstring: output.Body.Fault.faultstring };
866
860
  } else {
867
- promiseResults.results = { faultcode: output.Body.Fault.faultcode, faultstring: output.Body.Fault.faultstring };
861
+ errorResults.message = { faultcode: output.Body.Fault.faultcode, faultstring: output.Body.Fault.faultstring };
868
862
  }
869
- resolve(promiseResults);
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
- reject(response.status);
866
+ errorResults.message = response.status;
867
+ reject(errorResults);
873
868
  }
874
869
  }
875
870
  } catch (e) {
876
- promiseResults.results = e;
877
- reject(promiseResults);
871
+ errorResults.message = e;
872
+ reject(errorResults);
878
873
  }
879
874
  })
880
875
  .catch((error) => {
881
- promiseResults.results = error;
882
- reject(promiseResults);
876
+ errorResults.message = error;
877
+ reject(errorResults);
883
878
  }); // catches the error and logs it
884
879
  });
885
880
  }
@@ -910,11 +905,6 @@ 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) => {
@@ -940,37 +930,40 @@ class perfMonService {
940
930
  promiseResults.results = clean(returnResults);
941
931
  resolve(promiseResults);
942
932
  } else {
943
- promiseResults.results = { response: "empty" };
944
- resolve(promiseResults);
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
- promiseResults.results = { response: "empty" };
948
- resolve(promiseResults);
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
- promiseResults.results = { faultcode: "RateControl", faultstring: output.Body.Fault.faultstring };
946
+ errorResults.message = { faultcode: "RateControl", faultstring: output.Body.Fault.faultstring };
955
947
  } else if (output.Body.Fault.faultcode.includes("generalException")) {
956
- promiseResults.results = { faultcode: "generalException", faultstring: output.Body.Fault.faultstring };
948
+ errorResults.message = { faultcode: "generalException", faultstring: output.Body.Fault.faultstring };
957
949
  } else {
958
- promiseResults.results = { faultcode: output.Body.Fault.faultcode, faultstring: output.Body.Fault.faultstring };
950
+ errorResults.message = { faultcode: output.Body.Fault.faultcode, faultstring: output.Body.Fault.faultstring };
959
951
  }
960
- resolve(promiseResults);
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
- reject(response.status);
955
+ errorResults.message = response.status;
956
+ reject(errorResults);
964
957
  }
965
958
  }
966
959
  } catch (e) {
967
- promiseResults.results = e;
968
- reject(promiseResults);
960
+ errorResults.message = e;
961
+ reject(errorResults);
969
962
  }
970
963
  })
971
964
  .catch((error) => {
972
- promiseResults.results = error;
973
- reject(promiseResults);
965
+ errorResults.message = error;
966
+ reject(errorResults);
974
967
  }); // catches the error and logs it
975
968
  });
976
969
  }
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "cisco-perfmon",
3
- "version": "1.3.4",
3
+ "version": "1.4.0",
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=development node ./test/tests.js",
7
+ "test": "NODE_OPTIONS=--experimental-vm-modules NODE_NO_WARNINGS=1 NODE_TLS_REJECT_UNAUTHORIZED=0 NODE_ENV=test 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
@@ -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((results) => {
44
- console.log("queryCounterDescription: ", results.Results);
45
- if (results.Cookie) {
46
- serviceSSO = new perfMonService(env.CUCM_HOSTNAME, "", "", { Cookie: results.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((results) => {
57
- console.log("collectCounterData", results.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 (results) => {
67
- console.log("SessionID", results.Results);
68
- SessionID = results.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 (results) => {
72
- console.log("addCounter", results.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 (results) => {
79
- console.log("collectSessionData", results.Results);
78
+ .then(async (response) => {
79
+ console.log("collectSessionData", response.results);
80
80
  await serviceSSO
81
- .removeCounter(SessionID, results.Results)
82
- .then(async (results) => {
83
- console.log("removeCounter", results.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((results) => {
87
- console.log("closeSession", results.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((results) => {
113
- console.log("listCounter", results.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.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
  })();