From 142f9cf3582e111910723cacbdc4a66267a79c75 Mon Sep 17 00:00:00 2001 From: Gibheer Date: Tue, 28 May 2019 13:38:16 +0200 Subject: [PATCH] fill in state_change column Any time the state of the check changes, we need to refresh the column. This will be used in the frontend. This way it is much faster than using the notifications and also doesn't rely on the last of it being still around. --- cmd/moncheck/main.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) 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()