aboutsummaryrefslogtreecommitdiff
path: root/cmd/moncheck
diff options
context:
space:
mode:
Diffstat (limited to 'cmd/moncheck')
-rw-r--r--cmd/moncheck/main.go10
1 files changed, 7 insertions, 3 deletions
diff --git a/cmd/moncheck/main.go b/cmd/moncheck/main.go
index ca31a02..dba3099 100644
--- a/cmd/moncheck/main.go
+++ b/cmd/moncheck/main.go
@@ -64,7 +64,7 @@ func check(thread int, db *sql.DB, waitDuration time.Duration) {
log.Printf("[%d] could not start transaction: %s", thread, err)
continue
}
- rows, err := tx.Query("select check_id, check_id, cmdLine, states, next_time from active_checks where next_time < now() and enabled order by next_time for update skip locked limit 1;")
+ rows, err := tx.Query("select check_id, cmdLine, states, notify from active_checks where next_time < now() and enabled order by next_time for update skip locked limit 1;")
if err != nil {
log.Printf("[%d] could not start query: %s", thread, err)
tx.Rollback()
@@ -128,12 +128,16 @@ func check(thread int, db *sql.DB, waitDuration time.Duration) {
states = append([]int64{0}, states[:statePos]...)
}
- if _, err := tx.Exec("update active_checks set next_time = now() + interval, states = $2 where check_id = $1", id, pq.Array(&states)); err != nil {
+ if _, err := tx.Exec("update active_checks set next_time = now() + intval, states = $2 where check_id = $1", id, pq.Array(&states)); err != nil {
log.Printf("[%d] could not update row '%d': %s", thread, id, err)
+ tx.Rollback()
+ continue
}
if notify {
- if _, err := tx.Exec("insert into notifications(check_id, states, output) values ($1, $2, $3);", id, pq.Array(&states), &output); err != nil {
+ if _, err := tx.Exec("insert into notifications(check_id, states, output) values ($1, $2, $3);", &id, pq.Array(&states), output.Bytes()); err != nil {
log.Printf("[%d] could not create notification for '%d': %s", thread, id, err)
+ tx.Rollback()
+ continue
}
}
tx.Commit()