Make Clients normal
This commit is contained in:
parent
cec0cfec60
commit
13274f1423
|
|
@ -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 == "":
|
||||
|
|
|
|||
|
|
@ -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"`
|
||||
|
|
|
|||
|
|
@ -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":
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue