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