From 7c541189fe618793f76a78b3c1d866256582d83e Mon Sep 17 00:00:00 2001 From: Gibheer Date: Thu, 3 Jan 2019 19:48:17 +0100 Subject: monfront - fix actions on checks This is related to #6. The muting, enable and disable were not working properly, because the date was not set when the check was updated. With this comes also the first icon to represent the muted status. --- cmd/monfront/main.go | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) (limited to 'cmd') diff --git a/cmd/monfront/main.go b/cmd/monfront/main.go index 989759a..fd3d3ec 100644 --- a/cmd/monfront/main.go +++ b/cmd/monfront/main.go @@ -48,6 +48,7 @@ type ( MappingId int State int Enabled bool + Notify bool Notice sql.NullString NextTime time.Time Msg string @@ -126,9 +127,9 @@ func checkAction(w http.ResponseWriter, r *http.Request) { setTable = "checks_notify" setClause = "enabled = true" case "enable": - setClause = "enabled = true" + setClause = "enabled = true, updated = now()" case "disable": - setClause = "enabled = false" + setClause = "enabled = false, updated = now()" case "reschedule": setClause = "next_time = now()" setTable = "active_checks" @@ -184,14 +185,16 @@ func checkAction(w http.ResponseWriter, r *http.Request) { func showChecks(w http.ResponseWriter, r *http.Request) { query := `select c.id, n.id, n.name, co.name, ac.mapping_id, ac.states[1] as state, - ac.enabled, ac.notice, ac.next_time, ac.msg + ac.enabled, ac.notice, ac.next_time, ac.msg, + case when cn.check_id is null then false else true end as notify_enabled from active_checks ac join checks c on ac.check_id = c.id join nodes n on c.node_id = n.id - join commands co on c.command_id = co.id` + join commands co on c.command_id = co.id + left join ( select distinct check_id from checks_notify where enabled = true) cn on c.id = cn.check_id` where := []string{} if strings.HasPrefix(r.URL.Path, "/unhandled") { - where = append(where, `ac.states[1] > 0`) + where = append(where, `ac.states[1] > 0 and ac.acknowledged = false`) } idx := 0 params := []interface{}{} @@ -236,7 +239,7 @@ func showChecks(w http.ResponseWriter, r *http.Request) { checks := []check{} for rows.Next() { c := check{} - err := rows.Scan(&c.CheckID, &c.NodeId, &c.NodeName, &c.CommandName, &c.MappingId, &c.State, &c.Enabled, &c.Notice, &c.NextTime, &c.Msg) + err := rows.Scan(&c.CheckID, &c.NodeId, &c.NodeName, &c.CommandName, &c.MappingId, &c.State, &c.Enabled, &c.Notice, &c.NextTime, &c.Msg, &c.Notify) if err != nil { w.WriteHeader(http.StatusInternalServerError) w.Write([]byte("problems with the database")) @@ -407,6 +410,8 @@ var ( table th { background: #cccccc; color: #3a5f78; } table td, table th { text-align: center; } table pre { font-size: 75%; } + table td.disabled { text-decoration: line-through; } + .icon { height: 1em; margin: 0; width: 1em; vertical-align: bottom; margin-right: 0.5em;} {{ range $mapId, $mapping := .Mappings }} {{ range $target, $val := $mapping }} td.state-{{ $mapId }}-{{ $target }} { background: {{ $val.Color }}; } @@ -414,7 +419,7 @@ var ( {{ end }} @@ -441,6 +446,7 @@ var ( + `, "footer": ``, @@ -476,8 +482,8 @@ var ( {{ if ne $current .NodeName }}{{ $current = .NodeName }}{{ .NodeName }}{{ end }} - {{ .CommandName }} - {{ (index $mapping .MappingId .State).Title }} - {{ .NextTime.Format "2006.01.02 15:04:05" }} + {{ if ne .Notify true }}{{ template "icon-mute" . }}{{ end }}{{ .CommandName }} - {{ (index $mapping .MappingId .State).Title }} + {{ .NextTime.Format "2006.01.02 15:04:05" }} - in {{ in .NextTime }}
{{ .Msg }}
{{ end }} @@ -527,9 +533,12 @@ var ( {{ template "footer" . }}`, + "icon-mute": `Check is muted`, } TmplUnhandledGroups = `TODO` Funcs = template.FuncMap{ "sub": func(base, amount int) int { return base - amount }, + "in": func(t time.Time) time.Duration { return t.Sub(time.Now()).Round(1 * time.Second) }, + "now": func() time.Time { return time.Now() }, } ) -- cgit v1.2.3-70-g09d2