mirror of
https://github.com/Luzifer/promcertcheck.git
synced 2024-11-08 07:50:05 +00:00
Added JSON output
This commit is contained in:
parent
41eb08c675
commit
f4d369c2d8
3 changed files with 17 additions and 4 deletions
|
@ -23,3 +23,9 @@ Usage of ./certcheck:
|
|||
PromCertcheck dev...
|
||||
Starting to listen on 0.0.0.0:3000
|
||||
```
|
||||
|
||||
## URLs
|
||||
|
||||
- `/` - Shows you a human readable version of the check data
|
||||
- `/metrics` - Prometheus compatible output of the check data
|
||||
- `/results.json` - Gives you a JSON version of the check results including certificate details
|
||||
|
|
8
http.go
8
http.go
|
@ -3,13 +3,14 @@ package main
|
|||
//go:generate go-bindata display.html
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"log"
|
||||
"net/http"
|
||||
|
||||
"github.com/flosch/pongo2"
|
||||
)
|
||||
|
||||
func httpHandler(res http.ResponseWriter, r *http.Request) {
|
||||
func htmlHandler(res http.ResponseWriter, r *http.Request) {
|
||||
tplsrc, _ := Asset("display.html")
|
||||
|
||||
template, err := pongo2.FromString(string(tplsrc))
|
||||
|
@ -24,3 +25,8 @@ func httpHandler(res http.ResponseWriter, r *http.Request) {
|
|||
"version": version,
|
||||
}, res)
|
||||
}
|
||||
|
||||
func jsonHandler(res http.ResponseWriter, r *http.Request) {
|
||||
res.Header().Set("Content-Type", "application/json")
|
||||
json.NewEncoder(res).Encode(probeMonitors)
|
||||
}
|
||||
|
|
7
main.go
7
main.go
|
@ -28,8 +28,8 @@ var (
|
|||
)
|
||||
|
||||
type probeMonitor struct {
|
||||
IsValid prometheus.Gauge
|
||||
Expires prometheus.Gauge
|
||||
IsValid prometheus.Gauge `json:"-"`
|
||||
Expires prometheus.Gauge `json:"-"`
|
||||
Status probeResult
|
||||
Certificate *x509.Certificate
|
||||
}
|
||||
|
@ -66,7 +66,8 @@ func main() {
|
|||
|
||||
r := mux.NewRouter()
|
||||
r.Handle("/metrics", prometheus.Handler())
|
||||
r.HandleFunc("/", httpHandler)
|
||||
r.HandleFunc("/", htmlHandler)
|
||||
r.HandleFunc("/results.json", jsonHandler)
|
||||
http.ListenAndServe(":3000", r)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue