aboutsummaryrefslogtreecommitdiff
path: root/cmd/moncheck
diff options
context:
space:
mode:
Diffstat (limited to 'cmd/moncheck')
-rw-r--r--cmd/moncheck/main.go18
1 files changed, 9 insertions, 9 deletions
diff --git a/cmd/moncheck/main.go b/cmd/moncheck/main.go
index bea8e77..e292637 100644
--- a/cmd/moncheck/main.go
+++ b/cmd/moncheck/main.go
@@ -81,7 +81,7 @@ func check(thread int, db *sql.DB, waitDuration, timeout time.Duration) {
log.Printf("[%d] could not start transaction: %s", thread, err)
continue
}
- rows, err := tx.Query(`select check_id, cmdLine, states, notify, mapping_id
+ rows, err := tx.Query(`select check_id, cmdLine, states, mapping_id
from active_checks
where next_time < now()
and enabled
@@ -97,7 +97,6 @@ func check(thread int, db *sql.DB, waitDuration, timeout time.Duration) {
id int64
cmdLine []string
states States
- notify bool
mapId int
state int
)
@@ -108,7 +107,7 @@ func check(thread int, db *sql.DB, waitDuration, timeout time.Duration) {
tx.Rollback()
break
}
- err := rows.Scan(&id, pq.Array(&cmdLine), &states, &notify, &mapId)
+ err := rows.Scan(&id, pq.Array(&cmdLine), &states, &mapId)
if err != nil {
log.Printf("could not scan values: %s", err)
tx.Rollback()
@@ -166,12 +165,13 @@ where check_id = $1`, id, &states, &msg, states.ToOK()); err != nil {
tx.Rollback()
continue
}
- if notify {
- if _, err := tx.Exec("insert into notifications(check_id, states, output, mapping_id) values ($1, $2, $3, $4);", &id, &states, &msg, &mapId); err != nil {
- log.Printf("[%d] could not create notification for '%d': %s", thread, id, err)
- tx.Rollback()
- continue
- }
+ if _, err := tx.Exec(`insert into notifications(check_id, states, output, mapping_id, notifier_id)
+ select $1, $2, $3, $4, cn.notifier_id
+ from checks_notify cn
+ where cn.check_id = $1`, &id, &states, &msg, &mapId); err != nil {
+ log.Printf("[%d] could not create notification for '%d': %s", thread, id, err)
+ tx.Rollback()
+ continue
}
tx.Commit()
}