feat: use hostname to query nextcloud version
All checks were successful
Build package / typos (push) Successful in 1m40s

This commit is contained in:
Valentin Doreau 2024-12-05 14:40:50 +01:00
parent 009f07e0af
commit 15b78c2f0c
Signed by: vdoreau
GPG key ID: F3E456CF9A14098B

View file

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