diff --git a/cmd/monfront/main.go b/cmd/monfront/main.go index c471ef1..b8ba1de 100644 --- a/cmd/monfront/main.go +++ b/cmd/monfront/main.go @@ -37,6 +37,7 @@ type ( Checks []check CheckDetails *checkDetails Groups []group + Unhandled bool // set this flag when unhandled was called } MapEntry struct { @@ -250,6 +251,7 @@ func checkAction(w http.ResponseWriter, r *http.Request) { } func showChecks(w http.ResponseWriter, r *http.Request) { + con := Context{} 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, case when cn.check_id is null then false else true end as notify_enabled @@ -269,6 +271,7 @@ func showChecks(w http.ResponseWriter, r *http.Request) { } if strings.HasPrefix(r.URL.Path, "/unhandled") { where = append(where, `ac.states[1] > 0 and ac.acknowledged = false and ac.enabled = true`) + con.Unhandled = true } if search, found := r.URL.Query()["search"]; found { idx += 1 @@ -324,9 +327,7 @@ func showChecks(w http.ResponseWriter, r *http.Request) { } checks = append(checks, c) } - con := Context{ - Checks: checks, - } + con.Checks = checks if err := loadMappings(&con); err != nil { con.Error = "could not load mapping data" w.WriteHeader(http.StatusInternalServerError) @@ -345,6 +346,7 @@ func showChecks(w http.ResponseWriter, r *http.Request) { } func showGroups(w http.ResponseWriter, r *http.Request) { + con := Context{} query := `select groupid, groupname, nodeid, nodename, mapping_id, state from ( select g.id groupid, g.name groupname, n.id nodeid, n.name nodename, ac.mapping_id, @@ -359,6 +361,7 @@ func showGroups(w http.ResponseWriter, r *http.Request) { where state = maxstate` if strings.HasPrefix(r.URL.Path, "/unhandled") { query += ` and state > 0` + con.Unhandled = true } if strings.HasPrefix(r.URL.Path, "/unhandled") { @@ -387,9 +390,7 @@ func showGroups(w http.ResponseWriter, r *http.Request) { } groups = append(groups, g) } - con := Context{ - Groups: groups, - } + con.Groups = groups if err := loadMappings(&con); err != nil { w.WriteHeader(http.StatusInternalServerError) w.Write([]byte("problem with the mappings")) @@ -790,7 +791,7 @@ var ( {{ range .Groups }} - {{ if ne $current .Name }}{{ $current = .Name }}{{ .Name }}{{ end }} + {{ if ne $current .Name }}{{ $current = .Name }}{{ .Name }}{{ end }} {{ .NodeName }} {{ (index $mapping .MappingId .State).Title }}