aboutsummaryrefslogtreecommitdiff
path: root/cmd/monfront
diff options
context:
space:
mode:
Diffstat (limited to 'cmd/monfront')
-rw-r--r--cmd/monfront/main.go96
1 files changed, 78 insertions, 18 deletions
diff --git a/cmd/monfront/main.go b/cmd/monfront/main.go
index eaf1d94..7d80c65 100644
--- a/cmd/monfront/main.go
+++ b/cmd/monfront/main.go
@@ -26,6 +26,29 @@ type (
DB string `json:"db"`
Listen string `json:"listen"`
}
+
+ Context struct {
+ Mappings map[int]map[int]MapEntry
+ Checks []check
+ }
+
+ MapEntry struct {
+ Title string
+ Color string
+ }
+
+ check struct {
+ NodeName string
+ CommandName string
+ CheckID int64
+ MappingId int
+ State int
+ Notify bool
+ Enabled bool
+ Notice sql.NullString
+ NextTime time.Time
+ Msg string
+ }
)
func main() {
@@ -149,21 +172,10 @@ func showChecks(w http.ResponseWriter, r *http.Request) {
return
}
- type check struct {
- NodeName string
- CommandName string
- CheckID int64
- State int
- Notify bool
- Enabled bool
- Notice sql.NullString
- NextTime time.Time
- Msg string
- }
checks := []check{}
for rows.Next() {
c := check{}
- err := rows.Scan(&c.CheckID, &c.NodeName, &c.CommandName, &c.State, &c.Notify, &c.Enabled, &c.Notice, &c.NextTime, &c.Msg)
+ err := rows.Scan(&c.CheckID, &c.NodeName, &c.CommandName, &c.MappingId, &c.State, &c.Notify, &c.Enabled, &c.Notice, &c.NextTime, &c.Msg)
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
w.Write([]byte("problems with the database"))
@@ -181,8 +193,17 @@ func showChecks(w http.ResponseWriter, r *http.Request) {
log.Printf("could not parse template: %s", err)
return
}
+ con := Context{
+ Checks: checks,
+ }
+ if err := loadMappings(&con); err != nil {
+ w.WriteHeader(http.StatusInternalServerError)
+ w.Write([]byte("problem with the mappings"))
+ log.Printf("could not load mappings: %s", err)
+ return
+ }
w.Header()["Content-Type"] = []string{"text/html"}
- if err := tmpl.Execute(w, checks); err != nil {
+ if err := tmpl.Execute(w, con); err != nil {
w.WriteHeader(http.StatusInternalServerError)
w.Write([]byte("problem with a template"))
log.Printf("could not execute template: %s", err)
@@ -193,6 +214,7 @@ func showChecks(w http.ResponseWriter, r *http.Request) {
func showUnhandledHosts(w http.ResponseWriter, r *http.Request) {
}
+
func showUnhandledGroups(w http.ResponseWriter, r *http.Request) {
rows, err := DB.Query(SQLShowUnhandledGroups)
if err != nil {
@@ -236,8 +258,40 @@ func showUnhandledGroups(w http.ResponseWriter, r *http.Request) {
return
}
+func loadMappings(c *Context) error {
+ c.Mappings = map[int]map[int]MapEntry{}
+ rows, err := DB.Query(SQLShowMappings)
+ if err != nil {
+ return err
+ }
+
+ for rows.Next() {
+ if rows.Err() != nil {
+ return rows.Err()
+ }
+ var (
+ mapId int
+ target int
+ title string
+ color string
+ )
+ if err := rows.Scan(&mapId, &target, &title, &color); err != nil {
+ return err
+ }
+ ma, found := c.Mappings[mapId]
+ if !found {
+ ma = map[int]MapEntry{}
+ c.Mappings[mapId] = ma
+ }
+ ma[target] = MapEntry{Title: title, Color: color}
+ }
+ return nil
+}
+
var (
- SQLShowChecks = `select c.id, n.name, co.name, ac.states[1] as state, ac.notify,
+ SQLShowMappings = `select mapping_id, target, title, color
+ from mapping_level`
+ SQLShowChecks = `select c.id, n.name, co.name, ac.mapping_id, ac.states[1] as state, ac.notify,
ac.enabled, ac.notice, ac.next_time, ac.msg
from active_checks ac
join checks c on ac.check_id = c.id
@@ -280,10 +334,15 @@ var (
form nav { display: flex; flex-direction: column; }
form nav > * { margin: 0.5em; }
table td, table th { padding: 0.5em; }
- td.state-0 { background: green; }
+ {{ range $mapId, $mapping := .Mappings }}
+ {{ range $target, $val := $mapping }}
+ td.state-{{ $mapId }}-{{ $target }} { background: {{ $val.Color }}; }
+ {{ end }}
+ {{ end }}
+ /* td.state-0 { background: green; }
td.state-1 { background: orange; }
td.state-2 { background: red; }
- td.state-99 { background: gray; }
+ td.state-99 { background: gray; } */
</style>
</head>
<body>
@@ -321,11 +380,12 @@ var (
<thead><tr><th></th><th>host</th><th>status</th><th>next check</th><th>message</th></tr></thead>
<tbody>
{{ $current := "" }}
- {{ range . }}
+ {{ $mapping := .Mappings }}
+ {{ range .Checks }}
<tr>
<td><input type="checkbox" name="checks" value="{{ .CheckID }}" /></td>
<td>{{ if ne $current .NodeName }}{{ $current = .NodeName }}{{ .NodeName }}{{ end }}</td>
- <td class="state-{{ .State }}">{{ .CommandName }} - {{ .State }}</td>
+ <td class="state-{{ .MappingId }}-{{ .State }}">{{ .CommandName }} - {{ (index $mapping .MappingId .State).Title }}</td>
<td>{{ .NextTime.Format "2006.01.02 15:04:05" }}</td>
<td><pre>{{ .Msg }}</pre></td>
</tr>