diff --git a/core/unifi/clients_influx.go b/core/unifi/clients_influx.go index 9219c785..e59bbcf7 100644 --- a/core/unifi/clients_influx.go +++ b/core/unifi/clients_influx.go @@ -9,7 +9,7 @@ import ( // Points generates Unifi Client datapoints for InfluxDB. // 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. switch { case c.Hostname == "" && c.Name == "": diff --git a/core/unifi/clients_type.go b/core/unifi/clients_type.go index 820e4b48..662a4ca6 100644 --- a/core/unifi/clients_type.go +++ b/core/unifi/clients_type.go @@ -1,12 +1,10 @@ package unifi // Clients contains a list that contains all of the unifi clients from a controller. -type Clients struct { - UCLs []UCL -} +type Clients []Client -// UCL defines all the data a connected-network client contains. -type UCL struct { +// Client defines all the data a connected-network client contains. +type Client struct { ID string `json:"_id"` IsGuestByUAP FlexBool `json:"_is_guest_by_uap"` IsGuestByUGW FlexBool `json:"_is_guest_by_ugw"` diff --git a/core/unifi/parsers.go b/core/unifi/parsers.go index 672187ea..a2b97ce5 100644 --- a/core/unifi/parsers.go +++ b/core/unifi/parsers.go @@ -13,7 +13,7 @@ func (u *Unifi) parseDevices(data []json.RawMessage, siteName string) *Devices { } else if t, ok := o["type"].(string); ok { 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. switch assetType { // Unmarshal again into the correct type.. case "uap": diff --git a/core/unifi/site_influx.go b/core/unifi/site_influx.go index a0ad2c77..bd219ba9 100644 --- a/core/unifi/site_influx.go +++ b/core/unifi/site_influx.go @@ -10,7 +10,7 @@ import ( // Points generates Unifi Sites' datapoints for InfluxDB. // These points can be passed directly to influx. func (u Site) Points() ([]*influx.Point, error) { - var points []*influx.Point + points := []*influx.Point{} for _, s := range u.Health { tags := map[string]string{ "id": u.ID, diff --git a/core/unifi/unifi.go b/core/unifi/unifi.go index 0676b3e1..aacd9cf3 100644 --- a/core/unifi/unifi.go +++ b/core/unifi/unifi.go @@ -68,14 +68,13 @@ func (u *Unifi) GetServer() (Server, error) { } // GetClients returns a response full of clients' data from the Unifi Controller. -func (u *Unifi) GetClients(sites []Site) (*Clients, error) { - data := make([]UCL, 0) +func (u *Unifi) GetClients(sites []Site) (Clients, error) { + data := make([]Client, 0) for _, site := range sites { var response struct { - Data []UCL `json:"data"` + Data []Client `json:"data"` } - u.dLogf("Polling Site '%s' (%s) Clients", site.Name, site.Desc) - u.dLogf("Unmarshalling Device Type: ucl") + u.dLogf("Polling Controller, retreiving Unifi Clients, site %s (%s) ", site.Name, site.Desc) clientPath := fmt.Sprintf(ClientPath, site.Name) if err := u.GetData(clientPath, &response); err != nil { return nil, err @@ -85,14 +84,13 @@ func (u *Unifi) GetClients(sites []Site) (*Clients, error) { } 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. func (u *Unifi) GetDevices(sites []Site) (*Devices, error) { devices := new(Devices) for _, site := range sites { - u.dLogf("Polling Site '%s' (%s) Devices", site.Name, site.Desc) var response struct { Data []json.RawMessage `json:"data"` } @@ -136,7 +134,7 @@ func (u *Unifi) GetSites() (Sites, error) { for i := range response.Data { 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 }