Add device names to clients.
This commit is contained in:
		
							parent
							
								
									ace4d5f3f9
								
							
						
					
					
						commit
						42afb96608
					
				|  | @ -10,12 +10,12 @@ | ||||||
|   version = "v0.3.1" |   version = "v0.3.1" | ||||||
| 
 | 
 | ||||||
| [[projects]] | [[projects]] | ||||||
|   digest = "1:7a6d857bd263ca56a403bfd8a4466b2cb01510e5177c7a16e3f87e084deecca7" |   digest = "1:b148ed25622a093e995956ed755bbfc0dd9907ced48946c3b04ca38fc69319e0" | ||||||
|   name = "github.com/golift/unifi" |   name = "github.com/golift/unifi" | ||||||
|   packages = ["."] |   packages = ["."] | ||||||
|   pruneopts = "UT" |   pruneopts = "UT" | ||||||
|   revision = "4648720c158a153924d1717f7f74736aa42a8ecb" |   revision = "af72953b15407ea795c955ddd503c75ee25c9d47" | ||||||
|   version = "v2.1.4" |   version = "v2.1.5" | ||||||
| 
 | 
 | ||||||
| [[projects]] | [[projects]] | ||||||
|   branch = "master" |   branch = "master" | ||||||
|  |  | ||||||
|  | @ -66,6 +66,9 @@ func (u *UnifiPoller) CollectAndReport() error { | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return err | 		return err | ||||||
| 	} | 	} | ||||||
|  | 	if err := u.AugmentMetrics(metrics); err != nil { | ||||||
|  | 		return err | ||||||
|  | 	} | ||||||
| 	err = u.ReportMetrics(metrics) | 	err = u.ReportMetrics(metrics) | ||||||
| 	u.LogError(err, "reporting metrics") | 	u.LogError(err, "reporting metrics") | ||||||
| 	return err | 	return err | ||||||
|  | @ -90,6 +93,29 @@ func (u *UnifiPoller) CollectMetrics() (*Metrics, error) { | ||||||
| 	return m, err | 	return m, err | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | // AugmentMetrics is our middleware layer between collecting metrics and writing them.
 | ||||||
|  | // This is where we can manipuate the returned data or make arbitrary decisions.
 | ||||||
|  | // This function currently adds parent device names to client metrics.
 | ||||||
|  | func (u *UnifiPoller) AugmentMetrics(metrics *Metrics) error { | ||||||
|  | 	devices := make(map[string]string) | ||||||
|  | 	for _, r := range metrics.UAPs { | ||||||
|  | 		devices[r.Mac] = r.Name | ||||||
|  | 	} | ||||||
|  | 	for _, r := range metrics.USGs { | ||||||
|  | 		devices[r.Mac] = r.Name | ||||||
|  | 	} | ||||||
|  | 	for _, r := range metrics.USWs { | ||||||
|  | 		devices[r.Mac] = r.Name | ||||||
|  | 	} | ||||||
|  | 	// These come blank, so set them here.
 | ||||||
|  | 	for i, c := range metrics.Clients { | ||||||
|  | 		metrics.Clients[i].SwName = devices[c.SwMac] | ||||||
|  | 		metrics.Clients[i].ApName = devices[c.ApMac] | ||||||
|  | 		metrics.Clients[i].GwName = devices[c.GwMac] | ||||||
|  | 	} | ||||||
|  | 	return nil | ||||||
|  | } | ||||||
|  | 
 | ||||||
| // ReportMetrics batches all the metrics and writes them to InfluxDB.
 | // ReportMetrics batches all the metrics and writes them to InfluxDB.
 | ||||||
| // Returns an error if the write to influx fails.
 | // Returns an error if the write to influx fails.
 | ||||||
| func (u *UnifiPoller) ReportMetrics(metrics *Metrics) error { | func (u *UnifiPoller) ReportMetrics(metrics *Metrics) error { | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue