diff --git a/http.go b/http.go index d1a17e5..2235ea3 100644 --- a/http.go +++ b/http.go @@ -26,6 +26,17 @@ func htmlHandler(res http.ResponseWriter, r *http.Request) { }, res) } +func httpStatusHandler(res http.ResponseWriter, r *http.Request) { + httpStatus := http.StatusOK + for _, mon := range probeMonitors { + if mon.Status != certificateOK { + httpStatus = http.StatusInternalServerError + } + } + + res.WriteHeader(httpStatus) +} + func jsonHandler(res http.ResponseWriter, r *http.Request) { res.Header().Set("Content-Type", "application/json") json.NewEncoder(res).Encode(probeMonitors) diff --git a/main.go b/main.go index b5a5a7c..4bfb9f8 100644 --- a/main.go +++ b/main.go @@ -61,6 +61,7 @@ func main() { r := mux.NewRouter() r.Handle("/metrics", prometheus.Handler()) r.HandleFunc("/", htmlHandler) + r.HandleFunc("/httpStatus", httpStatusHandler) r.HandleFunc("/results.json", jsonHandler) http.ListenAndServe(":3000", r) }