diff options
author | Gibheer <gibheer+git@zero-knowledge.org> | 2019-01-11 23:02:58 +0100 |
---|---|---|
committer | Gibheer <gibheer+git@zero-knowledge.org> | 2019-01-11 23:02:58 +0100 |
commit | 6a5c0b92bd12f4fb06780b67f5f8019de3c827f0 (patch) | |
tree | 90410c4dce62bd1b14fce26138532505d0707b41 /cmd | |
parent | aed518ea7670efb52a3d7fed3a35f298409c4003 (diff) |
monfront - add notifications to check details
This adds the first basic listing of notifications to the check details.
No idea how many of them should be listed here, but having the list at
all for a start should be okay.
Diffstat (limited to 'cmd')
-rw-r--r-- | cmd/monfront/main.go | 65 |
1 files changed, 56 insertions, 9 deletions
diff --git a/cmd/monfront/main.go b/cmd/monfront/main.go index cc37214..a4855d8 100644 --- a/cmd/monfront/main.go +++ b/cmd/monfront/main.go @@ -87,11 +87,13 @@ type ( } notification struct { - Id int64 - States []int - Output string - Inserted time.Time - Sent time.Time + Id int64 + State int + Output string + Inserted time.Time + Sent pq.NullTime + NotifierName string + MappingId int } group struct { @@ -425,7 +427,37 @@ func showCheck(w http.ResponseWriter, r *http.Request) { return } - // TODO load the last couple notifications + query = `select n.id, states[1], output, inserted, sent, no.name, n.mapping_id + from notifications n + join notifier no on n.notifier_id = no.id + where check_id = $1::bigint + order by inserted desc + limit 500` + rows, err := DB.Query(query, cd.Id) + if err != nil { + log.Printf("could not load notifications: %s", err) + con.Error = "could not load notification information" + returnError(http.StatusInternalServerError, con, w) + return + } + cd.Notifications = []notification{} + for rows.Next() { + if err := rows.Err(); err != nil { + log.Printf("could not load notifications: %s", err) + con.Error = "could not load notification information" + returnError(http.StatusInternalServerError, con, w) + return + } + no := notification{} + if err := rows.Scan(&no.Id, &no.State, &no.Output, &no.Inserted, + &no.Sent, &no.NotifierName, &no.MappingId); err != nil { + log.Printf("could not scan notifications: %s", err) + con.Error = "could not load notification information" + returnError(http.StatusInternalServerError, con, w) + return + } + cd.Notifications = append(cd.Notifications, no) + } if err := loadMappings(&con); err != nil { w.WriteHeader(http.StatusInternalServerError) @@ -717,9 +749,23 @@ var ( <div><span class="label">Message</span><span class="value">{{ .CommandMessage }}</span></div> <div><span class="label">command line</span><span class="value"><code>{{ join .CommandLine " " }}</code></span></div> </article> - States []int64 - Notifiers []notifier - Notifications []notification + <article> + <h1>notifications</h1> + <table> + <thead><tr><th>notifier</th><th>state</th><th>created</th><th>sent</th><th>output</th></thead> + <tbody> + {{ range .Notifications -}} + <tr> + <td>{{ .NotifierName }}</td> + <td class="state-{{ .MappingId }}-{{ .State }}">{{ (index $mapping .MappingId .State).Title }}</td> + <td>{{ .Inserted.Format "2006.01.02 15:04:05" }}</td> + <td>{{ if .Sent.Valid }}{{ .Sent.Time.Format "2006.01.02 15:04:05" }}{{ end }}</td> + <td>{{ .Output }}</td> + </tr> + {{ end -}} + </tbody> + </table> + </article> {{ end }} </content> {{ template "checkformfooter" . }} @@ -731,6 +777,7 @@ var ( } TmplUnhandledGroups = `TODO` Funcs = template.FuncMap{ + "int": func(in int64) int { return int(in) }, "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() }, |