aboutsummaryrefslogtreecommitdiff
path: root/cmd/moncheck
diff options
context:
space:
mode:
Diffstat (limited to 'cmd/moncheck')
-rw-r--r--cmd/moncheck/main.go19
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
+}