feat(agent): change detection + webhook/syslog alerts (P2-02 / 26.13)#16
Merged
Conversation
The agent now diffs the host inventory pre- and post-cycle and emits host.discovered / host.vanished events to configurable sinks. Operators no longer have to tail logs to notice a new device. New package internal/alerts: - Event + EventType (host.discovered, host.vanished). JSON-tagged for wire reuse. - Emitter interface + Multiplexer that fans events out to N sinks in parallel goroutines. Sink failures log but don't suppress sibling deliveries. - WebhookSink: HTTP POST JSON, one retry on 5xx/network, no retry on 4xx, optional Authorization header. - SyslogSink: RFC 5424 over UDP/TCP, hand-rolled because log/syslog is Unix-only and the agent runs on Windows. Message body is the same JSON as the webhook payload, so structured syslog parsers get fields for free. - NoopEmitter for the alerts-disabled default. Config gains an optional "alerts" section with webhook and syslog sub-sections. Either or both may be set. agent.New takes a new Emitter parameter (nil = noop). runCycle snapshots hosts pre-scan, snapshots again post-prune, and diffs by IP. Discovered events get fresh enrichment; vanished events get the last-known pre-cycle row. Cycle-failed runs skip the diff to avoid alert spam on transient DB errors. 11 new tests: multiplexer fan-out, sibling-survives-peer-error, webhook auth-header round-trip, 5xx retry, 4xx no-retry, nil-on- empty guards, syslog RFC 5424 format check against a real UDP listener (PRI math, MSGID, JSON MSG), bad-scheme rejection, end-to-end discovered+vanished events from the agent. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The agent now diffs the host inventory before and after every scan cycle and fires `host.discovered` / `host.vanished` events to configurable sinks. Operators no longer have to tail logs to notice a new device.
```json
{
"alerts": {
"webhook": { "url": "https://hooks.example/x\", "auth_header": "Bearer abc" },
"syslog": { "addr": "udp://syslog.example:514", "tag": "inventory" }
}
}
```
Both sinks ship the same JSON payload (`{type, ip, hostname, mac_address, vendor, device_type, time, agent}`). The syslog sink wraps it in RFC 5424; `rsyslog mmjsonparse` / `syslog-ng` / Splunk all parse out the inner fields for free.
Why two sinks
Operators pick one or both. Empty config disables alerting (no change for existing deployments).
Reliability model
Test plan
🤖 Generated with Claude Code