From b0ffce05f04ca2fb635abf673afc0513c572ee53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Magnus=20=C3=85hall?= Date: Sat, 29 Jun 2024 18:09:56 +0200 Subject: [PATCH] Start of error reporting --- notification_log.go | 32 +++++++++++++++------- static/css/default_light/notifications.css | 2 +- static/css/default_light/problems.css | 2 +- static/css/gruvbox/notifications.css | 2 +- static/css/gruvbox/problems.css | 2 +- static/less/notifications.less | 2 +- static/less/problems.less | 2 +- views/pages/notifications.gotmpl | 2 ++ 8 files changed, 30 insertions(+), 16 deletions(-) diff --git a/notification_log.go b/notification_log.go index a02495a..d080cc9 100644 --- a/notification_log.go +++ b/notification_log.go @@ -9,19 +9,22 @@ import ( "smon/notification" // Standard + "database/sql" + "encoding/json" "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"` + Prio int + Service string + ID int + UUID string + Sent time.Time `db:"send"` + OK bool + Error sql.NullString + ErrorIndented string + Acknowledged bool + TriggerName string `db:"trigger_name"` } func notificationLog(notificationService *notification.Service, problemID int, err error) { @@ -51,7 +54,7 @@ func notificationsSent() (nss []NotificationSend, err error) { ns.uuid, ns.send, ns.ok, - ns.error, + ns.error::varchar, ns.acknowledged FROM @@ -76,6 +79,15 @@ func notificationsSent() (nss []NotificationSend, err error) { err = werr.Wrap(err) return } + + // Error contains json (can be NULL), + // and can at least be presented indented. + foo := make(map[string]any) + json.Unmarshal([]byte(ns.Error.String), &foo) + var j []byte + j, err = json.MarshalIndent(foo, "", " ") + ns.ErrorIndented = string(j) + nss = append(nss, ns) } return diff --git a/static/css/default_light/notifications.css b/static/css/default_light/notifications.css index 8dc1736..b051c08 100644 --- a/static/css/default_light/notifications.css +++ b/static/css/default_light/notifications.css @@ -1,6 +1,6 @@ #notifications { display: grid; - grid-template-columns: repeat(4, min-content); + grid-template-columns: repeat(5, min-content); grid-gap: 4px 16px; margin-top: 32px; margin-bottom: 32px; diff --git a/static/css/default_light/problems.css b/static/css/default_light/problems.css index e597be8..3a415de 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; + grid-column: 1 / -1; font-weight: bold !important; line-height: 24px; } diff --git a/static/css/gruvbox/notifications.css b/static/css/gruvbox/notifications.css index e454f96..c6a1d82 100644 --- a/static/css/gruvbox/notifications.css +++ b/static/css/gruvbox/notifications.css @@ -1,6 +1,6 @@ #notifications { display: grid; - grid-template-columns: repeat(4, min-content); + grid-template-columns: repeat(5, min-content); grid-gap: 4px 16px; margin-top: 32px; margin-bottom: 32px; diff --git a/static/css/gruvbox/problems.css b/static/css/gruvbox/problems.css index b26c2c1..6c014f7 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; + grid-column: 1 / -1; font-weight: bold !important; line-height: 24px; } diff --git a/static/less/notifications.less b/static/less/notifications.less index f0a64f1..8753486 100644 --- a/static/less/notifications.less +++ b/static/less/notifications.less @@ -2,7 +2,7 @@ #notifications { display: grid; - grid-template-columns: repeat(4, min-content); + grid-template-columns: repeat(5, min-content); grid-gap: 4px 16px; margin-top: 32px; margin-bottom: 32px; diff --git a/static/less/problems.less b/static/less/problems.less index e68a06e..601a9b4 100644 --- a/static/less/problems.less +++ b/static/less/problems.less @@ -52,7 +52,7 @@ .name { color: @text2; - grid-column: 1 / -1; + grid-column: ~"1 / -1"; font-weight: bold !important; line-height: 24px; } diff --git a/views/pages/notifications.gotmpl b/views/pages/notifications.gotmpl index 45bb2a0..f93e39a 100644 --- a/views/pages/notifications.gotmpl +++ b/views/pages/notifications.gotmpl @@ -10,11 +10,13 @@
OK
Trigger name
Service
+
Error
{{ range .Data.Notifications }}
{{ format_time .Sent }}
{{ if .OK }}✔{{ else }}✗{{ end }}
{{ .TriggerName }}
{{ .Prio }}:{{ .Service }}
+
{{ if .Error.Valid }}{{ .ErrorIndented }}{{ end }}
{{ end }}