app-exporter/apps/nextcloud.go

33 lines
534 B
Go
Raw Permalink Normal View History

2024-10-31 20:42:28 +01:00
package apps
import (
"encoding/json"
"fmt"
2024-10-31 20:42:28 +01:00
"net/http"
"os"
2024-10-31 20:42:28 +01:00
"github.com/prometheus/client_golang/prometheus"
)
type apiResponse struct {
Version string `json:"version"`
2024-10-31 20:42:28 +01:00
}
func Nextcloud(m Metrics) {
hostname, err := os.Hostname()
if err != nil {
return
}
resp, err := http.Get(fmt.Sprintf("https://%s/status.php", hostname))
2024-10-31 20:42:28 +01:00
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)
2024-10-31 20:42:28 +01:00
}