Files
nmon/internal/api/device_poll_interval_test.go
Vibe Coder 881f0ae3b1 Poll every 300 s by default, with a per-device poll interval
The owner wants LibreNMS-like 5-minute polling by default and the option
to poll a given device faster or slower. Devices gain poll_interval_s
(new migration; 0 means the default, otherwise 30 to 3600 s), settable in
the device edit dialog and through PUT /api/v1/devices/{slug}; the
poller picks it up on the next inventory refresh.

Everything that assumed one-minute samples now follows the device's
interval: graph and p95 rate windows are at least two polls, the max
series uses irate, the up-series lookback, the no_data warning, the
"unheard of for three polls" fallback and the rollup's thin-window check.
interface_errors widens to 10 m. profiletest keeps 60 s because the
expect budgets are keyed by the 1m group. Recorded as DEVIATIONS 49.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017TuKgyKve2XLFtrrXWMi2w
2026-10-24 18:55:43 +00:00

31 lines
903 B
Go

package api_test
import (
"encoding/json"
"testing"
"github.com/v10networks/nmon/internal/api"
)
func TestPutDeviceSetsAndClearsPollInterval(t *testing.T) {
e := newEnv(t, 0)
d := e.device(t, "A", "yyz", "core")
url := "/api/v1/devices/" + d.Slug
var v api.DeviceView
rec := e.do("PUT", url, `{"poll_interval_s":60}`)
_ = json.Unmarshal(rec.Body.Bytes(), &v)
if rec.Code != 200 || v.PollIntervalS != 60 || v.PollIntervalEffectiveS != 60 {
t.Fatalf("set: %d %+v", rec.Code, v)
}
if e.ref.n.Load() != 1 {
t.Error("poller not refreshed")
}
rec = e.do("PUT", url, `{"poll_interval_s":0}`)
_ = json.Unmarshal(rec.Body.Bytes(), &v)
if rec.Code != 200 || v.PollIntervalS != 0 || v.PollIntervalEffectiveS != 300 {
t.Fatalf("clear: %d %+v", rec.Code, v)
}
isProblem(t, e.do("PUT", url, `{"poll_interval_s":10}`), 422)
isProblem(t, e.do("PUT", url, `{"poll_interval_s":7200}`), 422)
}