From 6a5c0b92bd12f4fb06780b67f5f8019de3c827f0 Mon Sep 17 00:00:00 2001 From: Gibheer Date: Fri, 11 Jan 2019 23:02:58 +0100 Subject: 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. --- cmd/monfront/main.go | 65 ++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 56 insertions(+), 9 deletions(-) (limited to 'cmd/monfront') 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 (
Message{{ .CommandMessage }}
command line{{ join .CommandLine " " }}
- States []int64 - Notifiers []notifier - Notifications []notification +
+

notifications

+ + + + {{ range .Notifications -}} + + + + + + + + {{ end -}} + +
notifierstatecreatedsentoutput
{{ .NotifierName }}{{ (index $mapping .MappingId .State).Title }}{{ .Inserted.Format "2006.01.02 15:04:05" }}{{ if .Sent.Valid }}{{ .Sent.Time.Format "2006.01.02 15:04:05" }}{{ end }}{{ .Output }}
+
{{ end }} {{ 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() }, -- cgit v1.2.3-70-g09d2