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.
This commit is contained in:
Gibheer 2019-01-11 13:03:07 +01:00
parent 7ed255d591
commit 203ca756e1

View File

@ -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)