@daemonitor/plugins 1.1.20 → 1.1.21

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.
@@ -92,7 +92,7 @@ function decodeSnmp(s) {
92
92
  }
93
93
  async function snmpGet(t, oid, timeout = 8000) {
94
94
  try {
95
- const { stdout } = await pexec("snmpget", ["-v", t.version || "2c", "-c", t.community || "public", "-Ovq", "-t", "2", "-r", "1", t.ip, oid], { timeout });
95
+ const { stdout } = await pexec("snmpget", ["-v", t.version || "2c", "-c", t.community || "public", "-Oevq", "-t", "2", "-r", "1", t.ip, oid], { timeout });
96
96
  const raw = stdout.trim().replace(/^"|"$/g, "");
97
97
  if (!raw || /No Such|no response|Timeout/i.test(raw))
98
98
  return null;
@@ -104,7 +104,7 @@ async function snmpGet(t, oid, timeout = 8000) {
104
104
  }
105
105
  async function snmpWalk(t, oid, timeout = 10000) {
106
106
  try {
107
- const { stdout } = await pexec("snmpwalk", ["-v", t.version || "2c", "-c", t.community || "public", "-Oqv", "-t", "2", "-r", "1", t.ip, oid], { timeout });
107
+ const { stdout } = await pexec("snmpwalk", ["-v", t.version || "2c", "-c", t.community || "public", "-Oeqv", "-t", "2", "-r", "1", t.ip, oid], { timeout });
108
108
  return stdout.split("\n").map((l) => decodeSnmp(l.trim().replace(/^"|"$/g, ""))).filter(Boolean);
109
109
  }
110
110
  catch {
@@ -184,14 +184,22 @@ async function collectDevice(t) {
184
184
  };
185
185
  const operByIdx = byIndex(oper);
186
186
  const adminByIdx = byIndex(admin);
187
+ // Values arrive numeric (-Oe), but tolerate an enum rendering like "up(1)"
188
+ // from any agent/MIB combination that slips one through.
189
+ const enumNum = (v) => {
190
+ if (v == null)
191
+ return undefined;
192
+ const m = /\((\d+)\)\s*$/.exec(v) || /^\s*(-?\d+)\s*$/.exec(v);
193
+ return m ? Number(m[1]) : undefined;
194
+ };
187
195
  // Only count ADMIN-enabled ports; an enabled port that's operationally down is
188
196
  // a real link-down (ignore the many disabled ports on a big switch).
189
197
  let portsTotal = 0;
190
198
  let portsUp = 0;
191
199
  for (const idx of Object.keys(adminByIdx)) {
192
- if (Number(adminByIdx[idx]) === 1) {
200
+ if (enumNum(adminByIdx[idx]) === 1) {
193
201
  portsTotal++;
194
- if (Number(operByIdx[idx]) === 1)
202
+ if (enumNum(operByIdx[idx]) === 1)
195
203
  portsUp++;
196
204
  }
197
205
  }
@@ -267,8 +275,8 @@ async function collectDevice(t) {
267
275
  }
268
276
  // ifOperStatus 1=up, ifAdminStatus 1=enabled. A link that's admin-enabled but
269
277
  // operationally down is a real fault; an admin-disabled port is just off.
270
- const adminUp = adminByIdx[idx] != null ? Number(adminByIdx[idx]) === 1 : undefined;
271
- const linkUp = operByIdx[idx] != null ? Number(operByIdx[idx]) === 1 : undefined;
278
+ const adminUp = adminByIdx[idx] != null ? enumNum(adminByIdx[idx]) === 1 : undefined;
279
+ const linkUp = operByIdx[idx] != null ? enumNum(operByIdx[idx]) === 1 : undefined;
272
280
  interfaces.push({ name, inBps, outBps, up: linkUp, adminUp });
273
281
  }
274
282
  netPrevIf[t.ip] = nextIf;
@@ -306,7 +314,7 @@ async function collectDevice(t) {
306
314
  // hrStorage table entries for the data volumes.
307
315
  async function snmpWalkIndexed(t, oid, timeout = 10000) {
308
316
  try {
309
- const { stdout } = await pexec("snmpwalk", ["-v", t.version || "2c", "-c", t.community || "public", "-On", "-t", "2", "-r", "1", t.ip, oid], { timeout });
317
+ const { stdout } = await pexec("snmpwalk", ["-v", t.version || "2c", "-c", t.community || "public", "-Oen", "-t", "2", "-r", "1", t.ip, oid], { timeout });
310
318
  return stdout.split("\n").map((l) => {
311
319
  const m = /^(\S+)\s*=\s*[^:]+:\s*(.*)$/.exec(l.trim());
312
320
  if (!m)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@daemonitor/plugins",
3
- "version": "1.1.20",
3
+ "version": "1.1.21",
4
4
  "description": "daemonitor plugins",
5
5
  "types": "types/index.d.ts",
6
6
  "main": "dist/index.js",