@daemonitor/plugins 1.1.3 → 1.1.4
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.
|
@@ -21,6 +21,14 @@ const OID = {
|
|
|
21
21
|
supplyLevel: "1.3.6.1.2.1.43.11.1.1.9", // prtMarkerSuppliesLevel (walk)
|
|
22
22
|
};
|
|
23
23
|
const PRINTER_STATUS = { "1": "other", "2": "unknown", "3": "idle", "4": "printing", "5": "warmup" };
|
|
24
|
+
// Generic SYSTEM / IF-MIB OIDs (switches, APs, anything SNMP-capable).
|
|
25
|
+
const SYS = {
|
|
26
|
+
descr: "1.3.6.1.2.1.1.1.0", // sysDescr
|
|
27
|
+
uptime: "1.3.6.1.2.1.1.3.0", // sysUpTime (timeticks, 1/100s)
|
|
28
|
+
name: "1.3.6.1.2.1.1.5.0", // sysName
|
|
29
|
+
ifOper: "1.3.6.1.2.1.2.2.1.8", // ifOperStatus (walk): 1=up 2=down
|
|
30
|
+
ifAdmin: "1.3.6.1.2.1.2.2.1.7", // ifAdminStatus (walk): 1=up (enabled)
|
|
31
|
+
};
|
|
24
32
|
function slug(s) {
|
|
25
33
|
return s.replace(/[^a-zA-Z0-9_.-]+/g, "-").replace(/^-+|-+$/g, "");
|
|
26
34
|
}
|
|
@@ -86,6 +94,45 @@ async function collectPrinter(t) {
|
|
|
86
94
|
warnPct,
|
|
87
95
|
};
|
|
88
96
|
}
|
|
97
|
+
// Generic SNMP device (switch/AP/…): identity, uptime, and enabled-port link
|
|
98
|
+
// state so a down uplink or dead switch surfaces. Reachability via SNMP is more
|
|
99
|
+
// reliable than ICMP — many devices drop ping but answer SNMP.
|
|
100
|
+
async function collectDevice(t) {
|
|
101
|
+
const [descr, name, uptimeRaw, oper, admin] = await Promise.all([
|
|
102
|
+
snmpGet(t, SYS.descr),
|
|
103
|
+
snmpGet(t, SYS.name),
|
|
104
|
+
snmpGet(t, SYS.uptime),
|
|
105
|
+
snmpWalk(t, SYS.ifOper),
|
|
106
|
+
snmpWalk(t, SYS.ifAdmin),
|
|
107
|
+
]);
|
|
108
|
+
if (descr == null && name == null && !oper.length) {
|
|
109
|
+
return { name: t.name, ip: t.ip, kind: t.kind || "device", reachable: false };
|
|
110
|
+
}
|
|
111
|
+
// Only count ADMIN-enabled ports; an enabled port that's operationally down is
|
|
112
|
+
// a real link-down (ignore the many disabled ports on a big switch).
|
|
113
|
+
let portsTotal = 0;
|
|
114
|
+
let portsUp = 0;
|
|
115
|
+
for (let i = 0; i < oper.length; i++) {
|
|
116
|
+
if (Number(admin[i]) === 1) {
|
|
117
|
+
portsTotal++;
|
|
118
|
+
if (Number(oper[i]) === 1)
|
|
119
|
+
portsUp++;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
// sysUpTime timeticks → seconds
|
|
123
|
+
const upSecs = uptimeRaw != null ? Math.round((Number(String(uptimeRaw).replace(/[^0-9]/g, "")) || 0) / 100) : undefined;
|
|
124
|
+
return {
|
|
125
|
+
name: t.name,
|
|
126
|
+
ip: t.ip,
|
|
127
|
+
kind: t.kind || "device",
|
|
128
|
+
reachable: true,
|
|
129
|
+
sysDescr: descr || undefined,
|
|
130
|
+
sysName: name || undefined,
|
|
131
|
+
uptimeSecs: upSecs,
|
|
132
|
+
portsUp,
|
|
133
|
+
portsTotal,
|
|
134
|
+
};
|
|
135
|
+
}
|
|
89
136
|
export function createSnmpPlugin() {
|
|
90
137
|
let refreshTimer = null;
|
|
91
138
|
const targetsOf = (plugin) => {
|
|
@@ -97,7 +144,7 @@ export function createSnmpPlugin() {
|
|
|
97
144
|
const refreshFn = async (plugin) => {
|
|
98
145
|
await Promise.all(targetsOf(plugin).map(async (t) => {
|
|
99
146
|
try {
|
|
100
|
-
const data = t.kind === "printer" || !t.kind ? await collectPrinter(t) :
|
|
147
|
+
const data = t.kind === "printer" || !t.kind ? await collectPrinter(t) : await collectDevice(t);
|
|
101
148
|
await plugin.send(data, `snmp-${slug(t.name || t.ip)}`);
|
|
102
149
|
}
|
|
103
150
|
catch (e) {
|