Skip to content

sensor-monitor: add per-rule snooze DoCommand#11

Open
Nicolas Palpacuer (NickPPC) wants to merge 1 commit into
mainfrom
worktree-snooze-do-command
Open

sensor-monitor: add per-rule snooze DoCommand#11
Nicolas Palpacuer (NickPPC) wants to merge 1 commit into
mainfrom
worktree-snooze-do-command

Conversation

@NickPPC

Copy link
Copy Markdown
Collaborator

Summary

Adds a snooze DoCommand to the sensor-monitor model that temporarily suppresses a single rule's evaluation. This lets an operator silence a specific alert (e.g. during known maintenance) without disabling the whole monitor or the other rules.

Changes

  • resources/sensormonitor: Add {"snooze": {"rule_name": <name>, "duration": <dur>}} DoCommand that suppresses evaluation of one named rule until the duration elapses. Returns {"rule_name", "snoozed_until"} (RFC 3339).
  • resources/sensormonitor: Add an optional, unique name field to rules so they can be targeted by snooze; Validate rejects duplicate names. Only named rules can be snoozed.
  • resources/sensormonitor: Track snooze state per rule (ruleState.snoozeUntil). poll skips only snoozed rules — others keep evaluating, readings stay current, and a rule's state is frozen while snoozed so a condition still breaching when the snooze ends fires on the next poll.
  • resources/sensormonitor: Custom parseSnoozeDuration supporting s/m/h/d units (e.g. 30s, 90m, 24h, 5d), because time.ParseDuration has no d (day) unit.
  • resources/sensormonitor: Readings now exposes <key>_snoozed per rule alongside the existing <key>_triggered.
  • README: Document the name rule field, the snooze DoCommand payload/response, and the new per-rule _snoozed reading.

Testing

  • go build ./..., go vet ./..., and go test ./... all pass (package coverage 85.3%).
  • TestParseSnoozeDuration — all four units, decimals, case/whitespace handling, and invalid inputs (missing unit, unsupported unit, negative).
  • TestDoCommandSnoozeSuppressesRule — two rules; snoozing one keeps it silent while the other still fires, verifies per-rule _snoozed readings, and confirms firing resumes after the snooze expires.
  • TestDoCommandSnoozeInvalid — non-object payload, missing/empty/unknown rule_name, and missing/non-string/invalid duration.
  • TestValidate — added a duplicate-rule-names case.

Notes

  • Rules without a name cannot be snoozed. name was kept optional to avoid breaking existing configs.
  • Snooze state is in-memory and resets on module restart, consistent with the monitor's other runtime state.

Claude Code Prompts Used

  • "I would like to add a snooze DoCommand to the monitoring sensor. It should take in a duration represented as string, it should support seconds, minutes, hours, and days, examples: 30s, 90m, 24h, 5d"
  • "Can you modify it to make the snooze at the rule level? the do command should be `"snooze": {"rule_name": , "duration": }`"
  • "let's commit push and open a PR"

🤖 Generated with Claude Code

Add a "snooze" DoCommand that suppresses evaluation of a single named
rule for a duration: {"snooze": {"rule_name": <name>, "duration": <dur>}}.
Duration is a string with a seconds/minutes/hours/days unit (e.g. "30s",
"90m", "24h", "5d") — a custom parser is used because time.ParseDuration
does not support a "d" unit.

Rules gain an optional unique "name" so they can be targeted; snooze state
is tracked per rule, so snoozing one rule leaves the others evaluating.
While snoozed a rule is not evaluated and its actions do not fire, but
readings stay current and its state is frozen, so a condition still
breaching when the snooze ends fires on the next poll. Readings expose
"<key>_snoozed" per rule alongside the existing "<key>_triggered".

Co-Authored-By: Claude Opus 4.8 (1M context) <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.

1 participant