Switch to using nats for notifications
This commit is contained in:
@@ -7,13 +7,11 @@ import (
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"git.t-juice.club/torjus/alerttonotify/bus"
|
||||
)
|
||||
|
||||
type Server struct {
|
||||
logger *slog.Logger
|
||||
nbus *bus.NotifyBus
|
||||
ns *NotificationService
|
||||
http.Server
|
||||
}
|
||||
|
||||
@@ -39,9 +37,8 @@ type AlertMessage struct {
|
||||
Alerts []Alert `json:"alerts"`
|
||||
}
|
||||
|
||||
func NewServer(nbus *bus.NotifyBus, logger *slog.Logger) *Server {
|
||||
func NewServer(ns *NotificationService, logger *slog.Logger) *Server {
|
||||
srv := &Server{
|
||||
nbus: nbus,
|
||||
logger: logger,
|
||||
}
|
||||
|
||||
@@ -82,10 +79,14 @@ func (s *Server) handleAlert(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
}
|
||||
|
||||
notification := bus.BusNotification{
|
||||
msg := &BusNotification{
|
||||
Summary: fmt.Sprintf("%d alerts %s", len(alertMessage.Alerts), alertMessage.Status),
|
||||
Body: sb.String(),
|
||||
}
|
||||
s.logger.Debug("Sending notification", "notification", notification)
|
||||
s.nbus.Notify(notification)
|
||||
s.logger.Debug("Sending notification", "message", msg)
|
||||
if err := s.ns.Notify(msg); err != nil {
|
||||
s.logger.Error("Failed to send notification", "error", err)
|
||||
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user