1
0
Fork 0
mirror of https://github.com/Luzifer/promcertcheck.git synced 2024-11-08 07:50:05 +00:00
promcertcheck/http.go
Knut Ahlers 0b62b1cdd8
Add error logging for http rendering errors
Signed-off-by: Knut Ahlers <knut@ahlers.me>
2018-10-01 15:07:52 +02:00

45 lines
1.1 KiB
Go

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