Start of error reporting

This commit is contained in:
Magnus Åhall 2024-06-29 18:09:56 +02:00
parent e728a302ee
commit b0ffce05f0
8 changed files with 30 additions and 16 deletions

View File

@ -9,19 +9,22 @@ import (
"smon/notification" "smon/notification"
// Standard // Standard
"database/sql"
"encoding/json"
"time" "time"
) )
type NotificationSend struct { type NotificationSend struct {
Prio int Prio int
Service string Service string
ID int ID int
UUID string UUID string
Sent time.Time `db:"send"` Sent time.Time `db:"send"`
OK bool OK bool
Error []byte Error sql.NullString
Acknowledged bool ErrorIndented string
TriggerName string `db:"trigger_name"` Acknowledged bool
TriggerName string `db:"trigger_name"`
} }
func notificationLog(notificationService *notification.Service, problemID int, err error) { func notificationLog(notificationService *notification.Service, problemID int, err error) {
@ -51,7 +54,7 @@ func notificationsSent() (nss []NotificationSend, err error) {
ns.uuid, ns.uuid,
ns.send, ns.send,
ns.ok, ns.ok,
ns.error, ns.error::varchar,
ns.acknowledged ns.acknowledged
FROM FROM
@ -76,6 +79,15 @@ func notificationsSent() (nss []NotificationSend, err error) {
err = werr.Wrap(err) err = werr.Wrap(err)
return 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) nss = append(nss, ns)
} }
return return

View File

@ -1,6 +1,6 @@
#notifications { #notifications {
display: grid; display: grid;
grid-template-columns: repeat(4, min-content); grid-template-columns: repeat(5, min-content);
grid-gap: 4px 16px; grid-gap: 4px 16px;
margin-top: 32px; margin-top: 32px;
margin-bottom: 32px; margin-bottom: 32px;

View File

@ -46,7 +46,7 @@
} }
#areas .area .section .name { #areas .area .section .name {
color: #000; color: #000;
grid-column: -1; grid-column: 1 / -1;
font-weight: bold !important; font-weight: bold !important;
line-height: 24px; line-height: 24px;
} }

View File

@ -1,6 +1,6 @@
#notifications { #notifications {
display: grid; display: grid;
grid-template-columns: repeat(4, min-content); grid-template-columns: repeat(5, min-content);
grid-gap: 4px 16px; grid-gap: 4px 16px;
margin-top: 32px; margin-top: 32px;
margin-bottom: 32px; margin-bottom: 32px;

View File

@ -46,7 +46,7 @@
} }
#areas .area .section .name { #areas .area .section .name {
color: #f7edd7; color: #f7edd7;
grid-column: -1; grid-column: 1 / -1;
font-weight: bold !important; font-weight: bold !important;
line-height: 24px; line-height: 24px;
} }

View File

@ -2,7 +2,7 @@
#notifications { #notifications {
display: grid; display: grid;
grid-template-columns: repeat(4, min-content); grid-template-columns: repeat(5, min-content);
grid-gap: 4px 16px; grid-gap: 4px 16px;
margin-top: 32px; margin-top: 32px;
margin-bottom: 32px; margin-bottom: 32px;

View File

@ -52,7 +52,7 @@
.name { .name {
color: @text2; color: @text2;
grid-column: 1 / -1; grid-column: ~"1 / -1";
font-weight: bold !important; font-weight: bold !important;
line-height: 24px; line-height: 24px;
} }

View File

@ -10,11 +10,13 @@
<div class="header">OK</div> <div class="header">OK</div>
<div class="header">Trigger name</div> <div class="header">Trigger name</div>
<div class="header">Service</div> <div class="header">Service</div>
<div class="header">Error</div>
{{ range .Data.Notifications }} {{ range .Data.Notifications }}
<div>{{ format_time .Sent }}</div> <div>{{ format_time .Sent }}</div>
<div>{{ if .OK }}{{ else }}{{ end }}</div> <div>{{ if .OK }}{{ else }}{{ end }}</div>
<div>{{ .TriggerName }}</div> <div>{{ .TriggerName }}</div>
<div>{{ .Prio }}:{{ .Service }}</div> <div>{{ .Prio }}:{{ .Service }}</div>
<div><pre>{{ if .Error.Valid }}{{ .ErrorIndented }}{{ end }}</pre></div>
{{ end }} {{ end }}
</div> </div>