cisco-perfmon 1.6.0 → 1.6.1

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 CHANGED
@@ -112,19 +112,21 @@ const XML_REMOVE_COUNTER_ENVELOPE = (sessionHandle, counters) => `<soapenv:Envel
112
112
  * @param {string} host - The host to collect data from. This is usually the IP address/FQDN of the CUCM publisher.
113
113
  * @param {string} username - The username to authenticate with. This is usually an AXL user. Can leave this blank if using JESSIONSSO cookie.
114
114
  * @param {string} password - The password to authenticate with. This is usually an AXL user. Can leave this blank if using JESSIONSSO cookie.
115
- * @param {object} options - Additional headers to add to the request. Useful for adding cookies for SSO sessions.
115
+ * @param {object} options - Options object. Supports `retries` (default 3), `retryDelay` ms (default 5000), and any additional headers (e.g. cookies for SSO).
116
116
  * @returns {object} returns constructor object.
117
117
  */
118
118
  class perfMonService {
119
119
  constructor(host, username, password, options = {}, retry = true) {
120
120
  const RATE_LIMIT_DELAYS = [30000, 60000, 120000]; // 30s, 60s, 120s exponential backoff
121
+ const maxRetries = options.retries ?? (process.env.PM_RETRY ? parseInt(process.env.PM_RETRY) : 3);
122
+ const retryDelay = options.retryDelay ?? (process.env.PM_RETRY_DELAY ? parseInt(process.env.PM_RETRY_DELAY) : 5000);
121
123
 
122
124
  this._OPTIONS = {
123
125
  retryOn: async function (attempt, error, response) {
124
126
  if (!retry) {
125
127
  return false;
126
128
  }
127
- if (attempt > (process.env.PM_RETRY ? parseInt(process.env.PM_RETRY) : 3)) {
129
+ if (attempt > maxRetries) {
128
130
  return false;
129
131
  }
130
132
 
@@ -147,7 +149,7 @@ class perfMonService {
147
149
  // retry on any network error, or 4xx or 5xx status codes
148
150
  if (error !== null || response.status >= 400) {
149
151
  const delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
150
- await delay(process.env.PM_RETRY_DELAY ? parseInt(process.env.PM_RETRY_DELAY) : 5000);
152
+ await delay(retryDelay);
151
153
  return true;
152
154
  }
153
155
  },
@@ -204,7 +206,7 @@ class perfMonService {
204
206
  */
205
207
  async collectCounterData(host, object) {
206
208
  try {
207
- let options = this._OPTIONS;
209
+ let options = { ...this._OPTIONS, headers: { ...this._OPTIONS.headers } };
208
210
  let server = this._HOST;
209
211
  let XML = XML_COLLECT_COUNTER_ENVELOPE(escapeXml(host), escapeXml(object));
210
212
  let soapBody = Buffer.from(XML);
@@ -220,9 +222,6 @@ class perfMonService {
220
222
  };
221
223
 
222
224
  promiseResults.cookie = response.headers.get("set-cookie") ? response.headers.get("set-cookie") : "";
223
- if (promiseResults.cookie) {
224
- this.setCookie(promiseResults.cookie);
225
- }
226
225
  if (promiseResults.cookie) {
227
226
  this.setCookie(promiseResults.cookie);
228
227
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cisco-perfmon",
3
- "version": "1.6.0",
3
+ "version": "1.6.1",
4
4
  "description": "A library to pull Perfmon data from Cisco VOS applications via SOAP",
5
5
  "main": "main.js",
6
6
  "module": "main.mjs",
package/types/index.d.ts CHANGED
@@ -1,6 +1,10 @@
1
1
  export interface PerfmonOptions {
2
+ /** Max number of retries on network/HTTP errors. Defaults to PM_RETRY env var or 3. */
3
+ retries?: number;
4
+ /** Delay in ms between retries. Defaults to PM_RETRY_DELAY env var or 5000. */
5
+ retryDelay?: number;
2
6
  Cookie?: string;
3
- [key: string]: string | undefined;
7
+ [key: string]: string | number | undefined;
4
8
  }
5
9
 
6
10
  export interface PerfmonResult {