From bb48d9387be746339dd34d7aa24c314e10cfe14f Mon Sep 17 00:00:00 2001 From: Gibheer Date: Fri, 8 Mar 2019 14:41:38 +0100 Subject: [PATCH] monfront - add link to list checks from a group --- cmd/monfront/main.go | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/cmd/monfront/main.go b/cmd/monfront/main.go index 048a09c..c471ef1 100644 --- a/cmd/monfront/main.go +++ b/cmd/monfront/main.go @@ -129,9 +129,14 @@ func main() { for k, val := range Templates { template.Must(tmpl.New(k).Parse(val)) } + for k, val := range AdminTemplates { + template.Must(tmpl.New("admin-" + k).Parse(val)) + } Tmpl = tmpl http.HandleFunc("/", showChecks) + http.HandleFunc("/admin/", showAdmin) + http.HandleFunc("/admin/action", adminAction) http.HandleFunc("/static/", showStatic) http.HandleFunc("/check", showCheck) http.HandleFunc("/checks", showChecks) @@ -254,11 +259,17 @@ func showChecks(w http.ResponseWriter, r *http.Request) { 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{} + idx := 0 + params := []interface{}{} + if id, found := r.URL.Query()["group_id"]; found { + query += ` join nodes_groups ng on n.id = ng.node_id` + idx += 1 + where = append(where, fmt.Sprintf(`ng.group_id = $%d::int`, idx)) + params = append(params, id[0]) + } if strings.HasPrefix(r.URL.Path, "/unhandled") { where = append(where, `ac.states[1] > 0 and ac.acknowledged = false and ac.enabled = true`) } - idx := 0 - params := []interface{}{} if search, found := r.URL.Query()["search"]; found { idx += 1 // Add the search for nodes. As hostnames or FQDNs are really weird, the @@ -473,7 +484,7 @@ func showCheck(w http.ResponseWriter, r *http.Request) { } } -func returnError(status int, con Context, w http.ResponseWriter) { +func returnError(status int, con interface{}, w http.ResponseWriter) { w.Header()["Content-Type"] = []string{"text/html"} w.WriteHeader(status) if err := Tmpl.ExecuteTemplate(w, "error", con); err != nil { @@ -597,6 +608,7 @@ var ( .mute { background-image: url(/static/icon-mute); } .detail > div { display: grid; grid-template-columns: 25% auto; } .detail > div:hover { background: #dfdfdf; } + .error { padding: 0.5em; background: #ffc6c6; border: 1px solid red; } /* state background colors */ {{ range $mapId, $mapping := .Mappings -}} {{ range $target, $val := $mapping -}} @@ -611,7 +623,13 @@ var (