@daemonitor/plugins 1.1.19 → 1.1.20

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.
@@ -168,20 +168,30 @@ async function collectDevice(t) {
168
168
  snmpGet(t, SYS.descr),
169
169
  snmpGet(t, SYS.name),
170
170
  snmpGet(t, SYS.uptime),
171
- snmpWalk(t, SYS.ifOper),
172
- snmpWalk(t, SYS.ifAdmin),
171
+ snmpWalkIndexed(t, SYS.ifOper),
172
+ snmpWalkIndexed(t, SYS.ifAdmin),
173
173
  ]);
174
174
  if (descr == null && name == null && !oper.length) {
175
175
  return { name: t.name, ip: t.ip, kind: t.kind || "device", reachable: false };
176
176
  }
177
+ // Index the link-state walks by ifIndex so each interface can carry its own
178
+ // up/down (positional zipping breaks whenever the two walks differ in length).
179
+ const byIndex = (rows) => {
180
+ const m = {};
181
+ for (const r of rows)
182
+ m[r.idx] = r.val;
183
+ return m;
184
+ };
185
+ const operByIdx = byIndex(oper);
186
+ const adminByIdx = byIndex(admin);
177
187
  // Only count ADMIN-enabled ports; an enabled port that's operationally down is
178
188
  // a real link-down (ignore the many disabled ports on a big switch).
179
189
  let portsTotal = 0;
180
190
  let portsUp = 0;
181
- for (let i = 0; i < oper.length; i++) {
182
- if (Number(admin[i]) === 1) {
191
+ for (const idx of Object.keys(adminByIdx)) {
192
+ if (Number(adminByIdx[idx]) === 1) {
183
193
  portsTotal++;
184
- if (Number(oper[i]) === 1)
194
+ if (Number(operByIdx[idx]) === 1)
185
195
  portsUp++;
186
196
  }
187
197
  }
@@ -231,15 +241,9 @@ async function collectDevice(t) {
231
241
  // "internet traffic". Without one, the headline is left undefined rather than
232
242
  // reporting a number we know to be wrong.
233
243
  const PSEUDO = /^(lo|imq\d*|itf\d*|ifb\d*|sit\d*|gre\d*|teql\d*|tunl\d*)$/i;
234
- const idxOf = (rows) => {
235
- const m = {};
236
- for (const r of rows)
237
- m[r.idx] = r.val;
238
- return m;
239
- };
240
- const nameByIdx = idxOf(ifNames);
241
- const inByIdx = idxOf(hcInIdx);
242
- const outByIdx = idxOf(hcOutIdx);
244
+ const nameByIdx = byIndex(ifNames);
245
+ const inByIdx = byIndex(hcInIdx);
246
+ const outByIdx = byIndex(hcOutIdx);
243
247
  const now = Date.now();
244
248
  const prevIf = netPrevIf[t.ip] || {};
245
249
  const nextIf = {};
@@ -261,7 +265,11 @@ async function collectDevice(t) {
261
265
  outBps = Math.round((cout - p.out) / dt);
262
266
  }
263
267
  }
264
- interfaces.push({ name, inBps, outBps });
268
+ // ifOperStatus 1=up, ifAdminStatus 1=enabled. A link that's admin-enabled but
269
+ // 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;
272
+ interfaces.push({ name, inBps, outBps, up: linkUp, adminUp });
265
273
  }
266
274
  netPrevIf[t.ip] = nextIf;
267
275
  // Headline = the WAN link when the target names one.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@daemonitor/plugins",
3
- "version": "1.1.19",
3
+ "version": "1.1.20",
4
4
  "description": "daemonitor plugins",
5
5
  "types": "types/index.d.ts",
6
6
  "main": "dist/index.js",