diff options
Diffstat (limited to 'cmd/monfront/main.go')
-rw-r--r-- | cmd/monfront/main.go | 28 |
1 files 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 ( <body> <nav id="mainmenu"> <ul> - <li><a href="/">home</a></li> + <li class="submenu"> + <span class="header">main</span> + <ul> + <li><a href="/">home</a></li> + <li><a href="/admin">admin</a></li> + </ul> + </li> <li class="submenu"> <span class="header">all</span> <ul> @@ -772,7 +790,7 @@ var ( {{ range .Groups }} <tr> <td><input type="checkbox" name="nodes" value="{{ .NodeId }}" /></td> - <td>{{ if ne $current .Name }}{{ $current = .Name }}{{ .Name }}{{ end }}</td> + <td>{{ if ne $current .Name }}{{ $current = .Name }}<a href="/checks?group_id={{ .NodeId }}">{{ .Name }}</a>{{ end }}</td> <td><a href="/checks?node_id={{ .NodeId }}">{{ .NodeName }}</a></td> <td class="state-{{ .MappingId }}-{{ .State }}">{{ (index $mapping .MappingId .State).Title }}</td> </tr> |