From 15b78c2f0c1779337c2377bcb5782b94120ad965 Mon Sep 17 00:00:00 2001 From: Valentin Doreau Date: Thu, 5 Dec 2024 14:40:50 +0100 Subject: [PATCH] feat: use hostname to query nextcloud version --- apps/nextcloud.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/apps/nextcloud.go b/apps/nextcloud.go index a940e77..8c21cd5 100644 --- a/apps/nextcloud.go +++ b/apps/nextcloud.go @@ -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) }