add rogueap
This commit is contained in:
		
							parent
							
								
									884cf4f2e2
								
							
						
					
					
						commit
						2a3b692056
					
				|  | @ -39,6 +39,7 @@ type promUnifi struct { | ||||||
| 	USG     *usg | 	USG     *usg | ||||||
| 	USW     *usw | 	USW     *usw | ||||||
| 	Site    *site | 	Site    *site | ||||||
|  | 	RogueAP *rogueap | ||||||
| 	// This interface is passed to the Collect() method. The Collect method uses
 | 	// This interface is passed to the Collect() method. The Collect method uses
 | ||||||
| 	// this interface to retrieve the latest UniFi measurements and export them.
 | 	// this interface to retrieve the latest UniFi measurements and export them.
 | ||||||
| 	Collector poller.Collect | 	Collector poller.Collect | ||||||
|  | @ -137,6 +138,8 @@ func (u *promUnifi) Run(c poller.Collect) error { | ||||||
| 	u.USG = descUSG(u.Namespace + "_device_") | 	u.USG = descUSG(u.Namespace + "_device_") | ||||||
| 	u.USW = descUSW(u.Namespace + "_device_") | 	u.USW = descUSW(u.Namespace + "_device_") | ||||||
| 	u.Site = descSite(u.Namespace + "_site_") | 	u.Site = descSite(u.Namespace + "_site_") | ||||||
|  | 	u.RogueAP = descRogueAP(u.Namespace + "_rogueap_") | ||||||
|  | 
 | ||||||
| 	mux := http.NewServeMux() | 	mux := http.NewServeMux() | ||||||
| 
 | 
 | ||||||
| 	webserver.UpdateOutput(&webserver.Output{Name: PluginName, Config: u.Config}) | 	webserver.UpdateOutput(&webserver.Output{Name: PluginName, Config: u.Config}) | ||||||
|  | @ -295,6 +298,10 @@ func (u *promUnifi) exportMetrics(r report, ch chan<- prometheus.Metric, ourChan | ||||||
| func (u *promUnifi) loopExports(r report) { | func (u *promUnifi) loopExports(r report) { | ||||||
| 	m := r.metrics() | 	m := r.metrics() | ||||||
| 
 | 
 | ||||||
|  | 	for _, s := range m.RogueAPs { | ||||||
|  | 		u.switchExport(r, s) | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
| 	for _, s := range m.Sites { | 	for _, s := range m.Sites { | ||||||
| 		u.switchExport(r, s) | 		u.switchExport(r, s) | ||||||
| 	} | 	} | ||||||
|  | @ -323,6 +330,9 @@ func (u *promUnifi) loopExports(r report) { | ||||||
| 
 | 
 | ||||||
| func (u *promUnifi) switchExport(r report, v interface{}) { | func (u *promUnifi) switchExport(r report, v interface{}) { | ||||||
| 	switch v := v.(type) { | 	switch v := v.(type) { | ||||||
|  | 	case *unifi.RogueAP: | ||||||
|  | 		// r.addRogueAP()
 | ||||||
|  | 		u.exportRogueAP(r, v) | ||||||
| 	case *unifi.UAP: | 	case *unifi.UAP: | ||||||
| 		r.addUAP() | 		r.addUAP() | ||||||
| 		u.exportUAP(r, v) | 		u.exportUAP(r, v) | ||||||
|  |  | ||||||
|  | @ -5,7 +5,7 @@ go 1.15 | ||||||
| require ( | require ( | ||||||
| 	github.com/prometheus/client_golang v1.9.0 | 	github.com/prometheus/client_golang v1.9.0 | ||||||
| 	github.com/prometheus/common v0.18.0 | 	github.com/prometheus/common v0.18.0 | ||||||
| 	github.com/unifi-poller/poller v0.0.8 | 	github.com/unifi-poller/poller v0.0.0-20210315011940-c43dc3c221b4 | ||||||
| 	github.com/unifi-poller/unifi v0.0.7-0.20210315051727-4c317f9a2b95 | 	github.com/unifi-poller/unifi v0.0.7-0.20210315051727-4c317f9a2b95 | ||||||
| 	github.com/unifi-poller/webserver v0.0.0-20200628212441-340749c94743 | 	github.com/unifi-poller/webserver v0.0.0-20210315055414-fa42b37295b7 | ||||||
| ) | ) | ||||||
|  |  | ||||||
|  | @ -80,6 +80,34 @@ type uap struct { | ||||||
| 	RadioTxRetries          *prometheus.Desc | 	RadioTxRetries          *prometheus.Desc | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | type rogueap struct { | ||||||
|  | 	Age        *prometheus.Desc | ||||||
|  | 	BW         *prometheus.Desc | ||||||
|  | 	CenterFreq *prometheus.Desc | ||||||
|  | 	Channel    *prometheus.Desc | ||||||
|  | 	Freq       *prometheus.Desc | ||||||
|  | 	Noise      *prometheus.Desc | ||||||
|  | 	RSSI       *prometheus.Desc | ||||||
|  | 	RSSIAge    *prometheus.Desc | ||||||
|  | 	Signal     *prometheus.Desc | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | func descRogueAP(ns string) *rogueap { | ||||||
|  | 	label := []string{"security", "oui", "band", "mac", "site_name", "essid", "source"} | ||||||
|  | 
 | ||||||
|  | 	return &rogueap{ | ||||||
|  | 		Age:        prometheus.NewDesc(ns+"age", "RogueAP Age", label, nil), | ||||||
|  | 		BW:         prometheus.NewDesc(ns+"bw", "RogueAP BW", label, nil), | ||||||
|  | 		CenterFreq: prometheus.NewDesc(ns+"center_freq", "RogueAP Center Frequency", label, nil), | ||||||
|  | 		Channel:    prometheus.NewDesc(ns+"channel", "RogueAP Channel", label, nil), | ||||||
|  | 		Freq:       prometheus.NewDesc(ns+"frequency", "RogueAP Frequency", label, nil), | ||||||
|  | 		Noise:      prometheus.NewDesc(ns+"noise", "RogueAP Noise", label, nil), | ||||||
|  | 		RSSI:       prometheus.NewDesc(ns+"rssi", "RogueAP RSSI", label, nil), | ||||||
|  | 		RSSIAge:    prometheus.NewDesc(ns+"rssi_age", "RogueAP RSSI Age", label, nil), | ||||||
|  | 		Signal:     prometheus.NewDesc(ns+"signal", "RogueAP Signal", label, nil), | ||||||
|  | 	} | ||||||
|  | } | ||||||
|  | 
 | ||||||
| func descUAP(ns string) *uap { // nolint: funlen
 | func descUAP(ns string) *uap { // nolint: funlen
 | ||||||
| 	labelA := []string{"stat", "site_name", "name", "source"} // stat + labels[1:]
 | 	labelA := []string{"stat", "site_name", "name", "source"} // stat + labels[1:]
 | ||||||
| 	labelV := []string{"vap_name", "bssid", "radio", "radio_name", "essid", "usage", "site_name", "name", "source"} | 	labelV := []string{"vap_name", "bssid", "radio", "radio_name", "essid", "usage", "site_name", "name", "source"} | ||||||
|  | @ -162,6 +190,22 @@ func descUAP(ns string) *uap { // nolint: funlen | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | func (u *promUnifi) exportRogueAP(r report, d *unifi.RogueAP) { | ||||||
|  | 	labels := []string{d.Security, d.Oui, d.Band, d.ApMac, d.SiteName, d.Essid, d.SourceName} | ||||||
|  | 
 | ||||||
|  | 	r.send([]*metric{ | ||||||
|  | 		{u.RogueAP.Age, gauge, d.Age.Val, labels}, | ||||||
|  | 		{u.RogueAP.BW, gauge, d.Bw.Val, labels}, | ||||||
|  | 		{u.RogueAP.CenterFreq, gauge, d.CenterFreq.Val, labels}, | ||||||
|  | 		{u.RogueAP.Channel, gauge, d.Channel, labels}, | ||||||
|  | 		{u.RogueAP.Freq, gauge, d.Freq.Val, labels}, | ||||||
|  | 		{u.RogueAP.Noise, gauge, d.Noise.Val, labels}, | ||||||
|  | 		{u.RogueAP.RSSI, gauge, d.Rssi.Val, labels}, | ||||||
|  | 		{u.RogueAP.RSSIAge, gauge, d.RssiAge.Val, labels}, | ||||||
|  | 		{u.RogueAP.Signal, gauge, d.Signal.Val, labels}, | ||||||
|  | 	}) | ||||||
|  | } | ||||||
|  | 
 | ||||||
| func (u *promUnifi) exportUAP(r report, d *unifi.UAP) { | func (u *promUnifi) exportUAP(r report, d *unifi.UAP) { | ||||||
| 	if !d.Adopted.Val || d.Locating.Val { | 	if !d.Adopted.Val || d.Locating.Val { | ||||||
| 		return | 		return | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue