Skip to content

feat(observability): watch NUT's upsmon logs, so a disarmed shutdown pages - #1673

Merged
Gerrrt merged 2 commits into
mainfrom
gerrrt/watch-nut-on-morpheus
Nov 23, 2026
Merged

Gerrrt merged 2 commits into
mainfrom
gerrrt/watch-nut-on-morpheus

Conversation

@Gerrrt

@Gerrrt Gerrrt commented Nov 23, 2026

Copy link
Copy Markdown
Owner

What changed

Three Loki rules in a new stacks/observability/loki/rules/nut.rules.yaml, with behaviour tests in loki/tests/nut.test.yaml:

  • NutDriverNotConnected (critical, category power): an upsmon logs "Driver not connected" 10 or more times in 10 minutes, for 5 minutes. That means the snmp-ups driver on morpheus stayed down, so the shutdown is disarmed.
  • NutCommunicationsLost (critical): upsmon logs "… is unavailable", which is its own report of 5 minutes without UPS data on that host.
  • NutMonitorFailedToStart (warning): upsmon logs "Fatal error" and exits.

Each rule reads two sources: morpheus's syslog (app="upsmon") and the clients' journal (unit="nut-monitor.service", from Saruman and trinity). It joins them with or, the way security.rules.yaml reads sshd. observability.md, the shutdown runbook's If something goes wrong, the changelog and the rule counts are updated.

Why

The 2026-11-13 mjolnir audit found that nothing watches NUT itself. From about 10-30 to 11-07 the driver on morpheus was down. Only the generic card-silence alerts fired, and a driver down while the card still answers SNMP would have raised nothing at all. (The outage is recorded in the changelog by #1656.)

Blast radius

Alerting only. If the rules are wrong, they page falsely on the urgent receiver or stay quiet. Each one was evaluated against the live Loki at 9 instants across the 48 hours to 2026-11-23, and none would have fired. That window includes seven driver restarts and about 200 stale spells.

Not covered:

  • smaug: it ships no logs to Loki.

  • A stopped upsmon: it logs nothing, and a rule on silence would depend on the stale flapping as its heartbeat.

  • The flapping itself: about 100 stale spells a day, 1–5 s each, cause not established. Left alone on purpose.

  • No change to network segmentation or firewall rules

  • No new port published to a VLAN that could not already reach the service

  • No credential added outside secrets/*.sops.yaml

Verification

  • make validate: passed before the rebase.

  • Skipped in that run: backup-offsite.sh's path refusal (/tmp is a tmpfs; CI covers it), and the unit, installed-timer and sensitive-stack checks that run only from the deployment checkout.

  • After rebasing onto main:

    • the count conflicts were resolved; check_docs.py reads 161 Prometheus + 25 Loki rules.
    • ./scripts/lint.sh passes everything.
    • test_loki_rules.py: 62/62 tests over 25 of 25 rules.
  • The test cases:

    • real upsmon lines from both sources
    • a driver restart (quiet)
    • the everyday stale spells (quiet)
    • a loss recovered within seconds (quiet)
  • After merge: confirm the ruler loads the group (/loki/api/v1/rules).

  • make validate passes

  • Deployed to the lab and confirmed working

  • Docs updated

Merge order: this and #1672 both change the rule counts. Whichever merges second needs a rebase to 164 + 25 = 189.

🤖 Generated with Claude Code

…pages

The card's SNMP cannot see NUT. From 10-30 to 11-07 the driver on morpheus
was down and only the generic card-silence alerts fired. Every upsmon but
smaug's already reaches Loki, so three LogQL rules read them:
NutDriverNotConnected and NutCommunicationsLost (critical), and
NutMonitorFailedToStart.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings November 23, 2026 06:28

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Historical failed polls can satisfy the alert’s five-minute hold after communications recover, causing a false critical page claiming shutdown remains disarmed.

2 open issues
What changed in this PR

Adds log-based monitoring of NUT’s UPS shutdown path, covering failures that card-level SNMP alerts cannot detect.

Changes:

  • Adds three Loki alerts for driver disconnection, communications loss, and monitor startup failure.
  • Adds behavior fixtures for failures, clean starts, and brief interruptions.
  • Documents coverage and troubleshooting, and updates totals to 186 alerts: 161 Prometheus and 25 Loki.
File Description
stacks/​observability/​README.md Updates Loki rule count and coverage.
stacks/​observability/​loki/​tests/​nut.test.yaml Adds NUT alert behavior fixtures.
stacks/​observability/​loki/​rules/​nut.rules.yaml Adds three NUT log-based alerts.
README.md Updates overall and Loki alert counts.
docs/​security.md Updates the alert coverage total.
docs/​runbooks/​shut-down-on-the-ups.md Adds troubleshooting guidance for NUT pages.
docs/​observability.md Describes NUT monitoring and its exclusions.
docs/​changelog.md Records the new monitoring and evaluation window.

Review effort: Balanced

Comment thread docs/runbooks/shut-down-on-the-ups.md Resolved
…runbook by alert

NutDriverNotConnected counted over ten minutes, so a 50-second outage's
lines held the count at ten long enough for `for: 5m` to page after the
driver was back. It now counts over three minutes, and a recovered
outage is a quiet test case.

The runbook sent a client that logged "Driver not connected" to check its
network, though that line means it reached upsd. It now splits by alert,
and names each client's own upsd: 10.0.30.1 from Saruman, 10.0.99.1 from
trinity. The Saruman test lines name 10.0.30.1 to match.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Gerrrt
Gerrrt merged commit 9046f6e into main Nov 23, 2026
9 checks passed
@Gerrrt
Gerrrt deleted the gerrrt/watch-nut-on-morpheus branch November 23, 2026 14:46
Gerrrt added a commit that referenced this pull request Nov 23, 2026
… review points

main's #1673 added loki/rules/nut.rules.yaml, which covers a lasting loss
(NutCommunicationsLost) and a driver down (NutDriverNotConnected). So
NutUpsDataStaleSustained is dropped: it overlapped NutCommunicationsLost and
its start-minus-end count across a sliding window could hide an open spell
whose predecessor began before the window. NutUpsDataStaleFrequent moves into
nut.rules.yaml, at > 24 an hour: the worst sliding hour to 2026-11-23 was 12,
not the 9 an hour-aligned count gave.

collect-nut-state.sh now finds the status line wherever upsc prints it, so a
diagnostic such as "Init SSL without certificate database" before "OL" reads
as readable, with two new fixtures.

Counts: 192 rules, 166 Prometheus and 26 Loki; the Rules page lists 172.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants