Merge pull request #3 from unifi-poller/dn2_no_role

Deprecate role param.
This commit is contained in:
David Newhall II 2020-06-15 06:39:47 -07:00 committed by GitHub
commit e6d4f6a589
1 changed files with 23 additions and 16 deletions

View File

@ -145,20 +145,32 @@ func (u *promUnifi) Run(c poller.Collect) error {
func (u *promUnifi) ScrapeHandler(w http.ResponseWriter, r *http.Request) { func (u *promUnifi) ScrapeHandler(w http.ResponseWriter, r *http.Request) {
t := &target{u: u, Filter: &poller.Filter{ t := &target{u: u, Filter: &poller.Filter{
Name: r.URL.Query().Get("input"), // "unifi" Name: r.URL.Query().Get("input"), // "unifi"
Path: r.URL.Query().Get("path"), // url: "https://127.0.0.1:8443" Path: r.URL.Query().Get("target"), // url: "https://127.0.0.1:8443"
Role: r.URL.Query().Get("role"), // configured role in up.conf.
}} }}
if t.Name == "" { if t.Name == "" {
u.Collector.LogErrorf("input parameter missing on scrape from %v", r.RemoteAddr) t.Name = "unifi" // the default
http.Error(w, `'input' parameter must be specified (try "unifi")`, 400)
return
} }
if t.Role == "" && t.Path == "" { if pathOld := r.URL.Query().Get("path"); pathOld != "" {
u.Collector.LogErrorf("role and path parameters missing on scrape from %v", r.RemoteAddr) u.Collector.LogErrorf("deprecated 'path' parameter used; update your config to use 'target'")
http.Error(w, "'role' OR 'path' parameter must be specified: configured role OR unconfigured url", 400)
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 return
} }
@ -220,12 +232,7 @@ func (u *promUnifi) collect(ch chan<- prometheus.Metric, filter *poller.Filter)
ok := false 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) r.Fetch = time.Since(r.Start)
if err != nil { if err != nil {