diff options
author | Gibheer <gibheer+git@zero-knowledge.org> | 2018-11-20 21:47:35 +0100 |
---|---|---|
committer | Gibheer <gibheer+git@zero-knowledge.org> | 2018-11-20 21:47:35 +0100 |
commit | ddc0053ce8eda6001df8de1b30cf2395c625846e (patch) | |
tree | c2f8e50c09171917c62c3df202b06aac7f3379a2 /cmd | |
parent | a0c78acddaa9b28cc36a12f62c5a3a05767ccaeb (diff) |
moncheck - add function to remove acknowledge
An acknowledge should be set to false when the alarm switches to an ok
state.
Diffstat (limited to 'cmd')
-rw-r--r-- | cmd/moncheck/main.go | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/cmd/moncheck/main.go b/cmd/moncheck/main.go index 82b3d1f..fbc2b57 100644 --- a/cmd/moncheck/main.go +++ b/cmd/moncheck/main.go @@ -131,7 +131,9 @@ func check(thread int, db *sql.DB, waitDuration time.Duration) { } msg := output.String() - if _, err := tx.Exec("update active_checks set next_time = now() + intval, states = $2 where check_id = $1", id, &states); err != nil { + if _, err := tx.Exec(`update active_checks +set next_time = now() + intval, states = $2, msg = $3, acknowledged = case when $4 then false else acknowledged end +where check_id = $1`, id, &states, &msg, states.ToOK()); err != nil { log.Printf("[%d] could not update row '%d': %s", thread, id, err) tx.Rollback() continue @@ -203,3 +205,18 @@ func (s *States) Add(state int) { *s = append([]int{state}, vals[:statePos]...) return } + +// ToOK returns true when the state returns from != 0 to 0. +func (s *States) ToOK() bool { + vals := *s + if len(vals) == 0 { + return false + } + if len(vals) <= 1 { + return vals[0] == 0 + } + if vals[0] == 0 && vals[1] > 0 { + return true + } + return false +} |