diff --git a/cmd/moncheck/main.go b/cmd/moncheck/main.go index 62a1551..6aa34a5 100644 --- a/cmd/moncheck/main.go +++ b/cmd/moncheck/main.go @@ -145,8 +145,11 @@ func check(thread int, db *sql.DB, waitDuration, timeout time.Duration, hostname msg := output.String() if _, err := tx.Exec(`update active_checks ac - set next_time = now() + intval, states = ARRAY[$2::int] || states[1:4], msg = $3, acknowledged = case when $4 then false else acknowledged end -where check_id = $1`, id, &state, &msg, states.ToOK()); err != nil { + set next_time = now() + intval, states = ARRAY[$2::int] || states[1:4], + msg = $3, + acknowledged = case when $4 then false else acknowledged end, + state_since = case $2 when states[1] then state_since else now() end + where check_id = $1`, id, &state, &msg, states.ToOK()); err != nil { log.Printf("[%d] could not update row '%d': %s", thread, id, err) tx.Rollback() continue @@ -158,6 +161,7 @@ where check_id = $1`, id, &state, &msg, states.ToOK()); err != nil { join checks_notify cn on ac.check_id = cn.check_id join mapping_level ml on ac.mapping_id = ml.mapping_id and s.s = ml.source where ac.check_id = $1 + and ac.acknowledged = false group by cn.notifier_id;`, &id, &msg, &mapId, &hostname); err != nil { log.Printf("[%d] could not create notification for '%d': %s", thread, id, err) tx.Rollback()