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"
// 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

View File

@ -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;

View File

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

View File

@ -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;

View File

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

View File

@ -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;

View File

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

View File

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