From 49dac92034f352698429ee1d78d4bfb070006693 Mon Sep 17 00:00:00 2001 From: Gibheer Date: Fri, 2 Dec 2022 09:32:05 +0100 Subject: monfront - only ACK when the check is in alarm state The acknowledged flag gets removed by checkers when the state changes to okay. But if we acknowledge a check when it is okay the notification system stops working. --- cmd/monfront/main.go | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/cmd/monfront/main.go b/cmd/monfront/main.go index 6275b34..63c1b9a 100644 --- a/cmd/monfront/main.go +++ b/cmd/monfront/main.go @@ -215,6 +215,9 @@ func checkAction(con *Context) { action = "reschedule" } + whereFields := []string{} + whereVals := []any{} + switch action { case "mute": setTable = "checks_notify" @@ -255,6 +258,8 @@ func checkAction(con *Context) { case "ack": setClause = "acknowledged = true" setTable = "active_checks" + whereFields = append(whereFields, "states[0]") + whereVals = append(whereVals, 0) hostname, err := os.Hostname() if err != nil { @@ -312,7 +317,15 @@ func checkAction(con *Context) { whereColumn = "check_id" } - _, err := DB.Exec("update "+setTable+" set "+setClause+" where "+whereColumn+" = any ($1::bigint[]);", pq.Array(&checks)) + sql := "update " + setTable + " set " + setClause + " where " + whereColumn + " = any($1::bigint[])" + if len(whereFields) > 0 { + whereVals = append([]any{pq.Array(&checks)}, whereVals...) + for i, column := range whereFields { + sql = sql + " and " + column + fmt.Sprintf(" = $%d", i+1) + } + } + + _, err := DB.Exec(sql, whereVals) if err != nil { con.w.WriteHeader(http.StatusInternalServerError) fmt.Fprintf(con.w, "could not store changes") -- cgit v1.2.3-70-g09d2