cisco-perfmon 1.4.0 → 1.4.2

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/README.md CHANGED
@@ -51,11 +51,11 @@ var counterObj = {
51
51
  console.log("Let's get a description of our counter.");
52
52
  service
53
53
  .queryCounterDescription(counterObj)
54
- .then((results) => {
55
- console.log("queryCounterDescription", results);
54
+ .then((response) => {
55
+ console.log("queryCounterDescription", response.results);
56
56
  })
57
57
  .catch((error) => {
58
- console.log(error);
58
+ console.log(error.message);
59
59
  });
60
60
  ```
61
61
 
package/main.js CHANGED
@@ -176,52 +176,45 @@ class perfMonService {
176
176
  if (keyExists(output, "perfmonCollectCounterDataResponse")) {
177
177
  if (keyExists(output, "perfmonCollectCounterDataReturn")) {
178
178
  var returnResults = output.Body.perfmonCollectCounterDataResponse.perfmonCollectCounterDataReturn;
179
- if (returnResults) {
180
- var newOutput;
181
- if (Array.isArray(returnResults)) {
182
- newOutput = returnResults.map((item) => {
183
- let arr = item.Name.split("\\").filter((element) => element);
184
-
185
- let instanceArr = arr[1].split(/[()]+/).filter(function (e) {
186
- return e;
187
- });
188
-
189
- return {
190
- host: arr[0],
191
- object: instanceArr[0],
192
- instance: instanceArr[1] ? instanceArr[1] : "",
193
- counter: arr[2],
194
- value: item.Value,
195
- cstatus: item.CStatus,
196
- };
197
- });
198
- } else {
199
- let arr = returnResults.Name.split("\\").filter((element) => element);
179
+ var newOutput;
180
+ if (Array.isArray(returnResults)) {
181
+ newOutput = returnResults.map((item) => {
182
+ let arr = item.Name.split("\\").filter((element) => element);
200
183
 
201
184
  let instanceArr = arr[1].split(/[()]+/).filter(function (e) {
202
185
  return e;
203
186
  });
204
187
 
205
- newOutput = {
188
+ return {
206
189
  host: arr[0],
207
190
  object: instanceArr[0],
208
191
  instance: instanceArr[1] ? instanceArr[1] : "",
209
192
  counter: arr[2],
210
- value: returnResults.Value,
211
- cstatus: returnResults.CStatus,
193
+ value: item.Value,
194
+ cstatus: item.CStatus,
212
195
  };
213
- }
214
- promiseResults.results = clean(newOutput);
215
- resolve(promiseResults);
196
+ });
216
197
  } else {
217
- // We expected results but got none. This is an error.
218
- errorResults.message = "No results found";
219
- reject(errorResults);
198
+ let arr = returnResults.Name.split("\\").filter((element) => element);
199
+
200
+ let instanceArr = arr[1].split(/[()]+/).filter(function (e) {
201
+ return e;
202
+ });
203
+
204
+ newOutput = {
205
+ host: arr[0],
206
+ object: instanceArr[0],
207
+ instance: instanceArr[1] ? instanceArr[1] : "",
208
+ counter: arr[2],
209
+ value: returnResults.Value,
210
+ cstatus: returnResults.CStatus,
211
+ };
220
212
  }
213
+ promiseResults.results = clean(newOutput);
214
+ resolve(promiseResults);
221
215
  } else {
222
- // We expected results but got none. This is an error.
223
- errorResults.message = "No results found";
224
- reject(errorResults);
216
+ // Return JSON with no results.
217
+ resolve(promiseResults);
225
218
  }
226
219
  } else {
227
220
  // Error checking. If the response contains a fault, we return the fault.
@@ -296,52 +289,45 @@ class perfMonService {
296
289
  if (keyExists(output, "perfmonCollectSessionDataResponse")) {
297
290
  if (keyExists(output, "perfmonCollectSessionDataReturn")) {
298
291
  var returnResults = output.Body.perfmonCollectSessionDataResponse.perfmonCollectSessionDataReturn;
299
- if (returnResults) {
300
- var newOutput;
301
- if (Array.isArray(returnResults)) {
302
- newOutput = returnResults.map((item) => {
303
- let arr = item.Name.split("\\").filter((element) => element);
304
-
305
- let instanceArr = arr[1].split(/[()]+/).filter(function (e) {
306
- return e;
307
- });
308
-
309
- return {
310
- host: arr[0],
311
- object: instanceArr[0],
312
- instance: instanceArr[1] ? instanceArr[1] : "",
313
- counter: arr[2],
314
- value: item.Value,
315
- cstatus: item.CStatus,
316
- };
317
- });
318
- } else {
319
- let arr = returnResults.Name.split("\\").filter((element) => element);
292
+ var newOutput;
293
+ if (Array.isArray(returnResults)) {
294
+ newOutput = returnResults.map((item) => {
295
+ let arr = item.Name.split("\\").filter((element) => element);
320
296
 
321
297
  let instanceArr = arr[1].split(/[()]+/).filter(function (e) {
322
298
  return e;
323
299
  });
324
300
 
325
- newOutput = {
301
+ return {
326
302
  host: arr[0],
327
303
  object: instanceArr[0],
328
304
  instance: instanceArr[1] ? instanceArr[1] : "",
329
305
  counter: arr[2],
330
- value: returnResults.Value,
331
- cstatus: returnResults.CStatus,
306
+ value: item.Value,
307
+ cstatus: item.CStatus,
332
308
  };
333
- }
334
- promiseResults.results = clean(newOutput);
335
- resolve(promiseResults);
309
+ });
336
310
  } else {
337
- // We expected results but got none. This is an error.
338
- errorResults.message = "No results found";
339
- reject(errorResults);
311
+ let arr = returnResults.Name.split("\\").filter((element) => element);
312
+
313
+ let instanceArr = arr[1].split(/[()]+/).filter(function (e) {
314
+ return e;
315
+ });
316
+
317
+ newOutput = {
318
+ host: arr[0],
319
+ object: instanceArr[0],
320
+ instance: instanceArr[1] ? instanceArr[1] : "",
321
+ counter: arr[2],
322
+ value: returnResults.Value,
323
+ cstatus: returnResults.CStatus,
324
+ };
340
325
  }
326
+ promiseResults.results = clean(newOutput);
327
+ resolve(promiseResults);
341
328
  } else {
342
- // We expected results but got none. This is an error.
343
- errorResults.message = "No results found";
344
- reject(errorResults);
329
+ // Return JSON with no results.
330
+ resolve(promiseResults);
345
331
  }
346
332
  } else {
347
333
  // Error checking. If the response contains a fault, we return the fault.
@@ -384,7 +370,7 @@ class perfMonService {
384
370
  * @param {string} host - The host to collect data from.
385
371
  * @returns {object} returns JSON via a Promise. JSON contains Session Cookie (If availible) and Results.
386
372
  */
387
- listCounter(host) {
373
+ listCounter(host,filtered = []) {
388
374
  var XML;
389
375
  var options = this._OPTIONS;
390
376
  options.SOAPAction = `perfmonListCounter`;
@@ -416,18 +402,15 @@ class perfMonService {
416
402
  if (keyExists(output, "perfmonListCounterResponse")) {
417
403
  if (keyExists(output, "perfmonListCounterReturn")) {
418
404
  var returnResults = output.Body.perfmonListCounterResponse.perfmonListCounterReturn;
419
- if (returnResults) {
420
- promiseResults.results = clean(returnResults);
421
- resolve(promiseResults);
422
- } else {
423
- // We expected results but got none. This is an error.
424
- errorResults.message = "No results found";
425
- reject(errorResults);
405
+ promiseResults.results = clean(returnResults);
406
+ if (filtered.length > 0) {
407
+ var res = promiseResults.results.filter(item => filtered.includes(item.Name));
408
+ promiseResults.results = res;
426
409
  }
410
+ resolve(promiseResults);
427
411
  } else {
428
- // We expected results but got none. This is an error.
429
- errorResults.message = "No results found";
430
- reject(errorResults);
412
+ // Return JSON with no results.
413
+ resolve(promiseResults);
431
414
  }
432
415
  } else {
433
416
  // Error checking. If the response contains a fault, we return the fault.
@@ -503,18 +486,18 @@ class perfMonService {
503
486
  if (keyExists(output, "perfmonListInstanceResponse")) {
504
487
  if (keyExists(output, "perfmonListInstanceReturn")) {
505
488
  var returnResults = output.Body.perfmonListInstanceResponse.perfmonListInstanceReturn;
506
- if (returnResults) {
507
- promiseResults.results = clean(returnResults);
508
- resolve(promiseResults);
509
- } else {
510
- // We expected results but got none. This is an error.
511
- errorResults.message = "No results found";
512
- reject(errorResults);
489
+ promiseResults.results = clean(returnResults);
490
+ if (!Array.isArray(promiseResults.results)) {
491
+ var temp = promiseResults.results;
492
+ promiseResults = {
493
+ results: [],
494
+ };
495
+ promiseResults.results.push(temp);
513
496
  }
497
+ resolve(promiseResults);
514
498
  } else {
515
- // We expected results but got none. This is an error.
516
- errorResults.message = "No results found";
517
- reject(errorResults);
499
+ // Return JSON with no results.
500
+ resolve(promiseResults);
518
501
  }
519
502
  } else {
520
503
  // Error checking. If the response contains a fault, we return the fault.
@@ -587,18 +570,11 @@ class perfMonService {
587
570
  if (keyExists(output, "perfmonOpenSessionResponse")) {
588
571
  if (keyExists(output, "perfmonOpenSessionReturn")) {
589
572
  var returnResults = output.Body.perfmonOpenSessionResponse.perfmonOpenSessionReturn;
590
- if (returnResults) {
591
- promiseResults.results = clean(returnResults);
592
- resolve(promiseResults);
593
- } else {
594
- // We expected results but got none. This is an error.
595
- errorResults.message = "No results found";
596
- reject(errorResults);
597
- }
573
+ promiseResults.results = clean(returnResults);
574
+ resolve(promiseResults);
598
575
  } else {
599
- // We expected results but got none. This is an error.
600
- errorResults.message = "No results found";
601
- reject(errorResults);
576
+ // Return JSON with no results.
577
+ resolve(promiseResults);
602
578
  }
603
579
  } else {
604
580
  // Error checking. If the response contains a fault, we return the fault.
@@ -926,18 +902,11 @@ class perfMonService {
926
902
  if (keyExists(output, "perfmonQueryCounterDescriptionResponse")) {
927
903
  if (keyExists(output, "perfmonQueryCounterDescriptionReturn")) {
928
904
  var returnResults = output.Body.perfmonQueryCounterDescriptionResponse.perfmonQueryCounterDescriptionReturn;
929
- if (returnResults) {
930
- promiseResults.results = clean(returnResults);
931
- resolve(promiseResults);
932
- } else {
933
- // We expected results but got none. This is an error.
934
- errorResults.message = "No results found";
935
- reject(errorResults);
936
- }
905
+ promiseResults.results = clean(returnResults);
906
+ resolve(promiseResults);
937
907
  } else {
938
- // We expected results but got none. This is an error.
939
- errorResults.message = "No results found";
940
- reject(errorResults);
908
+ // Return JSON with no results.
909
+ resolve(promiseResults);
941
910
  }
942
911
  } else {
943
912
  // Error checking. If the response contains a fault, we return the fault.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cisco-perfmon",
3
- "version": "1.4.0",
3
+ "version": "1.4.2",
4
4
  "description": "A library to pull Perfmon data from Cisco VOS applications via SOAP",
5
5
  "main": "main.js",
6
6
  "scripts": {
package/test/tests.js CHANGED
@@ -34,7 +34,6 @@ var counterObj = {
34
34
  counter: "% Mem Used",
35
35
  };
36
36
 
37
- var serviceSSO = "";
38
37
 
39
38
  (async () => {
40
39
  console.log("Let's get a description of our counter. We will also retrieve a cookie to use for the rest of the session.");
@@ -43,7 +42,7 @@ var serviceSSO = "";
43
42
  .then((response) => {
44
43
  console.log("queryCounterDescription: ", response.results);
45
44
  if (response.cookie) {
46
- serviceSSO = new perfMonService(env.CUCM_HOSTNAME, "", "", { Cookie: response.cookie });
45
+ service = new perfMonService(env.CUCM_HOSTNAME, "", "", { Cookie: response.cookie });
47
46
  }
48
47
  })
49
48
  .catch((error) => {
@@ -51,7 +50,7 @@ var serviceSSO = "";
51
50
  });
52
51
 
53
52
  console.log("Let's collect some non session counter data.");
54
- await serviceSSO
53
+ await service
55
54
  .collectCounterData(cucmServerName, "Cisco CallManager")
56
55
  .then((response) => {
57
56
  console.log("collectCounterData", response.results);
@@ -61,27 +60,27 @@ var serviceSSO = "";
61
60
  });
62
61
 
63
62
  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
- await serviceSSO
63
+ await service
65
64
  .openSession()
66
65
  .then(async (response) => {
67
66
  console.log("SessionID", response.results);
68
67
  SessionID = response.results;
69
- await serviceSSO
68
+ await service
70
69
  .addCounter(SessionID, counterObj)
71
70
  .then(async (response) => {
72
71
  console.log("addCounter", response.results);
73
72
  const delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
74
73
  console.log("Wait 30 seconds");
75
74
  await delay(30000); /// waiting 30 second.
76
- await serviceSSO
75
+ await service
77
76
  .collectSessionData(SessionID)
78
77
  .then(async (response) => {
79
78
  console.log("collectSessionData", response.results);
80
- await serviceSSO
79
+ await service
81
80
  .removeCounter(SessionID, response.results)
82
81
  .then(async (response) => {
83
82
  console.log("removeCounter", response.results);
84
- await serviceSSO
83
+ await service
85
84
  .closeSession(SessionID)
86
85
  .then((response) => {
87
86
  console.log("closeSession", response.results);
@@ -107,7 +106,7 @@ var serviceSSO = "";
107
106
  });
108
107
 
109
108
  console.log("Let's returns the list of available PerfMon objects and counters on a particular host");
110
- await serviceSSO
109
+ await service
111
110
  .listCounter(cucmServerName)
112
111
  .then((response) => {
113
112
  console.log("listCounter", response.results);
@@ -117,7 +116,7 @@ var serviceSSO = "";
117
116
  });
118
117
 
119
118
  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
- await serviceSSO
119
+ await service
121
120
  .listInstance(cucmServerName, "Processor")
122
121
  .then((results) => {
123
122
  console.log("listInstance", results.results);