diff options
author | Gibheer <gibheer+git@zero-knowledge.org> | 2019-01-11 13:02:37 +0100 |
---|---|---|
committer | Gibheer <gibheer+git@zero-knowledge.org> | 2019-01-11 13:02:37 +0100 |
commit | 7ed255d5911f22ac278c1e7a34b11ce273029c6e (patch) | |
tree | bd434863bffccda384a68865030b17e0cc49bd66 /cmd/moncheck | |
parent | f804446ad3e2e653ffd6ef00a662d91ab79bc0dd (diff) |
moncheck - add hostname to notifications
This can help with determining which exact check connection broke the
check.
Diffstat (limited to 'cmd/moncheck')
-rw-r--r-- | cmd/moncheck/main.go | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/cmd/moncheck/main.go b/cmd/moncheck/main.go index 28b177e..3080309 100644 --- a/cmd/moncheck/main.go +++ b/cmd/moncheck/main.go @@ -67,15 +67,20 @@ func main() { log.Fatalf("could not open database connection: %s", err) } + hostname, err := os.Hostname() + if err != nil { + log.Fatalf("could not resolve hostname: %s", err) + } + for i := 0; i < config.Workers; i++ { - go check(i, db, waitDuration, timeout) + go check(i, db, waitDuration, timeout, hostname) } wg := sync.WaitGroup{} wg.Add(1) wg.Wait() } -func check(thread int, db *sql.DB, waitDuration, timeout time.Duration) { +func check(thread int, db *sql.DB, waitDuration, timeout time.Duration, hostname string) { for { tx, err := db.Begin() if err != nil { @@ -167,10 +172,10 @@ where check_id = $1`, id, &states, &msg, states.ToOK()); err != nil { 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 + 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); err != nil { + where cn.check_id = $1`, &id, &states, &msg, &mapId, &hostname); err != nil { log.Printf("[%d] could not create notification for '%d': %s", thread, id, err) tx.Rollback() continue |