Initial add of notifications
This commit is contained in:
parent
24cf7fd4cc
commit
ca9a6c3e1d
9 changed files with 98 additions and 6 deletions
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue