Each server runs an ultralight probe (scratch image, ~7 MiB RSS) that tails the logs, ships raw lines to the hub over HTTPS with an on-disk spool, and applies enforce decisions locally. The hub keeps one node per probe (primary node = the 1.x data dir, unchanged), does all analysis and serves the UI. Peer federation is removed. 'urutau import' brings 1.x data dirs in with hash and count verification. UI: probes page, host qualified incidents, IPs never wrap, egress heatmap labels, live and replay globes no longer auto-rotate, replay repeat, live traffic metrics. BREAKING CHANGE: URUTAU_PEERS, URUTAU_PEER_* and /api/v1/peer/* are gone; log path variables move from the hub to the probe. See docs/migration-2.0.md. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
56 lines
1.3 KiB
Go
56 lines
1.3 KiB
Go
package probeagent
|
|
|
|
import (
|
|
"os"
|
|
|
|
"git.lucasrguerra.dev.br/ciberfauna/urutau/internal/wire"
|
|
)
|
|
|
|
// appendLine appends one validated line to path and syncs it.
|
|
func appendLine(path, line string) error {
|
|
f, err := os.OpenFile(path, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0o640)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if _, err := f.WriteString(line); err != nil {
|
|
f.Close()
|
|
return err
|
|
}
|
|
if err := f.Sync(); err != nil {
|
|
f.Close()
|
|
return err
|
|
}
|
|
return f.Close()
|
|
}
|
|
|
|
// applyCmds executes the commands above lastCmd, in order, and persists
|
|
// lastCmd after each one. An invalid or unroutable command is counted and
|
|
// skipped; it never stops the queue. A write failure stops (the same command
|
|
// is delivered again later).
|
|
func (p *probe) applyCmds(cmds []wire.Cmd) error {
|
|
for _, c := range cmds {
|
|
if c.Seq <= p.st.lastCmd() {
|
|
continue
|
|
}
|
|
var path string
|
|
switch c.Kind {
|
|
case wire.CmdDecision:
|
|
path = p.cfg.DecisionsLog
|
|
case wire.CmdUnban:
|
|
path = p.cfg.UnbanLog
|
|
}
|
|
if path == "" || !wire.ValidCmdLine(c.Kind, c.Line) {
|
|
p.cmdErrors.Add(1)
|
|
p.log.Warn("command ignored", "seq", c.Seq, "kind", c.Kind)
|
|
} else if err := appendLine(path, c.Line); err != nil {
|
|
p.cmdErrors.Add(1)
|
|
p.log.Error("command write failed", "seq", c.Seq, "kind", c.Kind)
|
|
return err
|
|
}
|
|
if err := p.st.setLastCmd(c.Seq); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
return nil
|
|
}
|