diff options
author | Gibheer <gibheer+git@zero-knowledge.org> | 2019-01-03 19:48:17 +0100 |
---|---|---|
committer | Gibheer <gibheer+git@zero-knowledge.org> | 2019-01-03 19:48:17 +0100 |
commit | 7c541189fe618793f76a78b3c1d866256582d83e (patch) | |
tree | f33018c99a93512884dd8325629cd157b4d94b43 | |
parent | db3a7cdda936fe5ebadb3ff7792c6acf8f468367 (diff) |
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.
-rw-r--r-- | cmd/monfront/main.go | 27 |
1 files changed, 18 insertions, 9 deletions
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 }} </style> <script> - setTimeout(function() { location.reload(true) }, 30000) + setTimeout(function() { if (document.activeElement.tagName == "BODY") { location.reload(true) } }, 30000) </script> </head> <body> @@ -441,6 +446,7 @@ var ( <button type="submit">search</button> </form> </li> + <li class="submenu"><span class="header">{{ now.Format "2006.01.02 15:04:05" }}</span></li> </ul> </nav>`, "footer": `</body></html>`, @@ -476,8 +482,8 @@ var ( <tr> <td><input type="checkbox" name="checks" value="{{ .CheckID }}" /></td> <td>{{ if ne $current .NodeName }}{{ $current = .NodeName }}<a href="/checks?node_id={{ .NodeId }}">{{ .NodeName }}</a>{{ end }}</td> - <td class="state-{{ .MappingId }}-{{ .State }}">{{ .CommandName }} - {{ (index $mapping .MappingId .State).Title }}</td> - <td>{{ .NextTime.Format "2006.01.02 15:04:05" }}</td> + <td class="state-{{ .MappingId }}-{{ .State }}">{{ if ne .Notify true }}{{ template "icon-mute" . }}{{ end }}{{ .CommandName }} - {{ (index $mapping .MappingId .State).Title }}</td> + <td {{ if ne .Enabled true }}title="This check is disabled." class="disabled"{{ end }}>{{ .NextTime.Format "2006.01.02 15:04:05" }} - in {{ in .NextTime }}</td> <td><pre>{{ .Msg }}</pre></td> </tr> {{ end }} @@ -527,9 +533,12 @@ var ( </content> </form> {{ template "footer" . }}`, + "icon-mute": `<svg class="icon" width="100" height="100" viewBox="0 0 35.3 35.3" version="1.1"><title>Check is muted</title><style>.s0{fill:#191919;}</style><g transform="translate(0,-261.72223)"><path d="m17.6 261.7v35.3L5.3 284.7H0v-10.6l5.3 0zM30.2 273.1l-3.7 3.7-3.7-3.7-2.5 2.5 3.7 3.7-3.7 3.7 2.5 2.5 3.7-3.7 3.7 3.7 2.5-2.5-3.7-3.7 3.7-3.7z" fill="#191919"/></g></svg>`, } 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() }, } ) |