1
0
Fork 0
mirror of https://github.com/Luzifer/promcertcheck.git synced 2024-11-08 16:00:08 +00:00
promcertcheck/http.go
Knut Ahlers 357693db38
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>
2017-06-26 15:08:54 +02:00

43 lines
961 B
Go

package main
//go:generate go-bindata display.html
import (
"encoding/json"
"log"
"net/http"
"github.com/flosch/pongo2"
)
func htmlHandler(res http.ResponseWriter, r *http.Request) {
tplsrc, _ := Asset("display.html")
template, err := pongo2.FromString(string(tplsrc))
if err != nil {
log.Fatal(err)
}
template.ExecuteWriter(pongo2.Context{
"results": probeMonitors,
"certificateOK": certificateOK,
"certificateExpiresSoon": certificateExpiresSoon,
"version": version,
}, 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)
}