Make Clients normal
This commit is contained in:
parent
cec0cfec60
commit
13274f1423
|
|
@ -9,7 +9,7 @@ import (
|
||||||
|
|
||||||
// Points generates Unifi Client datapoints for InfluxDB.
|
// Points generates Unifi Client datapoints for InfluxDB.
|
||||||
// These points can be passed directly to influx.
|
// These points can be passed directly to influx.
|
||||||
func (c UCL) Points() ([]*influx.Point, error) {
|
func (c Client) Points() ([]*influx.Point, error) {
|
||||||
// Fix name and hostname fields. Sometimes one or the other is blank.
|
// Fix name and hostname fields. Sometimes one or the other is blank.
|
||||||
switch {
|
switch {
|
||||||
case c.Hostname == "" && c.Name == "":
|
case c.Hostname == "" && c.Name == "":
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,10 @@
|
||||||
package unifi
|
package unifi
|
||||||
|
|
||||||
// Clients contains a list that contains all of the unifi clients from a controller.
|
// Clients contains a list that contains all of the unifi clients from a controller.
|
||||||
type Clients struct {
|
type Clients []Client
|
||||||
UCLs []UCL
|
|
||||||
}
|
|
||||||
|
|
||||||
// UCL defines all the data a connected-network client contains.
|
// Client defines all the data a connected-network client contains.
|
||||||
type UCL struct {
|
type Client struct {
|
||||||
ID string `json:"_id"`
|
ID string `json:"_id"`
|
||||||
IsGuestByUAP FlexBool `json:"_is_guest_by_uap"`
|
IsGuestByUAP FlexBool `json:"_is_guest_by_uap"`
|
||||||
IsGuestByUGW FlexBool `json:"_is_guest_by_ugw"`
|
IsGuestByUGW FlexBool `json:"_is_guest_by_ugw"`
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ func (u *Unifi) parseDevices(data []json.RawMessage, siteName string) *Devices {
|
||||||
} else if t, ok := o["type"].(string); ok {
|
} else if t, ok := o["type"].(string); ok {
|
||||||
assetType = t
|
assetType = t
|
||||||
}
|
}
|
||||||
u.dLogf("Unmarshalling Device Type: %v", assetType)
|
u.dLogf("Unmarshalling Device Type: %v, site %s ", assetType, siteName)
|
||||||
// Choose which type to unmarshal into based on the "type" json key.
|
// Choose which type to unmarshal into based on the "type" json key.
|
||||||
switch assetType { // Unmarshal again into the correct type..
|
switch assetType { // Unmarshal again into the correct type..
|
||||||
case "uap":
|
case "uap":
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ import (
|
||||||
// Points generates Unifi Sites' datapoints for InfluxDB.
|
// Points generates Unifi Sites' datapoints for InfluxDB.
|
||||||
// These points can be passed directly to influx.
|
// These points can be passed directly to influx.
|
||||||
func (u Site) Points() ([]*influx.Point, error) {
|
func (u Site) Points() ([]*influx.Point, error) {
|
||||||
var points []*influx.Point
|
points := []*influx.Point{}
|
||||||
for _, s := range u.Health {
|
for _, s := range u.Health {
|
||||||
tags := map[string]string{
|
tags := map[string]string{
|
||||||
"id": u.ID,
|
"id": u.ID,
|
||||||
|
|
|
||||||
|
|
@ -68,14 +68,13 @@ func (u *Unifi) GetServer() (Server, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetClients returns a response full of clients' data from the Unifi Controller.
|
// GetClients returns a response full of clients' data from the Unifi Controller.
|
||||||
func (u *Unifi) GetClients(sites []Site) (*Clients, error) {
|
func (u *Unifi) GetClients(sites []Site) (Clients, error) {
|
||||||
data := make([]UCL, 0)
|
data := make([]Client, 0)
|
||||||
for _, site := range sites {
|
for _, site := range sites {
|
||||||
var response struct {
|
var response struct {
|
||||||
Data []UCL `json:"data"`
|
Data []Client `json:"data"`
|
||||||
}
|
}
|
||||||
u.dLogf("Polling Site '%s' (%s) Clients", site.Name, site.Desc)
|
u.dLogf("Polling Controller, retreiving Unifi Clients, site %s (%s) ", site.Name, site.Desc)
|
||||||
u.dLogf("Unmarshalling Device Type: ucl")
|
|
||||||
clientPath := fmt.Sprintf(ClientPath, site.Name)
|
clientPath := fmt.Sprintf(ClientPath, site.Name)
|
||||||
if err := u.GetData(clientPath, &response); err != nil {
|
if err := u.GetData(clientPath, &response); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
@ -85,14 +84,13 @@ func (u *Unifi) GetClients(sites []Site) (*Clients, error) {
|
||||||
}
|
}
|
||||||
data = append(data, response.Data...)
|
data = append(data, response.Data...)
|
||||||
}
|
}
|
||||||
return &Clients{UCLs: data}, nil
|
return data, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetDevices returns a response full of devices' data from the Unifi Controller.
|
// GetDevices returns a response full of devices' data from the Unifi Controller.
|
||||||
func (u *Unifi) GetDevices(sites []Site) (*Devices, error) {
|
func (u *Unifi) GetDevices(sites []Site) (*Devices, error) {
|
||||||
devices := new(Devices)
|
devices := new(Devices)
|
||||||
for _, site := range sites {
|
for _, site := range sites {
|
||||||
u.dLogf("Polling Site '%s' (%s) Devices", site.Name, site.Desc)
|
|
||||||
var response struct {
|
var response struct {
|
||||||
Data []json.RawMessage `json:"data"`
|
Data []json.RawMessage `json:"data"`
|
||||||
}
|
}
|
||||||
|
|
@ -136,7 +134,7 @@ func (u *Unifi) GetSites() (Sites, error) {
|
||||||
for i := range response.Data {
|
for i := range response.Data {
|
||||||
sites = append(sites, response.Data[i].Name)
|
sites = append(sites, response.Data[i].Name)
|
||||||
}
|
}
|
||||||
u.dLogf("Found %d sites: %s", len(sites), strings.Join(sites, ","))
|
u.dLogf("Found %d site(s): %s", len(sites), strings.Join(sites, ","))
|
||||||
return response.Data, nil
|
return response.Data, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue