c97975c1df
Consumes the agent v0.94.0 smart payload (MinAgent floor unchanged; feature-detect by presence). One pure verdict fn agentapi.DiskVerdictFor shared by the dashboard card and the 6h check. Card via a 60s /disks TTL cache (anti-smartctl-storm); unreachable agent -> Nincs adat, page never blocks. disk-health-check (6h) emits disk_health_degraded on a degradation only vs an in-memory baseline (first run silent, recovery/UNKNOWN never notify, multi-attr -> one event). No global banner (deliberate). Pairs with the hub allowlist bump. Tests: verdict table (>=90 red-proof), notifier emit, check first-run-silent (red-proof), degradation-once, recovery-silent, UNKNOWN-excluded, FAILING-critical, nil-smart card, TTL cache.
45 lines
1.6 KiB
Go
45 lines
1.6 KiB
Go
package notify
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
// NotifyDiskHealthDegraded emits the right event type + severity + a message carrying the required
|
|
// "Lemez állapot romlás: <label>" phrase and the triggering attribute(s). Uses the pushFn seam.
|
|
func TestNotifyDiskHealthDegraded(t *testing.T) {
|
|
n := &Notifier{}
|
|
var gotType, gotSev, gotMsg string
|
|
var gotDetails interface{}
|
|
n.pushFn = func(eventType, severity, message string, details interface{}) {
|
|
gotType, gotSev, gotMsg, gotDetails = eventType, severity, message, details
|
|
}
|
|
|
|
// Warn (Figyelmeztetés): severity warn, attributes named.
|
|
n.NotifyDiskHealthDegraded("sdb (lassú)", []string{"függőben lévő szektorok"}, false)
|
|
if gotType != "disk_health_degraded" {
|
|
t.Errorf("event type = %q, want disk_health_degraded", gotType)
|
|
}
|
|
if gotSev != "warn" {
|
|
t.Errorf("severity = %q, want warn", gotSev)
|
|
}
|
|
if !strings.Contains(gotMsg, "Lemez állapot romlás: sdb (lassú)") {
|
|
t.Errorf("message missing the required subject phrase: %q", gotMsg)
|
|
}
|
|
if !strings.Contains(gotMsg, "függőben lévő szektorok") {
|
|
t.Errorf("message does not name the triggering attribute: %q", gotMsg)
|
|
}
|
|
if d, ok := gotDetails.(DiskHealthDetails); !ok || d.Disk != "sdb (lassú)" || d.Critical {
|
|
t.Errorf("details = %+v, want DiskHealthDetails{Disk:sdb (lassú), Critical:false}", gotDetails)
|
|
}
|
|
|
|
// Critical (Hiba/FAILING): severity critical.
|
|
n.NotifyDiskHealthDegraded("sdc", nil, true)
|
|
if gotSev != "critical" {
|
|
t.Errorf("critical severity = %q, want critical", gotSev)
|
|
}
|
|
if !strings.Contains(gotMsg, "SMART önellenőrzése hibát jelez") {
|
|
t.Errorf("critical message wrong: %q", gotMsg)
|
|
}
|
|
}
|