@daemonitor/plugins 1.1.20 → 1.1.23

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.
@@ -128,6 +128,38 @@ async function collectContainers(bin) {
128
128
  catch (err) {
129
129
  console.error("docker: inspect collection failed:", err.message);
130
130
  }
131
+ // 4. For UNHEALTHY containers only, read the healthcheck's own last output.
132
+ //
133
+ // "1/13 containers unhealthy" says a problem exists and nothing about what it
134
+ // is. Docker already stores the failing command's output in
135
+ // .State.Health.Log[] — that is the actual error text, and without it an alert
136
+ // sends someone to ssh into the box to run the same healthcheck by hand.
137
+ //
138
+ // Read one container at a time and only for the unhealthy ones. The batched
139
+ // inspect above avoids .State.Health because the template errors for
140
+ // containers that have no healthcheck; a container reporting "(unhealthy)"
141
+ // necessarily has one, so this is safe, and it is a handful of calls at most
142
+ // precisely when something is wrong.
143
+ const unhealthy = containers.filter((c) => c.health === "unhealthy").slice(0, 5);
144
+ for (const c of unhealthy) {
145
+ try {
146
+ const { stdout } = await execAsync(`${bin} inspect --format '{{json .State.Health}}' ${c.id}`, EXEC_OPTS);
147
+ const h = JSON.parse(stdout.trim() || "null");
148
+ if (!h)
149
+ continue;
150
+ c.healthFailingStreak = Number(h.FailingStreak) || 0;
151
+ const last = Array.isArray(h.Log) && h.Log.length ? h.Log[h.Log.length - 1] : null;
152
+ if (last?.Output) {
153
+ // Healthcheck output is often multi-line and ends in a newline; collapse
154
+ // it so it fits an alert line, and keep the head where the error is.
155
+ c.healthOutput = String(last.Output).replace(/\s+/g, " ").trim().slice(0, 300);
156
+ }
157
+ }
158
+ catch (err) {
159
+ // Best-effort: an alert naming the container is still better than none.
160
+ console.error(`docker: health log read failed for ${c.name}:`, err.message);
161
+ }
162
+ }
131
163
  return containers;
132
164
  }
133
165
  export function createDockerPlugin() {
@@ -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,15 +1,10 @@
1
1
  {
2
2
  "name": "@daemonitor/plugins",
3
- "version": "1.1.20",
3
+ "version": "1.1.23",
4
4
  "description": "daemonitor plugins",
5
5
  "types": "types/index.d.ts",
6
6
  "main": "dist/index.js",
7
7
  "type": "module",
8
- "scripts": {
9
- "build": "tsc",
10
- "test": "echo \"Error: no test specified\" && exit 1",
11
- "prepublishOnly": "npm run build"
12
- },
13
8
  "files": [
14
9
  "dist",
15
10
  "types"
@@ -53,5 +48,9 @@
53
48
  "bugs": {
54
49
  "url": "https://github.com/daemonitor/plugins/issues"
55
50
  },
56
- "homepage": "https://github.com/daemonitor/plugins#readme"
57
- }
51
+ "homepage": "https://github.com/daemonitor/plugins#readme",
52
+ "scripts": {
53
+ "build": "tsc",
54
+ "test": "echo \"Error: no test specified\" && exit 1"
55
+ }
56
+ }