From 203ca756e14853d42663a334fb8bfd9f9aba2999 Mon Sep 17 00:00:00 2001 From: Gibheer Date: Fri, 11 Jan 2019 13:03:07 +0100 Subject: [PATCH] monfront - send an okay notification when check is acknowledged When a check is acknowledged, no more further notifications should be sent. But for the notified system, it should be made clean, that it is taken care of and no further actions need to be done, therefore send an okay, even when the check isn't okay. --- cmd/monfront/main.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/cmd/monfront/main.go b/cmd/monfront/main.go index e600a9e..6f7c3dc 100644 --- a/cmd/monfront/main.go +++ b/cmd/monfront/main.go @@ -10,6 +10,7 @@ import ( "io/ioutil" "log" "net/http" + "os" "strings" "time" @@ -179,6 +180,25 @@ func checkAction(w http.ResponseWriter, r *http.Request) { case "ack": setClause = "acknowledged = true" setTable = "active_checks" + + hostname, err := os.Hostname() + if err != nil { + log.Printf("could not resolve hostname: %s", err) + con.Error = "could not resolve hostname" + returnError(http.StatusInternalServerError, con, w) + return + } + if _, err := DB.Exec(`insert into notifications(check_id, states, output, mapping_id, notifier_id, check_host) + select ac.check_id, 0 || states[1:array_length(states, 1)], 'check acknowledged', ac.mapping_id, + cn.notifier_id, $2 + from checks_notify cn + join active_checks ac on cn.check_id = ac.check_id + where cn.check_id = any ($1::int[])`, pq.Array(&checks), &hostname); err != nil { + log.Printf("could not acknowledge check: %s", err) + con.Error = "could not acknowledge check" + returnError(http.StatusInternalServerError, con, w) + return + } case "comment": if len(r.PostForm["comment"]) == 0 { w.WriteHeader(http.StatusBadRequest)