aboutsummaryrefslogtreecommitdiff
path: root/cmd/moncheck/main.go
diff options
context:
space:
mode:
authorGibheer <gibheer+git@zero-knowledge.org>2019-04-10 09:09:15 +0200
committerGibheer <gibheer+git@zero-knowledge.org>2019-04-10 09:09:15 +0200
commit2bfe75c8a702508284ddb75a8db3a1b4911b9635 (patch)
tree32a93def9645fc706cbb37b393476fcf53f64963 /cmd/moncheck/main.go
parent532f55d640ec0ab2cb3f352c8e449e9351522344 (diff)
cmd/moncheck: use mapping only for notifications
This should make the frontend much easier to handle than before. It isn't the best solution, but it makes it easier in the frontend for now.
Diffstat (limited to 'cmd/moncheck/main.go')
-rw-r--r--cmd/moncheck/main.go25
1 files changed, 9 insertions, 16 deletions
diff --git a/cmd/moncheck/main.go b/cmd/moncheck/main.go
index 7253c07..62a1551 100644
--- a/cmd/moncheck/main.go
+++ b/cmd/moncheck/main.go
@@ -142,30 +142,23 @@ func check(thread int, db *sql.DB, waitDuration, timeout time.Duration, hostname
cancel()
state = 0
}
-
- mappedState := state
- err = db.QueryRow(`select target
- from mapping_level
- where mapping_id = $1 and source = $2`, mapId, state).Scan(&mappedState)
- if err != nil {
- log.Printf("[%d] could not fetch error mapping for check '%d' and source code '%d': %s", thread, id, state, err)
- tx.Rollback()
- continue
- }
- states.Add(mappedState)
msg := output.String()
if _, err := tx.Exec(`update active_checks ac
-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 {
+ 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 {
log.Printf("[%d] could not update row '%d': %s", thread, id, err)
tx.Rollback()
continue
}
if _, err := tx.Exec(`insert into notifications(check_id, states, output, mapping_id, notifier_id, check_host)
- select $1, $2, $3, $4, cn.notifier_id, $5
- from checks_notify cn
- where cn.check_id = $1`, &id, &states, &msg, &mapId, &hostname); err != nil {
+ select $1, array_agg(ml.target), $2, $3, cn.notifier_id, $4
+ from active_checks ac
+ cross join lateral unnest(ac.states) s
+ 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
+ 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()
continue