@daemonitor/plugins 1.1.7 → 1.1.8
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.
|
@@ -88,32 +88,38 @@ async function snmpWalk(t, oid, timeout = 10000) {
|
|
|
88
88
|
}
|
|
89
89
|
async function collectPrinter(t) {
|
|
90
90
|
const warnPct = t.tonerWarnPct ?? 10;
|
|
91
|
-
|
|
91
|
+
// Walk LEVELS (clean numeric values, one per row) to get the supply indices,
|
|
92
|
+
// then fetch each supply's description/max by that index — a single get whose
|
|
93
|
+
// (possibly multi-line hex) value decodeSnmp handles, so a long description
|
|
94
|
+
// can't be split into phantom supplies and misalign the levels.
|
|
95
|
+
const [model, serial, pagesRaw, statusRaw, levelRows] = await Promise.all([
|
|
92
96
|
snmpGet(t, OID.model),
|
|
93
97
|
snmpGet(t, OID.serial),
|
|
94
98
|
snmpGet(t, OID.pages),
|
|
95
99
|
snmpGet(t, OID.status),
|
|
96
|
-
|
|
97
|
-
snmpWalk(t, OID.supplyMax),
|
|
98
|
-
snmpWalk(t, OID.supplyLevel),
|
|
100
|
+
snmpWalkIndexed(t, OID.supplyLevel),
|
|
99
101
|
]);
|
|
100
102
|
// No response at all → the printer is unreachable / SNMP off.
|
|
101
|
-
if (model == null && serial == null && pagesRaw == null && !
|
|
103
|
+
if (model == null && serial == null && pagesRaw == null && !levelRows.length) {
|
|
102
104
|
return { name: t.name, ip: t.ip, kind: "printer", reachable: false };
|
|
103
105
|
}
|
|
104
|
-
//
|
|
105
|
-
//
|
|
106
|
-
//
|
|
107
|
-
const supplies =
|
|
108
|
-
const
|
|
109
|
-
|
|
106
|
+
// prtMarkerSuppliesLevel semantics: -2 = unknown, -3 = "some remaining" (a
|
|
107
|
+
// level the device won't quantify); else a count out of MaxCapacity (which can
|
|
108
|
+
// itself be -2 = unknown).
|
|
109
|
+
const supplies = await Promise.all(levelRows.map(async (row) => {
|
|
110
|
+
const [descRaw, maxRaw] = await Promise.all([
|
|
111
|
+
snmpGet(t, `${OID.supplyDesc}.${row.idx}`),
|
|
112
|
+
snmpGet(t, `${OID.supplyMax}.${row.idx}`),
|
|
113
|
+
]);
|
|
114
|
+
const lvl = Number(row.val);
|
|
115
|
+
const max = Number(maxRaw);
|
|
110
116
|
let pct = null;
|
|
111
117
|
if (lvl === -3)
|
|
112
|
-
pct = 100;
|
|
118
|
+
pct = 100;
|
|
113
119
|
else if (lvl >= 0 && max > 0)
|
|
114
120
|
pct = Math.round((lvl / max) * 100);
|
|
115
|
-
return { name:
|
|
116
|
-
});
|
|
121
|
+
return { name: descRaw || "supply", level: lvl, max, pct };
|
|
122
|
+
}));
|
|
117
123
|
const low = supplies.filter((s) => s.pct != null && s.pct <= warnPct);
|
|
118
124
|
return {
|
|
119
125
|
name: t.name,
|