diff options
| -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  | 
