diff --git a/main.go b/main.go index 8094e2d..fb11c0b 100644 --- a/main.go +++ b/main.go @@ -150,6 +150,8 @@ func main() { // {{{ service.Register("/trigger/run/{id}", false, false, actionTriggerRun) service.Register("/trigger/delete/{id}", false, false, actionTriggerDelete) + service.Register("/notifications", false, false, pageNotifications) + service.Register("/configuration", false, false, pageConfiguration) service.Register("/configuration/theme", false, false, actionConfigurationTheme) service.Register("/configuration/timezone", false, false, actionConfigurationTimezone) @@ -1194,3 +1196,21 @@ func actionConfigurationNotificationDelete(w http.ResponseWriter, r *http.Reques w.Header().Add("Location", "/configuration") w.WriteHeader(302) } // }}} + +func pageNotifications(w http.ResponseWriter, r *http.Request, _ *session.T) { // {{{ + nss, err := notificationsSent() + if err != nil { + pageError(w, "/", werr.Wrap(err).Log()) + } + + page := Page{ + LAYOUT: "main", + PAGE: "notifications", + CONFIG: smonConfig.Settings, + Data: map[string]any{ + "Notifications": nss, + }, + } + + page.Render(w, r) +} // }}} diff --git a/notification_log.go b/notification_log.go index 7b70d35..a02495a 100644 --- a/notification_log.go +++ b/notification_log.go @@ -1,11 +1,29 @@ package main import ( + // External + werr "git.gibonuddevalla.se/go/wrappederror" + "github.com/jmoiron/sqlx" + // Internal "smon/notification" + // Standard + "time" ) +type NotificationSend struct { + Prio int + Service string + ID int + UUID string + Sent time.Time `db:"send"` + OK bool + Error []byte + Acknowledged bool + TriggerName string `db:"trigger_name"` +} + func notificationLog(notificationService *notification.Service, problemID int, err error) { if err == nil { logger.Info("notification", "service", (*notificationService).GetType(), "problemID", problemID, "prio", (*notificationService).GetPrio(), "ok", true) @@ -18,3 +36,47 @@ func notificationLog(notificationService *notification.Service, problemID int, e logger.Error("notification", "service", (*notificationService).GetType(), "problemID", problemID, "prio", (*notificationService).GetPrio(), "ok", false, "error", err) } } + +func notificationsSent() (nss []NotificationSend, err error) { + var rows *sqlx.Rows + rows, err = service.Db.Conn.Queryx( + ` + SELECT + n.prio, + n.service, + + t.name AS trigger_name, + + ns.id, + ns.uuid, + ns.send, + ns.ok, + ns.error, + ns.acknowledged + + FROM + public.notification_send ns + INNER JOIN notification n ON ns.notification_id = n.id + INNER JOIN problem p ON ns.problem_id = p.id + INNER JOIN "trigger" t ON p.trigger_id = t.id + + ORDER BY + send DESC + `) + if err != nil { + err = werr.Wrap(err) + return + } + defer rows.Close() + + for rows.Next() { + ns := NotificationSend{} + err = rows.StructScan(&ns) + if err != nil { + err = werr.Wrap(err) + return + } + nss = append(nss, ns) + } + return +} diff --git a/static/css/default_light/gruvbox.css b/static/css/default_light/gruvbox.css index 54b45b4..d0860ec 100644 --- a/static/css/default_light/gruvbox.css +++ b/static/css/default_light/gruvbox.css @@ -1,6 +1,9 @@ body { background-image: url(/images/v0/gruvbox/background.svg); } +#menu { + box-shadow: 2px 0px 5px 3px rgba(0, 0, 0, 0.25); +} #areas .area { box-shadow: 5px 5px 15px 0px rgba(0, 0, 0, 0.5); } diff --git a/static/css/default_light/main.css b/static/css/default_light/main.css index 30f8dae..10baf58 100644 --- a/static/css/default_light/main.css +++ b/static/css/default_light/main.css @@ -39,7 +39,7 @@ html { #layout { display: grid; grid-template-areas: "menu content"; - grid-template-columns: 104px 1fr; + grid-template-columns: 128px 1fr; height: 100vh; } #menu { diff --git a/static/css/default_light/problems.css b/static/css/default_light/problems.css index 3a415de..e597be8 100644 --- a/static/css/default_light/problems.css +++ b/static/css/default_light/problems.css @@ -46,7 +46,7 @@ } #areas .area .section .name { color: #000; - grid-column: 1 / -1; + grid-column: -1; font-weight: bold !important; line-height: 24px; } diff --git a/static/css/gruvbox/main.css b/static/css/gruvbox/main.css index b69f507..98f785f 100644 --- a/static/css/gruvbox/main.css +++ b/static/css/gruvbox/main.css @@ -39,7 +39,7 @@ html { #layout { display: grid; grid-template-areas: "menu content"; - grid-template-columns: 104px 1fr; + grid-template-columns: 128px 1fr; height: 100vh; } #menu { diff --git a/static/css/gruvbox/problems.css b/static/css/gruvbox/problems.css index 6c014f7..b26c2c1 100644 --- a/static/css/gruvbox/problems.css +++ b/static/css/gruvbox/problems.css @@ -46,7 +46,7 @@ } #areas .area .section .name { color: #f7edd7; - grid-column: 1 / -1; + grid-column: -1; font-weight: bold !important; line-height: 24px; } diff --git a/static/less/main.less b/static/less/main.less index 81d35a5..aa11833 100644 --- a/static/less/main.less +++ b/static/less/main.less @@ -52,7 +52,7 @@ html { #layout { display: grid; grid-template-areas: "menu content"; - grid-template-columns: 104px 1fr; + grid-template-columns: 128px 1fr; height: 100vh; } @@ -248,7 +248,7 @@ button { } .line { - grid-column: 1 / -1; + grid-column: ~"1 / -1"; border-bottom: 1px solid .lighterOrDarker(@bg1, 15%)[@result]; } diff --git a/views/components/menu.gotmpl b/views/components/menu.gotmpl index c0c1ddf..5a45fe0 100644 --- a/views/components/menu.gotmpl +++ b/views/components/menu.gotmpl @@ -28,6 +28,13 @@ +
+ + +
Notifications
+
+
+