diff options
author | Gibheer <gibheer+git@zero-knowledge.org> | 2019-01-11 13:03:07 +0100 |
---|---|---|
committer | Gibheer <gibheer+git@zero-knowledge.org> | 2019-01-11 13:03:07 +0100 |
commit | 203ca756e14853d42663a334fb8bfd9f9aba2999 (patch) | |
tree | a5f228584c567435a9c2455ebcdd10ebe9e1e72c | |
parent | 7ed255d5911f22ac278c1e7a34b11ce273029c6e (diff) |
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.
-rw-r--r-- | cmd/monfront/main.go | 20 |
1 files changed, 20 insertions, 0 deletions
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) |