diff --git a/main.go b/main.go index 688b3f8..cca2f54 100644 --- a/main.go +++ b/main.go @@ -5,6 +5,7 @@ import ( "fmt" "log" "net/http" + "net/url" "os" "strings" @@ -42,7 +43,7 @@ func WebhookHandler(w http.ResponseWriter, r *http.Request) { req, err := http.NewRequest("POST", os.Getenv("NTFY_TOPIC"), strings.NewReader(alert.Annotations["description"])) if err != nil { - log.Printf("Building request to %s failed: %s", req.RemoteAddr, err) + log.Printf("Building request failed: %s", err) w.WriteHeader(http.StatusBadRequest) return } @@ -90,6 +91,11 @@ func main() { } } + _, err := url.Parse(os.Getenv("NTFY_TOPIC")) + if err != nil { + log.Fatal("Environment variable NTFY_TOPIC is not a valid URL") + } + http.HandleFunc("/", WebhookHandler) var listenAddr = fmt.Sprintf("%v:%v", os.Getenv("HTTP_ADDRESS"), os.Getenv("HTTP_PORT")) log.Printf("Listening for HTTP requests (webhooks) on %v\n", listenAddr)