Setup repeat camera down notifications #24

This commit is contained in:
ashish committed 2025-05-15 12:01:49 -05:00
1 parent 7b24dad5b9
commit e6ccd8f1d7
8 files changed
+38 -46

No files matched your search

+1 -2
View File
@@ -5,14 +5,13 @@ import (
"strings"
)
type Notifier interface {
SendNotification(camera string, online bool)
}
func createMessage(camera string, online bool) string {
var msgTemplates = map[bool]string{
true: "%s camera is back online!",
true: "%s camera is back online!",
false: "%s camera is offline!",
}
+12 -13
View File
@@ -1,15 +1,14 @@
package notify
import (
"crypto/tls"
"bytes"
"crypto/tls"
"encoding/json"
"fmt"
"log/slog"
"net/http"
)
type NtfyNotifier struct {
client *http.Client
}
@@ -26,21 +25,21 @@ func NewNtfyNotifier() NtfyNotifier {
func (n NtfyNotifier) SendNotification(camera string, online bool) {
type ntfyJson struct {
Topic string `json:"topic"`
Title string `json:"title"`
Message string `json:"message"`
Priority int `json:"priority"`
Click string `json:"click"`
Icon string `json:"icon"`
Topic string `json:"topic"`
Title string `json:"title"`
Message string `json:"message"`
Priority int `json:"priority"`
Click string `json:"click"`
Icon string `json:"icon"`
}
var reqJson, jsonErr = json.Marshal(ntfyJson{
Topic: "frigate_camera_uptime",
Title: "Frigate",
Message: createMessage(camera, online),
Topic: "frigate_camera_uptime",
Title: "Frigate",
Message: createMessage(camera, online),
Priority: 3,
Click: fmt.Sprintf("https://frigate.homelab.net/cameras/%s", camera),
Icon: "https://cdn.jsdelivr.net/gh/walkxcode/dashboard-icons/png/frigate.png",
Click: fmt.Sprintf("https://frigate.homelab.net/cameras/%s", camera),
Icon: "https://cdn.jsdelivr.net/gh/walkxcode/dashboard-icons/png/frigate.png",
})
if jsonErr != nil {
slog.Error("Failed to construct JSON request body", "error", jsonErr)