Fix Golang slog in uptime monitor #13
This commit is contained in:
1 parent
adb6e54c9c
commit
fb7a84cf4c
2 files changed
+36
-21
No files matched your search
@@ -1,9 +1,10 @@
|
||||
package notify
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"crypto/tls"
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"log/slog"
|
||||
"net/http"
|
||||
)
|
||||
@@ -15,7 +16,11 @@ type NtfyNotifier struct {
|
||||
|
||||
func NewNtfyNotifier() NtfyNotifier {
|
||||
return NtfyNotifier{
|
||||
client: &http.Client{},
|
||||
client: &http.Client{
|
||||
Transport: &http.Transport{
|
||||
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,21 +43,23 @@ func (n NtfyNotifier) SendNotification(camera string, online bool) {
|
||||
Icon: "https://cdn.jsdelivr.net/gh/walkxcode/dashboard-icons/png/frigate.png",
|
||||
})
|
||||
if jsonErr != nil {
|
||||
slog.Error("Failed to construct JSON request body", jsonErr)
|
||||
slog.Error("Failed to construct JSON request body", "error", jsonErr)
|
||||
return
|
||||
}
|
||||
|
||||
var req, reqErr = http.NewRequest("POST", "https://ntfy.homelab.net", bytes.NewBuffer([]byte(reqJson)))
|
||||
if reqErr != nil {
|
||||
slog.Error("Failed to create HTTP request", reqErr)
|
||||
slog.Error("Failed to create HTTP request", "error", reqErr)
|
||||
return
|
||||
}
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
|
||||
var resp, respErr = n.client.Do(req)
|
||||
if respErr != nil {
|
||||
slog.Error("Failed to send HTTP request", respErr)
|
||||
slog.Error("Failed to send HTTP request", "error", respErr)
|
||||
return
|
||||
}
|
||||
if resp.StatusCode != 200 {
|
||||
slog.Error("Ntfy notification returned HTTP", resp.Status)
|
||||
slog.Error("Ntfy notification returned HTTP", "status", resp.Status)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user