Add nil checks

This commit is contained in:
David Newhall II 2019-08-25 16:38:29 -07:00
parent 8317e9d2ef
commit 406a1383b9
4 changed files with 15 additions and 0 deletions

View File

@ -10,6 +10,9 @@ import (
// UAPPoints generates Wireless-Access-Point datapoints for InfluxDB. // UAPPoints generates Wireless-Access-Point datapoints for InfluxDB.
// These points can be passed directly to influx. // These points can be passed directly to influx.
func UAPPoints(u *unifi.UAP, now time.Time) ([]*influx.Point, error) { func UAPPoints(u *unifi.UAP, now time.Time) ([]*influx.Point, error) {
if u.Stat.Ap == nil {
u.Stat.Ap = &unifi.Ap{}
}
tags := map[string]string{ tags := map[string]string{
"id": u.ID, "id": u.ID,
"mac": u.Mac, "mac": u.Mac,

View File

@ -10,6 +10,12 @@ import (
// UDMPoints generates Unifi Gateway datapoints for InfluxDB. // UDMPoints generates Unifi Gateway datapoints for InfluxDB.
// These points can be passed directly to influx. // These points can be passed directly to influx.
func UDMPoints(u *unifi.UDM, now time.Time) ([]*influx.Point, error) { func UDMPoints(u *unifi.UDM, now time.Time) ([]*influx.Point, error) {
if u.Stat.Sw == nil {
u.Stat.Sw = &unifi.Sw{}
}
if u.Stat.Gw == nil {
u.Stat.Gw = &unifi.Gw{}
}
tags := map[string]string{ tags := map[string]string{
"id": u.ID, "id": u.ID,
"mac": u.Mac, "mac": u.Mac,

View File

@ -11,6 +11,9 @@ import (
// USGPoints generates Unifi Gateway datapoints for InfluxDB. // USGPoints generates Unifi Gateway datapoints for InfluxDB.
// These points can be passed directly to influx. // These points can be passed directly to influx.
func USGPoints(u *unifi.USG, now time.Time) ([]*influx.Point, error) { func USGPoints(u *unifi.USG, now time.Time) ([]*influx.Point, error) {
if u.Stat.Gw == nil {
u.Stat.Gw = &unifi.Gw{}
}
tags := map[string]string{ tags := map[string]string{
"id": u.ID, "id": u.ID,
"mac": u.Mac, "mac": u.Mac,

View File

@ -10,6 +10,9 @@ import (
// USWPoints generates Unifi Switch datapoints for InfluxDB. // USWPoints generates Unifi Switch datapoints for InfluxDB.
// These points can be passed directly to influx. // These points can be passed directly to influx.
func USWPoints(u *unifi.USW, now time.Time) ([]*influx.Point, error) { func USWPoints(u *unifi.USW, now time.Time) ([]*influx.Point, error) {
if u.Stat.Sw == nil {
u.Stat.Sw = &unifi.Sw{}
}
tags := map[string]string{ tags := map[string]string{
"id": u.ID, "id": u.ID,
"mac": u.Mac, "mac": u.Mac,