aboutsummaryrefslogtreecommitdiff
path: root/cmd/monfront/main.go
diff options
context:
space:
mode:
Diffstat (limited to 'cmd/monfront/main.go')
-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")