mirror of
https://github.com/Luzifer/promcertcheck.git
synced 2024-11-09 16:30:04 +00:00
Introduce /httpStatus endpoint
which will respond with HTTP200 if everything is fine or HTTP500 if one or more certificates are broken Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
parent
c3f86a29f0
commit
357693db38
2 changed files with 12 additions and 0 deletions
11
http.go
11
http.go
|
@ -26,6 +26,17 @@ func htmlHandler(res http.ResponseWriter, r *http.Request) {
|
||||||
}, res)
|
}, 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) {
|
func jsonHandler(res http.ResponseWriter, r *http.Request) {
|
||||||
res.Header().Set("Content-Type", "application/json")
|
res.Header().Set("Content-Type", "application/json")
|
||||||
json.NewEncoder(res).Encode(probeMonitors)
|
json.NewEncoder(res).Encode(probeMonitors)
|
||||||
|
|
1
main.go
1
main.go
|
@ -61,6 +61,7 @@ func main() {
|
||||||
r := mux.NewRouter()
|
r := mux.NewRouter()
|
||||||
r.Handle("/metrics", prometheus.Handler())
|
r.Handle("/metrics", prometheus.Handler())
|
||||||
r.HandleFunc("/", htmlHandler)
|
r.HandleFunc("/", htmlHandler)
|
||||||
|
r.HandleFunc("/httpStatus", httpStatusHandler)
|
||||||
r.HandleFunc("/results.json", jsonHandler)
|
r.HandleFunc("/results.json", jsonHandler)
|
||||||
http.ListenAndServe(":3000", r)
|
http.ListenAndServe(":3000", r)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue