mirror of
https://github.com/Luzifer/promcertcheck.git
synced 2024-11-08 16:00:08 +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...
|
PromCertcheck dev...
|
||||||
Starting to listen on 0.0.0.0:3000
|
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
|
//go:generate go-bindata display.html
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/flosch/pongo2"
|
"github.com/flosch/pongo2"
|
||||||
)
|
)
|
||||||
|
|
||||||
func httpHandler(res http.ResponseWriter, r *http.Request) {
|
func htmlHandler(res http.ResponseWriter, r *http.Request) {
|
||||||
tplsrc, _ := Asset("display.html")
|
tplsrc, _ := Asset("display.html")
|
||||||
|
|
||||||
template, err := pongo2.FromString(string(tplsrc))
|
template, err := pongo2.FromString(string(tplsrc))
|
||||||
|
@ -24,3 +25,8 @@ func httpHandler(res http.ResponseWriter, r *http.Request) {
|
||||||
"version": version,
|
"version": version,
|
||||||
}, res)
|
}, 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 {
|
type probeMonitor struct {
|
||||||
IsValid prometheus.Gauge
|
IsValid prometheus.Gauge `json:"-"`
|
||||||
Expires prometheus.Gauge
|
Expires prometheus.Gauge `json:"-"`
|
||||||
Status probeResult
|
Status probeResult
|
||||||
Certificate *x509.Certificate
|
Certificate *x509.Certificate
|
||||||
}
|
}
|
||||||
|
@ -66,7 +66,8 @@ func main() {
|
||||||
|
|
||||||
r := mux.NewRouter()
|
r := mux.NewRouter()
|
||||||
r.Handle("/metrics", prometheus.Handler())
|
r.Handle("/metrics", prometheus.Handler())
|
||||||
r.HandleFunc("/", httpHandler)
|
r.HandleFunc("/", htmlHandler)
|
||||||
|
r.HandleFunc("/results.json", jsonHandler)
|
||||||
http.ListenAndServe(":3000", r)
|
http.ListenAndServe(":3000", r)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue