1
0
Fork 0
mirror of https://github.com/Luzifer/promcertcheck.git synced 2024-11-09 16:30:04 +00:00
promcertcheck/http.go

46 lines
1.1 KiB
Go
Raw Normal View History

2015-09-04 13:36:49 +00:00
package main
//go:generate go-bindata display.html
import (
2015-09-04 13:54:08 +00:00
"encoding/json"
2015-09-04 13:36:49 +00:00
"net/http"
"github.com/flosch/pongo2"
log "github.com/sirupsen/logrus"
2015-09-04 13:36:49 +00:00
)
2015-09-04 13:54:08 +00:00
func htmlHandler(res http.ResponseWriter, r *http.Request) {
tplsrc := MustAsset("display.html")
2015-09-04 13:36:49 +00:00
template, err := pongo2.FromString(string(tplsrc))
if err != nil {
log.Fatal(err)
}
if err := template.ExecuteWriter(pongo2.Context{
2015-09-04 13:36:49 +00:00
"results": probeMonitors,
"certificateOK": certificateOK,
"certificateExpiresSoon": certificateExpiresSoon,
"version": version,
}, res); err != nil {
log.WithError(err).Error("Unable to render display template")
}
2015-09-04 13:36:49 +00:00
}
2015-09-04 13:54:08 +00:00
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)
}
2015-09-04 13:54:08 +00:00
func jsonHandler(res http.ResponseWriter, r *http.Request) {
res.Header().Set("Content-Type", "application/json")
json.NewEncoder(res).Encode(probeMonitors)
}