1
0
Fork 0

Add more logging

This commit is contained in:
Pablo Ovelleiro Corral 2022-11-04 08:32:26 +01:00
parent acd656c6ea
commit c658a0fd33
No known key found for this signature in database
GPG key ID: F7C1D57C8464E825

View file

@ -33,10 +33,11 @@ func WebhookHandler(w http.ResponseWriter, r *http.Request) {
// Skip resolved messages
if alert.Status == string(model.AlertResolved) {
log.Printf("Skipping notification for alert: %v\n", alert)
continue
}
log.Println(alert)
log.Printf("Processing alert: %v\n", alert)
req, err := http.NewRequest("POST", os.Getenv("NTFY_TOPIC"), strings.NewReader(alert.Annotations["description"]))
if err != nil {
@ -58,6 +59,8 @@ func WebhookHandler(w http.ResponseWriter, r *http.Request) {
req.SetBasicAuth(os.Getenv("NTFY_USER"), os.Getenv("NTFY_PASS"))
log.Printf("Sending request: %v\n", req)
if _, err := http.DefaultClient.Do(req); err != nil {
log.Printf("Sending to %s failed: %s\n", req.RemoteAddr, err)
w.WriteHeader(http.StatusBadRequest)