Preprod fires everything: every default rule applied to every device and port, so a WiFi port that always sees errors was judged like a fiber uplink where one error matters. WiFi errors are acceptable, fiber errors are not, and one global threshold cannot say both. An alert policy (new alert_policies table, migration 12) binds one rule to a scope: groups plus device and port attribute matchers (ifType, name/alias regexes, speed, site, role, profile, kind, the alert_down bell). The highest priority decides, ignore beats alert on a tie, and a policy's severity/threshold/for override the rule's (its threshold also beats group overrides). With no policy nothing alerts: not metric rules, not device_down/device_warning, not system alarms. Nothing is seeded, so on upgrade open alerts without a binding close silently as retired. The pure internal/alertpolicy package makes the decision; alert, reach and the system alarms take a gate (Options.Policy, Options.Wants, a system policy) that the app backs with a cache refreshed every 30 s and invalidated on every API write, so policy edits apply live. New API: /alert-policies CRUD, a viewer-level preview of what a scope covers, and /alert-rules. The UI gets an Alert policies tab with templates and a live preview; the port bell now says it only marks the port. Gate scripts create the policies they need. DEVIATIONS row 41 and the operations guide describe the new default. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01T4PdJUPrakM8fHvN8jYv2x Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
8.2 KiB
Operating nmon
How to run, secure, back up and maintain a production nmon. Design background: docs/spec/spec.md ("Auth", "Operations").
Starting
nmon serve --data-dir /var/lib/nmon --secret-key-file /etc/nmon/secret.key \
--tls-cert /etc/nmon/tls.crt --tls-key /etc/nmon/tls.key
- HTTPS is the default. Pass a certificate pair (
--tls-cert,--tls-key;SIGHUPreloads them without dropping connections) or Let's Encrypt (--acme-host nmon.example.netrepeatable,--acme-email you@example.net; nmon answers the http-01 challenge on--acme-listen, default:80, certificates are cached in<data-dir>/acme). Without either,serverefuses to start and says so.--insecure-httpis for development: plain HTTP, cookies withoutSecure. - A sign-in method is required over TLS (
auth.oidcand/orauth.break_glass_fileinconfig.yaml). With--insecure-httpand neither configured nmon runs in dev-open mode (everyone is admindev; a banner says so); never expose that port. - Behind a reverse proxy, list it in
auth.trusted_proxies;X-Forwarded-*is ignored from anyone else.
Sign-in
config.yaml:
auth:
oidc:
issuer: https://idp.example.net/realms/net
client_id: nmon
client_secret_name: oidc-client # the secret itself is never in this file
redirect_url: https://nmon.example.net/auth/callback
groups_claim: groups
admin_group: nmon-admins # members are admins; every other user is a viewer
break_glass_file: /etc/nmon/breakglass # bcrypt hash, "hash" or "user:hash", created by you
Store the client secret before the first start: printf '%s\n' "$SECRET" | nmon secret set oidc-client --data-dir D --secret-key-file K (it can also be set later with PUT /api/v1/secrets/oidc-client; OIDC stays off until the secret exists). The break-glass file holds one bcrypt hash ($2a$/$2b$), made with any bcrypt tool (the source tree's nmon-devtools bcrypt PASSWORD works); keep it readable by the nmon user only.
- There is no login page. Opening nmon without a session redirects to the IdP and back; API clients use a token. If the IdP is down, open
/auth/breakglass: the browser asks for the local admin user and password (HTTP Basic), and a successful sign-in lands on the page you asked for. - Break-glass: five wrong passwords lock the source address for 15 minutes; every use and every lock is audited and raises an alert.
nmon unlock [IP|all] --data-dir Dclears locks, also while nmon runs. - API tokens: an admin mints viewer, admin or push tokens (
POST /api/v1/tokens, or Settings, API tokens). UseAuthorization: Bearer nma_.... A push token works for ingest only. Revoking takes effect on the next request. GET /api/v1/audit(admin) lists who did what.
Backup and restore
A running nmon owns the stores, so copying the data folder is not a backup.
nmon backup /backups/nmon.tar --api https://nmon.example.net --token nma_... # key NOT included
nmon backup /backups/nmon.tar --include-key --api ... --token ... # key included
Every run prints whether the key file is in the archive. Lose the key file and a restore has an inventory with no SNMP credentials. The nightly schedule is backup: {at: "02:30", dir: /var/backups/nmon, keep: 7} (time in the configured timezone, default dir <data-dir>/backups); a failed run raises the backup_failed alert. A backup is refused when the disk is below its 5% reserve.
Restore with nmon stopped, into a clean directory:
nmon restore /backups/nmon.tar --data-dir /var/lib/nmon-restored --secret-key-file /etc/nmon/secret.key
It verifies inventory row counts and a sample of series before it says done. Then start nmon on that directory. Restore needs the embedded stores (the normal release build).
Keys
nmon key rotate --data-dir D --secret-key-file K (nmon stopped) adds a new key version, re-encrypts every SNMP credential and secret under it, and keeps the old key in the file so older backups still restore. Remove old keys only after a release.
Configuration
Edit in Settings (admin) or config.yaml + SIGHUP. An invalid document is rejected and the running configuration stays. Alert receivers, the outbound allow-list, trusted proxies, the backup schedule, disk thresholds and the purge period apply live; everything else is listed as restart_required until the next restart. disk: {alert_used: 0.8, admit_used: 0.9, reserve_free: 0.05}: alert at 80% used, no new series at 90%, ingest throttled / rollup paused / backups refused below 5% free.
Metric stores
The supervisor restarts a crashed store; after three restarts in ten minutes it raises store_failed and stops. nmon store restart [hot|long] --api URL --token T (or SIGHUP) resumes it.
Interface-down alerts are opt-in
Since v1.1 the bell and the group switch only mark ports: interface_down alerts for them only where an alert policy for interface_down uses the alert_down matcher (template "Bell-marked ports: interface_down"). Mark ports in one at a time (the bell on the device page's interface table), all at once (the "Alert on down" control in the interfaces card header, or POST /api/v1/devices/{slug}/interfaces/alert-down), or through a group (the group's "Alert when member ports go down" switch; PUT /api/v1/interfaces/{id} with {"alert_down": true} for one port). A port in a group with the switch on alerts for as long as its membership is in force. Changes reach the evaluator at once; opting a port out closes its open alert silently as retired.
Alert policies: nothing alerts until you add one
Alerts fire only where an alert policy binds a rule to a scope. A fresh install has no policies and records no alerts at all: no metric rule, no device_down or device_warning, no system alarm (ingest caps, late p95, rollup, disk guard, break-glass, backup). The startup log says so once ("no alert policies: nothing will alert"). Upgrading from v1.0 seeds nothing: the first cycle closes every open alert that no policy binds, silently, as retired (no "resolved" notices go out).
Manage policies under Alerts > Alert policies (admins edit, viewers read) or with GET/POST /api/v1/alert-policies and GET/PUT/DELETE /api/v1/alert-policies/{id}. GET /api/v1/alert-rules lists the rule names. POST /api/v1/alert-policies/preview counts the devices and ports a draft scope covers. Changes apply on the next cycle with no restart. Removing or disabling a policy retires its open alerts quietly.
A policy has a rule (a metric rule, device_down, device_warning, or system), an action (alert or ignore), a priority, optional severity, threshold and for overrides, and a scope. Scope fields are ANDed and any entry of a list may match: all, groups (a port is in force as a member now; a device matches if any port does), devices (slugs globs, profiles, roles, sites, kinds) and interfaces (if_types, if_name and if_alias as RE2, min_speed_mbps, max_speed_mbps, alert_down). For one entity and rule the matching policy with the highest priority decides; on a tie ignore beats alert, then the lowest name. A policy threshold beats a rule's group override, the profile threshold and the default. Interface matchers are refused on device-level rules, and a system policy takes only all: true.
Fiber and uplinks alert on any error, WiFi never alerts on errors:
{"name": "Fiber + uplinks: errors", "rule": "interface_errors", "action": "alert", "threshold": 0,
"scope": {"interfaces": {"if_types": [6], "if_alias": "(?i)fib|uplink|core"}}}
{"name": "WiFi: no error alerts", "rule": "interface_errors", "action": "ignore", "priority": 10,
"scope": {"interfaces": {"if_types": [71]}}}
Retired devices
POST /api/v1/devices/{slug}/purge (admin) deletes a retired device's series from both stores once it has been retired for retired_purge_after (default 1y).
CSV import
Devices (name,address,site,role,credential,parents,...) and port descriptions (device,ifname,alias) from Settings or POST /api/v1/devices/import. Port descriptions are stored in the operator-owned description field, which discovery never overwrites. A dependency cycle is rejected with its path; nothing is written unless the whole import is valid.