Hub v0.149.0: a box the household switched off is not an outage for 14 days (R-998)
gates / gates (push) Successful in 6m40s
gates / gates (push) Successful in 6m40s
hosts.deliberate_off_at follows the agent's deliberate_off field (set, then cleared by the first report of a new boot; one info event each way). While held, every silence alarm is held: host and node staleness, the 05:00 backup deadlines, off-site and restore-test freshness, the OS alarms and the kernel notice. After 14 days the usual alarms fire once, naming the power-off. Pages show KIKAPCSOLVA and the time. Consequence tests with controls; each guard red-proofed.
This commit is contained in:
1 parent
ed59bf3cbd
commit
50e47e29af
24 files changed
+638
-17
No files matched your search
@@ -0,0 +1,68 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"gitea.dooplex.hu/admin/felhom-hub/internal/store"
|
||||
)
|
||||
|
||||
// Event types of the household power-off (R-998, doc 14). Both are info: recorded on the customer's event list,
|
||||
// never mailed (the dispatcher mails warning and above).
|
||||
const (
|
||||
eventHostDeliberateOff = "host_deliberate_off"
|
||||
eventHostDeliberateOffEnded = "host_deliberate_off_ended"
|
||||
)
|
||||
|
||||
// checkDeliberateOff keeps the host row's deliberate-off time in step with the report: set while the report
|
||||
// carries the field, cleared by the first report without it (the box is in a new boot — switched back on).
|
||||
func (h *Handler) checkDeliberateOff(hostID, custID string, rep *hostReportPayload) {
|
||||
var at *time.Time
|
||||
if rep.DeliberateOff != nil && rep.DeliberateOff.RequestedAt != "" {
|
||||
t, err := time.Parse(time.RFC3339, rep.DeliberateOff.RequestedAt)
|
||||
if err != nil {
|
||||
h.logger.Printf("[WARN] host-report from %s: unreadable deliberate_off.requested_at %q — ignored", hostID, rep.DeliberateOff.RequestedAt)
|
||||
return
|
||||
}
|
||||
t = t.UTC()
|
||||
at = &t
|
||||
}
|
||||
prev, err := h.store.SetHostDeliberateOff(hostID, at)
|
||||
if err != nil {
|
||||
h.logger.Printf("[WARN] host-report from %s: deliberate-off not stored: %v", hostID, err)
|
||||
return
|
||||
}
|
||||
switch {
|
||||
case at != nil && (prev == nil || !prev.Equal(*at)):
|
||||
msg := "Switched off by the household at " + at.Format("2006-01-02 15:04 UTC") +
|
||||
" — silence alarms held for " + holdDays() + " days"
|
||||
h.logger.Printf("[INFO] host %s: deliberate power-off recorded (%s)", hostID, at.Format(time.RFC3339))
|
||||
h.saveInfoEvent(custID, eventHostDeliberateOff, msg)
|
||||
case at == nil && prev != nil:
|
||||
msg := "Reporting again after the household's power-off of " + prev.Format("2006-01-02 15:04 UTC")
|
||||
h.logger.Printf("[INFO] host %s: deliberate power-off ended (was %s)", hostID, prev.Format(time.RFC3339))
|
||||
h.saveInfoEvent(custID, eventHostDeliberateOffEnded, msg)
|
||||
}
|
||||
}
|
||||
|
||||
func holdDays() string {
|
||||
d := int(store.DeliberateOffHold / (24 * time.Hour))
|
||||
return itoa(d)
|
||||
}
|
||||
|
||||
func itoa(n int) string {
|
||||
if n == 0 {
|
||||
return "0"
|
||||
}
|
||||
var b []byte
|
||||
for n > 0 {
|
||||
b = append([]byte{byte('0' + n%10)}, b...)
|
||||
n /= 10
|
||||
}
|
||||
return string(b)
|
||||
}
|
||||
|
||||
func (h *Handler) saveInfoEvent(custID, eventType, msg string) {
|
||||
if _, err := h.store.SaveEvent(custID, eventType, "info", msg, "{}", "hub"); err != nil {
|
||||
h.logger.Printf("[WARN] save %s event: %v", eventType, err)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user