aboutsummaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
authorGibheer <gibheer+git@zero-knowledge.org>2022-12-02 09:32:05 +0100
committerGibheer <gibheer+git@zero-knowledge.org>2022-12-02 09:32:05 +0100
commit49dac92034f352698429ee1d78d4bfb070006693 (patch)
tree878172f6ba5ccb50510a1ba0caaba4dc69f5b0fd /cmd
parent4f5114fe3ac8e67395f9b3d0b00d2d48bc3b0c72 (diff)
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.
Diffstat (limited to 'cmd')
-rw-r--r--cmd/monfront/main.go15
1 files changed, 14 insertions, 1 deletions
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")