aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGibheer <gibheer+git@zero-knowledge.org>2019-05-28 13:38:16 +0200
committerGibheer <gibheer+git@zero-knowledge.org>2019-05-28 13:38:16 +0200
commit142f9cf3582e111910723cacbdc4a66267a79c75 (patch)
treea2d638f8ecc6c0fc69baf06c5bc8b65b6bb9f251
parent2bfe75c8a702508284ddb75a8db3a1b4911b9635 (diff)
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.
-rw-r--r--cmd/moncheck/main.go8
1 files 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()