Fix pointer mismatch.

This commit is contained in:
DN2 2018-04-28 01:42:44 -07:00
parent 3b3bbeb9d2
commit 9d619f3ff5
4 changed files with 25 additions and 13 deletions

View File

@ -8,7 +8,8 @@ import (
) )
// Points generates a client's datapoints for InfluxDB. // Points generates a client's datapoints for InfluxDB.
func (u UCL) Points() (points []*influx.Point, err error) { func (u UCL) Points() ([]*influx.Point, error) {
var points []*influx.Point
if u.Name == "" && u.Hostname != "" { if u.Name == "" && u.Hostname != "" {
u.Name = u.Hostname u.Name = u.Hostname
} else if u.Hostname == "" && u.Name != "" { } else if u.Hostname == "" && u.Name != "" {
@ -95,6 +96,9 @@ func (u UCL) Points() (points []*influx.Point, err error) {
"wired-tx_bytes-r": u.WiredTxBytesR, "wired-tx_bytes-r": u.WiredTxBytesR,
"wired-tx_packets": u.WiredTxPackets, "wired-tx_packets": u.WiredTxPackets,
} }
points[0], err = influx.NewPoint("clients", tags, fields, time.Now()) pt, err := influx.NewPoint("clients", tags, fields, time.Now())
return if err == nil {
points = append(points, pt)
}
return points, err
} }

View File

@ -34,7 +34,7 @@ func (c *AuthedReq) GetUnifiClients() ([]UCL, error) {
return nil, err return nil, err
} else if body, err := ioutil.ReadAll(resp.Body); err != nil { } else if body, err := ioutil.ReadAll(resp.Body); err != nil {
return nil, err return nil, err
} else if err = json.Unmarshal(body, response); err != nil { } else if err = json.Unmarshal(body, &response); err != nil {
return nil, err return nil, err
} else if err = resp.Body.Close(); err != nil { } else if err = resp.Body.Close(); err != nil {
log.Println("resp.Body.Close():", err) // Not fatal? Just log it. log.Println("resp.Body.Close():", err) // Not fatal? Just log it.
@ -95,17 +95,17 @@ func (c *AuthedReq) GetUnifiDevices() ([]USG, []USW, []UAP, error) {
// Unmarshal again into the correct type.. // Unmarshal again into the correct type..
switch assetType { switch assetType {
case "uap": case "uap":
if err := json.Unmarshal(r, uap); err != nil { if err := json.Unmarshal(r, &uap); err != nil {
return nil, nil, nil, err return nil, nil, nil, err
} }
uaps = append(uaps, uap) uaps = append(uaps, uap)
case "ugw", "usg": // in case they ever fix the name in the api. case "ugw", "usg": // in case they ever fix the name in the api.
if err := json.Unmarshal(r, usg); err != nil { if err := json.Unmarshal(r, &usg); err != nil {
return nil, nil, nil, err return nil, nil, nil, err
} }
usgs = append(usgs, usg) usgs = append(usgs, usg)
case "usw": case "usw":
if err := json.Unmarshal(r, usw); err != nil { if err := json.Unmarshal(r, &usw); err != nil {
return nil, nil, nil, err return nil, nil, nil, err
} }
usws = append(usws, usw) usws = append(usws, usw)

View File

@ -8,7 +8,8 @@ import (
) )
// Points generates a device's datapoints for InfluxDB. // Points generates a device's datapoints for InfluxDB.
func (u USG) Points() (points []*influx.Point, err error) { func (u USG) Points() ([]*influx.Point, error) {
var points []*influx.Point
tags := map[string]string{ tags := map[string]string{
"id": u.ID, "id": u.ID,
"mac": u.Mac, "mac": u.Mac,
@ -117,6 +118,9 @@ func (u USG) Points() (points []*influx.Point, err error) {
"wan-tx_bytes": u.Stat.WanTxBytes, "wan-tx_bytes": u.Stat.WanTxBytes,
"wan-tx_packets": u.Stat.WanTxPackets, "wan-tx_packets": u.Stat.WanTxPackets,
} }
points[0], err = influx.NewPoint("usg", tags, fields, time.Now()) pt, err := influx.NewPoint("usg", tags, fields, time.Now())
return if err == nil {
points = append(points, pt)
}
return points, err
} }

View File

@ -8,7 +8,8 @@ import (
) )
// Points generates a device's datapoints for InfluxDB. // Points generates a device's datapoints for InfluxDB.
func (u USW) Points() (points []*influx.Point, err error) { func (u USW) Points() ([]*influx.Point, error) {
var points []*influx.Point
tags := map[string]string{ tags := map[string]string{
"id": u.ID, "id": u.ID,
"mac": u.Mac, "mac": u.Mac,
@ -109,6 +110,9 @@ func (u USW) Points() (points []*influx.Point, err error) {
"stat_tx_retries": u.Stat.TxRetries, "stat_tx_retries": u.Stat.TxRetries,
// Add the port stats too. // Add the port stats too.
} }
points[0], err = influx.NewPoint("usw", tags, fields, time.Now()) pt, err := influx.NewPoint("usw", tags, fields, time.Now())
return if err == nil {
points = append(points, pt)
}
return points, err
} }