app-exporter/apps/nextcloud.go
Valentin Doreau 15b78c2f0c
All checks were successful
Build package / typos (push) Successful in 1m40s
feat: use hostname to query nextcloud version
2024-12-05 14:40:50 +01:00

32 lines
534 B
Go

package apps
import (
"encoding/json"
"fmt"
"net/http"
"os"
"github.com/prometheus/client_golang/prometheus"
)
type apiResponse struct {
Version string `json:"version"`
}
func Nextcloud(m Metrics) {
hostname, err := os.Hostname()
if err != nil {
return
}
resp, err := http.Get(fmt.Sprintf("https://%s/status.php", hostname))
if err != nil {
return
}
defer resp.Body.Close()
var res = apiResponse{}
json.NewDecoder(resp.Body).Decode(&res)
m.Nextcloud.With(prometheus.Labels{"version": res.Version}).Set(1)
}