diff --git a/integrations/promunifi/collector.go b/integrations/promunifi/collector.go index 8bdff576..e76517bb 100644 --- a/integrations/promunifi/collector.go +++ b/integrations/promunifi/collector.go @@ -144,21 +144,33 @@ func (u *promUnifi) Run(c poller.Collect) error { // ScrapeHandler allows prometheus to scrape a single source, instead of all sources. func (u *promUnifi) ScrapeHandler(w http.ResponseWriter, r *http.Request) { t := &target{u: u, Filter: &poller.Filter{ - Name: r.URL.Query().Get("input"), // "unifi" - Path: r.URL.Query().Get("path"), // url: "https://127.0.0.1:8443" - Role: r.URL.Query().Get("role"), // configured role in up.conf. + Name: r.URL.Query().Get("input"), // "unifi" + Path: r.URL.Query().Get("target"), // url: "https://127.0.0.1:8443" }} if t.Name == "" { - u.Collector.LogErrorf("input parameter missing on scrape from %v", r.RemoteAddr) - http.Error(w, `'input' parameter must be specified (try "unifi")`, 400) - - return + t.Name = "unifi" // the default } - if t.Role == "" && t.Path == "" { - u.Collector.LogErrorf("role and path parameters missing on scrape from %v", r.RemoteAddr) - http.Error(w, "'role' OR 'path' parameter must be specified: configured role OR unconfigured url", 400) + if pathOld := r.URL.Query().Get("path"); pathOld != "" { + u.Collector.LogErrorf("deprecated 'path' parameter used; update your config to use 'target'") + + if t.Path == "" { + t.Path = pathOld + } + } + + if roleOld := r.URL.Query().Get("role"); roleOld != "" { + u.Collector.LogErrorf("deprecated 'role' parameter used; update your config to use 'target'") + + if t.Path == "" { + t.Path = roleOld + } + } + + if t.Path == "" { + u.Collector.LogErrorf("'target' parameter missing on scrape from %v", r.RemoteAddr) + http.Error(w, "'target' parameter must be specified: configured OR unconfigured url", 400) return } @@ -220,12 +232,7 @@ func (u *promUnifi) collect(ch chan<- prometheus.Metric, filter *poller.Filter) ok := false - if filter == nil { - r.Metrics, ok, err = u.Collector.Metrics() - } else { - r.Metrics, ok, err = u.Collector.MetricsFrom(filter) - } - + r.Metrics, ok, err = u.Collector.MetricsFrom(filter) r.Fetch = time.Since(r.Start) if err != nil {