Merge pull request #7 from golift/dn2_cleaanup

Convert all the bools to FlexBool.
This commit is contained in:
David Newhall II 2019-04-17 02:42:31 -07:00 committed by GitHub
commit 65f9909648
9 changed files with 442 additions and 442 deletions

View File

@ -44,6 +44,7 @@ func main() {
log.Fatalln("Error:", err) log.Fatalln("Error:", err)
} }
log.Println(len(sites), "Unifi Sites Found: ", sites)
log.Println(len(clients.UCLs), "Clients connected:") log.Println(len(clients.UCLs), "Clients connected:")
for i, client := range clients.UCLs { for i, client := range clients.UCLs {
log.Println(i+1, client.ID, client.Hostname, client.IP, client.Name, client.LastSeen) log.Println(i+1, client.ID, client.Hostname, client.IP, client.Name, client.LastSeen)

View File

@ -42,17 +42,17 @@ func (c UCL) Points() ([]*influx.Point, error) {
"dev_cat": strconv.Itoa(c.DevCat), "dev_cat": strconv.Itoa(c.DevCat),
"dev_id": strconv.Itoa(c.DevID), "dev_id": strconv.Itoa(c.DevID),
"dev_family": strconv.Itoa(c.DevFamily), "dev_family": strconv.Itoa(c.DevFamily),
"authorized": strconv.FormatBool(c.Authorized), "authorized": c.Authorized.Txt,
"is_11r": strconv.FormatBool(c.Is11R), "is_11r": c.Is11R.Txt,
"is_wired": strconv.FormatBool(c.IsWired), "is_wired": c.IsWired.Txt,
"is_guest": strconv.FormatBool(c.IsGuest), "is_guest": c.IsGuest.Txt,
"is_guest_by_uap": strconv.FormatBool(c.IsGuestByUAP), "is_guest_by_uap": c.IsGuestByUAP.Txt,
"is_guest_by_ugw": strconv.FormatBool(c.IsGuestByUGW), "is_guest_by_ugw": c.IsGuestByUGW.Txt,
"is_guest_by_usw": strconv.FormatBool(c.IsGuestByUSW), "is_guest_by_usw": c.IsGuestByUSW.Txt,
"noted": strconv.FormatBool(c.Noted), "noted": c.Noted.Txt,
"powersave_enabled": strconv.FormatBool(c.PowersaveEnabled), "powersave_enabled": c.PowersaveEnabled.Txt,
"qos_policy_applied": strconv.FormatBool(c.QosPolicyApplied), "qos_policy_applied": c.QosPolicyApplied.Txt,
"use_fixedip": strconv.FormatBool(c.UseFixedIP), "use_fixedip": c.UseFixedIP.Txt,
"channel": strconv.Itoa(c.Channel), "channel": strconv.Itoa(c.Channel),
"vlan": strconv.Itoa(c.Vlan), "vlan": strconv.Itoa(c.Vlan),
} }

View File

@ -2,26 +2,26 @@ package unifi
// UCL defines all the data a connected-network client contains. // UCL defines all the data a connected-network client contains.
type UCL struct { type UCL struct {
ID string `json:"_id"` ID string `json:"_id"`
IsGuestByUAP bool `json:"_is_guest_by_uap"` IsGuestByUAP FlexBool `json:"_is_guest_by_uap"`
IsGuestByUGW bool `json:"_is_guest_by_ugw"` IsGuestByUGW FlexBool `json:"_is_guest_by_ugw"`
IsGuestByUSW bool `json:"_is_guest_by_usw"` IsGuestByUSW FlexBool `json:"_is_guest_by_usw"`
LastSeenByUAP int64 `json:"_last_seen_by_uap"` LastSeenByUAP int64 `json:"_last_seen_by_uap"`
LastSeenByUGW int64 `json:"_last_seen_by_ugw"` LastSeenByUGW int64 `json:"_last_seen_by_ugw"`
LastSeenByUSW int64 `json:"_last_seen_by_usw"` LastSeenByUSW int64 `json:"_last_seen_by_usw"`
UptimeByUAP int64 `json:"_uptime_by_uap"` UptimeByUAP int64 `json:"_uptime_by_uap"`
UptimeByUGW int64 `json:"_uptime_by_ugw"` UptimeByUGW int64 `json:"_uptime_by_ugw"`
UptimeByUSW int64 `json:"_uptime_by_usw"` UptimeByUSW int64 `json:"_uptime_by_usw"`
ApMac string `json:"ap_mac"` ApMac string `json:"ap_mac"`
AssocTime int64 `json:"assoc_time"` AssocTime int64 `json:"assoc_time"`
Authorized bool `json:"authorized"` Authorized FlexBool `json:"authorized"`
Bssid string `json:"bssid"` Bssid string `json:"bssid"`
BytesR int64 `json:"bytes-r"` BytesR int64 `json:"bytes-r"`
Ccq int64 `json:"ccq"` Ccq int64 `json:"ccq"`
Channel int `json:"channel"` Channel int `json:"channel"`
DevCat int `json:"dev_cat"` DevCat int `json:"dev_cat"`
DevFamily int `json:"dev_family"` DevFamily int `json:"dev_family"`
DevID int `json:"dev_id"` DevID int `json:"dev_id"`
DpiStats struct { DpiStats struct {
App int64 App int64
Cat int64 Cat int64
@ -30,59 +30,59 @@ type UCL struct {
TxBytes int64 TxBytes int64
TxPackets int64 TxPackets int64
} `json:"dpi_stats"` } `json:"dpi_stats"`
DpiStatsLastUpdated int64 `json:"dpi_stats_last_updated"` DpiStatsLastUpdated int64 `json:"dpi_stats_last_updated"`
Essid string `json:"essid"` Essid string `json:"essid"`
FirstSeen int64 `json:"first_seen"` FirstSeen int64 `json:"first_seen"`
FixedIP string `json:"fixed_ip"` FixedIP string `json:"fixed_ip"`
Hostname string `json:"hostname"` Hostname string `json:"hostname"`
GwMac string `json:"gw_mac"` GwMac string `json:"gw_mac"`
IdleTime int64 `json:"idle_time"` IdleTime int64 `json:"idle_time"`
IP string `json:"ip"` IP string `json:"ip"`
Is11R bool `json:"is_11r"` Is11R FlexBool `json:"is_11r"`
IsGuest bool `json:"is_guest"` IsGuest FlexBool `json:"is_guest"`
IsWired bool `json:"is_wired"` IsWired FlexBool `json:"is_wired"`
LastSeen int64 `json:"last_seen"` LastSeen int64 `json:"last_seen"`
LatestAssocTime int64 `json:"latest_assoc_time"` LatestAssocTime int64 `json:"latest_assoc_time"`
Mac string `json:"mac"` Mac string `json:"mac"`
Name string `json:"name"` Name string `json:"name"`
Network string `json:"network"` Network string `json:"network"`
NetworkID string `json:"network_id"` NetworkID string `json:"network_id"`
Noise int64 `json:"noise"` Noise int64 `json:"noise"`
Note string `json:"note"` Note string `json:"note"`
Noted bool `json:"noted"` Noted FlexBool `json:"noted"`
OsClass int `json:"os_class"` OsClass int `json:"os_class"`
OsName int `json:"os_name"` OsName int `json:"os_name"`
Oui string `json:"oui"` Oui string `json:"oui"`
PowersaveEnabled bool `json:"powersave_enabled"` PowersaveEnabled FlexBool `json:"powersave_enabled"`
QosPolicyApplied bool `json:"qos_policy_applied"` QosPolicyApplied FlexBool `json:"qos_policy_applied"`
Radio string `json:"radio"` Radio string `json:"radio"`
RadioName string `json:"radio_name"` RadioName string `json:"radio_name"`
RadioProto string `json:"radio_proto"` RadioProto string `json:"radio_proto"`
RoamCount int64 `json:"roam_count"` RoamCount int64 `json:"roam_count"`
Rssi int64 `json:"rssi"` Rssi int64 `json:"rssi"`
RxBytes int64 `json:"rx_bytes"` RxBytes int64 `json:"rx_bytes"`
RxBytesR int64 `json:"rx_bytes-r"` RxBytesR int64 `json:"rx_bytes-r"`
RxPackets int64 `json:"rx_packets"` RxPackets int64 `json:"rx_packets"`
RxRate int64 `json:"rx_rate"` RxRate int64 `json:"rx_rate"`
Signal int64 `json:"signal"` Signal int64 `json:"signal"`
SiteID string `json:"site_id"` SiteID string `json:"site_id"`
SwDepth int `json:"sw_depth"` SwDepth int `json:"sw_depth"`
SwMac string `json:"sw_mac"` SwMac string `json:"sw_mac"`
SwPort int `json:"sw_port"` SwPort int `json:"sw_port"`
TxBytes int64 `json:"tx_bytes"` TxBytes int64 `json:"tx_bytes"`
TxBytesR int64 `json:"tx_bytes-r"` TxBytesR int64 `json:"tx_bytes-r"`
TxPackets int64 `json:"tx_packets"` TxPackets int64 `json:"tx_packets"`
TxPower int64 `json:"tx_power"` TxPower int64 `json:"tx_power"`
TxRate int64 `json:"tx_rate"` TxRate int64 `json:"tx_rate"`
Uptime int64 `json:"uptime"` Uptime int64 `json:"uptime"`
UserID string `json:"user_id"` UserID string `json:"user_id"`
UserGroupID string `json:"usergroup_id"` UserGroupID string `json:"usergroup_id"`
UseFixedIP bool `json:"use_fixedip"` UseFixedIP FlexBool `json:"use_fixedip"`
Vlan int `json:"vlan"` Vlan int `json:"vlan"`
WiredRxBytes int64 `json:"wired-rx_bytes"` WiredRxBytes int64 `json:"wired-rx_bytes"`
WiredRxBytesR int64 `json:"wired-rx_bytes-r"` WiredRxBytesR int64 `json:"wired-rx_bytes-r"`
WiredRxPackets int64 `json:"wired-rx_packets"` WiredRxPackets int64 `json:"wired-rx_packets"`
WiredTxBytes int64 `json:"wired-tx_bytes"` WiredTxBytes int64 `json:"wired-tx_bytes"`
WiredTxBytesR int64 `json:"wired-tx_bytes-r"` WiredTxBytesR int64 `json:"wired-tx_bytes-r"`
WiredTxPackets int64 `json:"wired-tx_packets"` WiredTxPackets int64 `json:"wired-tx_packets"`
} }

View File

@ -21,7 +21,7 @@ func (u UAP) Points() ([]*influx.Point, error) {
"device_ap": u.Stat.Ap, "device_ap": u.Stat.Ap,
"site_id": u.SiteID, "site_id": u.SiteID,
"name": u.Name, "name": u.Name,
"adopted": strconv.FormatBool(u.Adopted), "adopted": u.Adopted.Txt,
"bandsteering_mode": u.BandsteeringMode, "bandsteering_mode": u.BandsteeringMode,
"board_rev": strconv.Itoa(u.BoardRev), "board_rev": strconv.Itoa(u.BoardRev),
"cfgversion": u.Cfgversion, "cfgversion": u.Cfgversion,
@ -29,27 +29,27 @@ func (u UAP) Points() ([]*influx.Point, error) {
"config_network_type": u.ConfigNetwork.Type, "config_network_type": u.ConfigNetwork.Type,
"connect_request_ip": u.ConnectRequestIP, "connect_request_ip": u.ConnectRequestIP,
"connect_request_port": u.ConnectRequestPort, "connect_request_port": u.ConnectRequestPort,
"default": strconv.FormatBool(u.Default), "default": u.Default.Txt,
"device_id": u.DeviceID, "device_id": u.DeviceID,
"discovered_via": u.DiscoveredVia, "discovered_via": u.DiscoveredVia,
"fw_caps": strconv.Itoa(u.FwCaps), "fw_caps": strconv.Itoa(u.FwCaps),
"guest-num_sta": strconv.Itoa(u.GuestNumSta), "guest-num_sta": strconv.Itoa(u.GuestNumSta),
"guest_token": u.GuestToken, "guest_token": u.GuestToken,
"has_eth1": strconv.FormatBool(u.HasEth1), "has_eth1": u.HasEth1.Txt,
"has_speaker": strconv.FormatBool(u.HasSpeaker), "has_speaker": u.HasSpeaker.Txt,
"inform_ip": u.InformIP, "inform_ip": u.InformIP,
"isolated": strconv.FormatBool(u.Isolated), "isolated": u.Isolated.Txt,
"last_uplink_mac": u.LastUplink.UplinkMac, "last_uplink_mac": u.LastUplink.UplinkMac,
"last_uplink_remote_port": strconv.Itoa(u.LastUplink.UplinkRemotePort), "last_uplink_remote_port": strconv.Itoa(u.LastUplink.UplinkRemotePort),
"known_cfgversion": u.KnownCfgversion, "known_cfgversion": u.KnownCfgversion,
"led_override": u.LedOverride, "led_override": u.LedOverride,
"locating": strconv.FormatBool(u.Locating), "locating": u.Locating.Txt,
"model": u.Model, "model": u.Model,
"outdoor_mode_override": u.OutdoorModeOverride, "outdoor_mode_override": u.OutdoorModeOverride,
"serial": u.Serial, "serial": u.Serial,
"type": u.Type, "type": u.Type,
"version_incompatible": strconv.FormatBool(u.VersionIncompatible), "version_incompatible": u.VersionIncompatible.Txt,
"vwireEnabled": strconv.FormatBool(u.VwireEnabled), "vwireEnabled": u.VwireEnabled.Txt,
"wifi_caps": strconv.Itoa(u.WifiCaps), "wifi_caps": strconv.Itoa(u.WifiCaps),
} }
fields := map[string]interface{}{ fields := map[string]interface{}{
@ -65,11 +65,11 @@ func (u UAP) Points() ([]*influx.Point, error) {
"uptime": u.Uptime.Val, "uptime": u.Uptime.Val,
"considered_lost_at": u.ConsideredLostAt, "considered_lost_at": u.ConsideredLostAt,
"next_heartbeat_at": u.NextHeartbeatAt, "next_heartbeat_at": u.NextHeartbeatAt,
"scanning": u.Scanning, "scanning": u.Scanning.Txt,
"spectrum_scanning": u.SpectrumScanning, "spectrum_scanning": u.SpectrumScanning,
"roll_upgrade": u.Rollupgrade, "roll_upgrade": u.Rollupgrade.Txt,
"state": u.State, "state": u.State,
"upgradable": u.Upgradable, "upgradable": u.Upgradable.Txt,
"user-num_sta": u.UserNumSta, "user-num_sta": u.UserNumSta,
"version": u.Version, "version": u.Version,
"loadavg_1": u.SysStats.Loadavg1, "loadavg_1": u.SysStats.Loadavg1,
@ -187,12 +187,12 @@ func (u UAP) Points() ([]*influx.Point, error) {
fields := map[string]interface{}{ fields := map[string]interface{}{
"builtin_ant_gain": p.BuiltinAntGain, "builtin_ant_gain": p.BuiltinAntGain,
"current_antenna_gain": p.CurrentAntennaGain, "current_antenna_gain": p.CurrentAntennaGain,
"has_dfs": p.HasDfs, "has_dfs": p.HasDfs.Txt,
"has_fccdfs": p.HasFccdfs, "has_fccdfs": p.HasFccdfs.Txt,
"ht": p.Ht, "ht": p.Ht,
"is_11ac": p.Is11Ac, "is_11ac": p.Is11Ac.Txt,
"max_txpower": p.MaxTxpower, "max_txpower": p.MaxTxpower,
"min_rssi_enabled": p.MinRssiEnabled, "min_rssi_enabled": p.MinRssiEnabled.Txt,
"min_txpower": p.MinTxpower, "min_txpower": p.MinTxpower,
"nss": p.Nss, "nss": p.Nss,
"radio_caps": p.RadioCaps, "radio_caps": p.RadioCaps,
@ -234,8 +234,8 @@ func (u UAP) Points() ([]*influx.Point, error) {
fields["ccq"] = s.Ccq fields["ccq"] = s.Ccq
fields["essid"] = s.Essid fields["essid"] = s.Essid
fields["extchannel"] = s.Extchannel fields["extchannel"] = s.Extchannel
fields["is_guest"] = s.IsGuest fields["is_guest"] = s.IsGuest.Txt
fields["is_wep"] = s.IsWep fields["is_wep"] = s.IsWep.Txt
fields["mac_filter_rejections"] = s.MacFilterRejections fields["mac_filter_rejections"] = s.MacFilterRejections
fields["map_id"] = s.MapID fields["map_id"] = s.MapID
fields["vap_rx_bytes"] = s.RxBytes fields["vap_rx_bytes"] = s.RxBytes

View File

@ -7,11 +7,11 @@ type UAP struct {
No ones feelings will be hurt if you want to break this No ones feelings will be hurt if you want to break this
up into multiple structs, and/or make it better in general. up into multiple structs, and/or make it better in general.
*/ */
ID string `json:"_id"` ID string `json:"_id"`
UUptime float64 `json:"_uptime"` UUptime float64 `json:"_uptime"`
AdoptIP string `json:"adopt_ip,omitempty"` AdoptIP string `json:"adopt_ip,omitempty"`
AdoptURL string `json:"adopt_url,omitempty"` AdoptURL string `json:"adopt_url,omitempty"`
Adopted bool `json:"adopted"` Adopted FlexBool `json:"adopted"`
AntennaTable []struct { AntennaTable []struct {
ID float64 `json:"id"` ID float64 `json:"id"`
Name string `json:"name"` Name string `json:"name"`
@ -32,7 +32,7 @@ type UAP struct {
ConnectRequestPort string `json:"connect_request_port"` ConnectRequestPort string `json:"connect_request_port"`
ConsideredLostAt float64 `json:"considered_lost_at"` ConsideredLostAt float64 `json:"considered_lost_at"`
CountrycodeTable []float64 `json:"countrycode_table"` CountrycodeTable []float64 `json:"countrycode_table"`
Default bool `json:"default,omitempty"` Default FlexBool `json:"default,omitempty"`
DeviceID string `json:"device_id"` DeviceID string `json:"device_id"`
DiscoveredVia string `json:"discovered_via,omitempty"` DiscoveredVia string `json:"discovered_via,omitempty"`
DownlinkTable []interface{} `json:"downlink_table"` DownlinkTable []interface{} `json:"downlink_table"`
@ -41,52 +41,52 @@ type UAP struct {
Name string `json:"name"` Name string `json:"name"`
NumPort float64 `json:"num_port"` NumPort float64 `json:"num_port"`
} `json:"ethernet_table"` } `json:"ethernet_table"`
FwCaps int `json:"fw_caps"` FwCaps int `json:"fw_caps"`
GuestNumSta int `json:"guest-num_sta"` GuestNumSta int `json:"guest-num_sta"`
GuestToken string `json:"guest_token"` GuestToken string `json:"guest_token"`
HasEth1 bool `json:"has_eth1"` HasEth1 FlexBool `json:"has_eth1"`
HasSpeaker bool `json:"has_speaker"` HasSpeaker FlexBool `json:"has_speaker"`
InformIP string `json:"inform_ip"` InformIP string `json:"inform_ip"`
InformURL string `json:"inform_url"` InformURL string `json:"inform_url"`
IP string `json:"ip"` IP string `json:"ip"`
Isolated bool `json:"isolated"` Isolated FlexBool `json:"isolated"`
KnownCfgversion string `json:"known_cfgversion"` KnownCfgversion string `json:"known_cfgversion"`
LastSeen float64 `json:"last_seen"` LastSeen float64 `json:"last_seen"`
LastUplink struct { LastUplink struct {
UplinkMac string `json:"uplink_mac"` UplinkMac string `json:"uplink_mac"`
UplinkRemotePort int `json:"uplink_remote_port"` UplinkRemotePort int `json:"uplink_remote_port"`
} `json:"last_uplink"` } `json:"last_uplink"`
LedOverride string `json:"led_override"` LedOverride string `json:"led_override"`
Locating bool `json:"locating"` Locating FlexBool `json:"locating"`
Mac string `json:"mac"` Mac string `json:"mac"`
Model string `json:"model"` Model string `json:"model"`
Name string `json:"name"` Name string `json:"name"`
NextHeartbeatAt float64 `json:"next_heartbeat_at"` NextHeartbeatAt float64 `json:"next_heartbeat_at"`
NumSta float64 `json:"num_sta"` NumSta float64 `json:"num_sta"`
OutdoorModeOverride string `json:"outdoor_mode_override"` OutdoorModeOverride string `json:"outdoor_mode_override"`
PortTable []struct { PortTable []struct {
AggregatedBy bool `json:"aggregated_by"` AggregatedBy FlexBool `json:"aggregated_by"`
AttrNoEdit bool `json:"attr_no_edit,omitempty"` AttrNoEdit FlexBool `json:"attr_no_edit,omitempty"`
Autoneg bool `json:"autoneg"` Autoneg FlexBool `json:"autoneg"`
BytesR float64 `json:"bytes-r"` BytesR float64 `json:"bytes-r"`
Enable bool `json:"enable"` Enable FlexBool `json:"enable"`
FlowctrlRx bool `json:"flowctrl_rx"` FlowctrlRx FlexBool `json:"flowctrl_rx"`
FlowctrlTx bool `json:"flowctrl_tx"` FlowctrlTx FlexBool `json:"flowctrl_tx"`
FullDuplex bool `json:"full_duplex"` FullDuplex FlexBool `json:"full_duplex"`
IsUplink bool `json:"is_uplink"` IsUplink FlexBool `json:"is_uplink"`
Jumbo bool `json:"jumbo"` Jumbo FlexBool `json:"jumbo"`
MacTable []struct { MacTable []struct {
Age float64 `json:"age"` Age float64 `json:"age"`
Mac string `json:"mac"` Mac string `json:"mac"`
Static bool `json:"static"` Static FlexBool `json:"static"`
Uptime float64 `json:"uptime"` Uptime float64 `json:"uptime"`
Vlan float64 `json:"vlan"` Vlan float64 `json:"vlan"`
} `json:"mac_table"` } `json:"mac_table"`
Masked bool `json:"masked"` Masked FlexBool `json:"masked"`
Media string `json:"media"` Media string `json:"media"`
Name string `json:"name"` Name string `json:"name"`
OpMode string `json:"op_mode"` OpMode string `json:"op_mode"`
PoeCaps float64 `json:"poe_caps"` PoeCaps float64 `json:"poe_caps"`
PortDelta struct { PortDelta struct {
RxBytes float64 `json:"rx_bytes"` RxBytes float64 `json:"rx_bytes"`
RxPackets float64 `json:"rx_packets"` RxPackets float64 `json:"rx_packets"`
@ -94,47 +94,47 @@ type UAP struct {
TxBytes float64 `json:"tx_bytes"` TxBytes float64 `json:"tx_bytes"`
TxPackets float64 `json:"tx_packets"` TxPackets float64 `json:"tx_packets"`
} `json:"port_delta"` } `json:"port_delta"`
PortIdx float64 `json:"port_idx"` PortIdx float64 `json:"port_idx"`
PortPoe bool `json:"port_poe"` PortPoe FlexBool `json:"port_poe"`
PortconfID string `json:"portconf_id"` PortconfID string `json:"portconf_id"`
RxBroadcast float64 `json:"rx_broadcast"` RxBroadcast float64 `json:"rx_broadcast"`
RxBytes float64 `json:"rx_bytes"` RxBytes float64 `json:"rx_bytes"`
RxBytesR float64 `json:"rx_bytes-r"` RxBytesR float64 `json:"rx_bytes-r"`
RxDropped float64 `json:"rx_dropped"` RxDropped float64 `json:"rx_dropped"`
RxErrors float64 `json:"rx_errors"` RxErrors float64 `json:"rx_errors"`
RxMulticast float64 `json:"rx_multicast"` RxMulticast float64 `json:"rx_multicast"`
RxPackets float64 `json:"rx_packets"` RxPackets float64 `json:"rx_packets"`
Speed float64 `json:"speed"` Speed float64 `json:"speed"`
StpPathcost float64 `json:"stp_pathcost"` StpPathcost float64 `json:"stp_pathcost"`
StpState string `json:"stp_state"` StpState string `json:"stp_state"`
TxBroadcast float64 `json:"tx_broadcast"` TxBroadcast float64 `json:"tx_broadcast"`
TxBytes float64 `json:"tx_bytes"` TxBytes float64 `json:"tx_bytes"`
TxBytesR float64 `json:"tx_bytes-r"` TxBytesR float64 `json:"tx_bytes-r"`
TxDropped float64 `json:"tx_dropped"` TxDropped float64 `json:"tx_dropped"`
TxErrors float64 `json:"tx_errors"` TxErrors float64 `json:"tx_errors"`
TxMulticast float64 `json:"tx_multicast"` TxMulticast float64 `json:"tx_multicast"`
TxPackets float64 `json:"tx_packets"` TxPackets float64 `json:"tx_packets"`
Up bool `json:"up"` Up FlexBool `json:"up"`
} `json:"port_table"` } `json:"port_table"`
RadioTable []struct { RadioTable []struct {
BuiltinAntGain float64 `json:"builtin_ant_gain"` BuiltinAntGain float64 `json:"builtin_ant_gain"`
BuiltinAntenna bool `json:"builtin_antenna"` BuiltinAntenna FlexBool `json:"builtin_antenna"`
Channel FlexInt `json:"channel"` Channel FlexInt `json:"channel"`
CurrentAntennaGain float64 `json:"current_antenna_gain"` CurrentAntennaGain float64 `json:"current_antenna_gain"`
Ht string `json:"ht"` Ht string `json:"ht"`
MaxTxpower float64 `json:"max_txpower"` MaxTxpower float64 `json:"max_txpower"`
MinRssiEnabled bool `json:"min_rssi_enabled"` MinRssiEnabled FlexBool `json:"min_rssi_enabled"`
MinTxpower float64 `json:"min_txpower"` MinTxpower float64 `json:"min_txpower"`
Name string `json:"name"` Name string `json:"name"`
Nss float64 `json:"nss"` Nss float64 `json:"nss"`
Radio string `json:"radio"` Radio string `json:"radio"`
RadioCaps float64 `json:"radio_caps"` RadioCaps float64 `json:"radio_caps"`
TxPower FlexInt `json:"tx_power"` TxPower FlexInt `json:"tx_power"`
TxPowerMode string `json:"tx_power_mode"` TxPowerMode string `json:"tx_power_mode"`
WlangroupID string `json:"wlangroup_id"` WlangroupID string `json:"wlangroup_id"`
HasDfs bool `json:"has_dfs,omitempty"` HasDfs FlexBool `json:"has_dfs,omitempty"`
HasFccdfs bool `json:"has_fccdfs,omitempty"` HasFccdfs FlexBool `json:"has_fccdfs,omitempty"`
Is11Ac bool `json:"is_11ac,omitempty"` Is11Ac FlexBool `json:"is_11ac,omitempty"`
} `json:"radio_table"` } `json:"radio_table"`
RadioTableStats []struct { RadioTableStats []struct {
AstBeXmit float64 `json:"ast_be_xmit"` AstBeXmit float64 `json:"ast_be_xmit"`
@ -156,14 +156,14 @@ type UAP struct {
TxRetries float64 `json:"tx_retries"` TxRetries float64 `json:"tx_retries"`
UserNumSta float64 `json:"user-num_sta"` UserNumSta float64 `json:"user-num_sta"`
} `json:"radio_table_stats"` } `json:"radio_table_stats"`
Rollupgrade bool `json:"rollupgrade"` Rollupgrade FlexBool `json:"rollupgrade"`
RxBytes float64 `json:"rx_bytes"` RxBytes float64 `json:"rx_bytes"`
RxBytesD float64 `json:"rx_bytes-d"` RxBytesD float64 `json:"rx_bytes-d"`
ScanRadioTable []interface{} `json:"scan_radio_table"` ScanRadioTable []interface{} `json:"scan_radio_table"`
Scanning bool `json:"scanning"` Scanning FlexBool `json:"scanning"`
Serial string `json:"serial"` Serial string `json:"serial"`
SiteID string `json:"site_id"` SiteID string `json:"site_id"`
SpectrumScanning bool `json:"spectrum_scanning"` SpectrumScanning FlexBool `json:"spectrum_scanning"`
SSHSessionTable []interface{} `json:"ssh_session_table"` SSHSessionTable []interface{} `json:"ssh_session_table"`
Stat struct { Stat struct {
Ap string `json:"ap"` Ap string `json:"ap"`
@ -274,82 +274,82 @@ type UAP struct {
Mem float64 `json:"mem,string"` Mem float64 `json:"mem,string"`
Uptime float64 `json:"uptime,string"` Uptime float64 `json:"uptime,string"`
} `json:"system-stats"` } `json:"system-stats"`
TxBytes float64 `json:"tx_bytes"` TxBytes float64 `json:"tx_bytes"`
TxBytesD float64 `json:"tx_bytes-d"` TxBytesD float64 `json:"tx_bytes-d"`
Type string `json:"type"` Type string `json:"type"`
Upgradable bool `json:"upgradable"` Upgradable FlexBool `json:"upgradable"`
Uplink struct { Uplink struct {
FullDuplex bool `json:"full_duplex"` FullDuplex FlexBool `json:"full_duplex"`
IP string `json:"ip"` IP string `json:"ip"`
Mac string `json:"mac"` Mac string `json:"mac"`
MaxSpeed int `json:"max_speed"` MaxSpeed int `json:"max_speed"`
MaxVlan int `json:"max_vlan"` MaxVlan int `json:"max_vlan"`
Media string `json:"media"` Media string `json:"media"`
Name string `json:"name"` Name string `json:"name"`
Netmask string `json:"netmask"` Netmask string `json:"netmask"`
NumPort int `json:"num_port"` NumPort int `json:"num_port"`
RxBytes float64 `json:"rx_bytes"` RxBytes float64 `json:"rx_bytes"`
RxBytesR float64 `json:"rx_bytes-r"` RxBytesR float64 `json:"rx_bytes-r"`
RxDropped float64 `json:"rx_dropped"` RxDropped float64 `json:"rx_dropped"`
RxErrors float64 `json:"rx_errors"` RxErrors float64 `json:"rx_errors"`
RxMulticast float64 `json:"rx_multicast"` RxMulticast float64 `json:"rx_multicast"`
RxPackets float64 `json:"rx_packets"` RxPackets float64 `json:"rx_packets"`
Speed float64 `json:"speed"` Speed float64 `json:"speed"`
TxBytes float64 `json:"tx_bytes"` TxBytes float64 `json:"tx_bytes"`
TxBytesR float64 `json:"tx_bytes-r"` TxBytesR float64 `json:"tx_bytes-r"`
TxDropped float64 `json:"tx_dropped"` TxDropped float64 `json:"tx_dropped"`
TxErrors float64 `json:"tx_errors"` TxErrors float64 `json:"tx_errors"`
TxPackets float64 `json:"tx_packets"` TxPackets float64 `json:"tx_packets"`
Type string `json:"type"` Type string `json:"type"`
Up bool `json:"up"` Up FlexBool `json:"up"`
UplinkMac string `json:"uplink_mac"` UplinkMac string `json:"uplink_mac"`
UplinkRemotePort int `json:"uplink_remote_port"` UplinkRemotePort int `json:"uplink_remote_port"`
} `json:"uplink"` } `json:"uplink"`
UplinkTable []interface{} `json:"uplink_table"` UplinkTable []interface{} `json:"uplink_table"`
Uptime FlexInt `json:"uptime"` Uptime FlexInt `json:"uptime"`
UserNumSta int `json:"user-num_sta"` UserNumSta int `json:"user-num_sta"`
VapTable []struct { VapTable []struct {
ApMac string `json:"ap_mac"` ApMac string `json:"ap_mac"`
Bssid string `json:"bssid"` Bssid string `json:"bssid"`
Ccq int `json:"ccq"` Ccq int `json:"ccq"`
Channel int `json:"channel"` Channel int `json:"channel"`
Essid string `json:"essid"` Essid string `json:"essid"`
Extchannel int `json:"extchannel"` Extchannel int `json:"extchannel"`
ID string `json:"id"` ID string `json:"id"`
IsGuest bool `json:"is_guest"` IsGuest FlexBool `json:"is_guest"`
IsWep bool `json:"is_wep"` IsWep FlexBool `json:"is_wep"`
MacFilterRejections int `json:"mac_filter_rejections"` MacFilterRejections int `json:"mac_filter_rejections"`
MapID string `json:"map_id"` MapID string `json:"map_id"`
Name string `json:"name"` Name string `json:"name"`
NumSta int `json:"num_sta"` NumSta int `json:"num_sta"`
Radio string `json:"radio"` Radio string `json:"radio"`
RadioName string `json:"radio_name"` RadioName string `json:"radio_name"`
RxBytes float64 `json:"rx_bytes"` RxBytes float64 `json:"rx_bytes"`
RxCrypts float64 `json:"rx_crypts"` RxCrypts float64 `json:"rx_crypts"`
RxDropped float64 `json:"rx_dropped"` RxDropped float64 `json:"rx_dropped"`
RxErrors float64 `json:"rx_errors"` RxErrors float64 `json:"rx_errors"`
RxFrags float64 `json:"rx_frags"` RxFrags float64 `json:"rx_frags"`
RxNwids float64 `json:"rx_nwids"` RxNwids float64 `json:"rx_nwids"`
RxPackets float64 `json:"rx_packets"` RxPackets float64 `json:"rx_packets"`
SiteID string `json:"site_id"` SiteID string `json:"site_id"`
State string `json:"state"` State string `json:"state"`
T string `json:"t"` T string `json:"t"`
TxBytes float64 `json:"tx_bytes"` TxBytes float64 `json:"tx_bytes"`
TxDropped float64 `json:"tx_dropped"` TxDropped float64 `json:"tx_dropped"`
TxErrors float64 `json:"tx_errors"` TxErrors float64 `json:"tx_errors"`
TxLatencyAvg float64 `json:"tx_latency_avg"` TxLatencyAvg float64 `json:"tx_latency_avg"`
TxLatencyMax float64 `json:"tx_latency_max"` TxLatencyMax float64 `json:"tx_latency_max"`
TxLatencyMin float64 `json:"tx_latency_min"` TxLatencyMin float64 `json:"tx_latency_min"`
TxPackets float64 `json:"tx_packets"` TxPackets float64 `json:"tx_packets"`
TxPower FlexInt `json:"tx_power"` TxPower FlexInt `json:"tx_power"`
TxRetries int `json:"tx_retries"` TxRetries int `json:"tx_retries"`
Up bool `json:"up"` Up FlexBool `json:"up"`
Usage string `json:"usage"` Usage string `json:"usage"`
WlanconfID string `json:"wlanconf_id"` WlanconfID string `json:"wlanconf_id"`
} `json:"vap_table"` } `json:"vap_table"`
Version string `json:"version"` Version string `json:"version"`
VersionIncompatible bool `json:"version_incompatible"` VersionIncompatible FlexBool `json:"version_incompatible"`
VwireEnabled bool `json:"vwireEnabled"` VwireEnabled FlexBool `json:"vwireEnabled"`
VwireTable []interface{} `json:"vwire_table"` VwireTable []interface{} `json:"vwire_table"`
VwireVapTable []struct { VwireVapTable []struct {
Bssid string `json:"bssid"` Bssid string `json:"bssid"`

View File

@ -16,7 +16,7 @@ func (u USG) Points() ([]*influx.Point, error) {
"device_type": u.Stat.O, "device_type": u.Stat.O,
"device_oid": u.Stat.Oid, "device_oid": u.Stat.Oid,
"site_id": u.SiteID, "site_id": u.SiteID,
"adopted": strconv.FormatBool(u.Adopted), "adopted": u.Adopted.Txt,
"name": u.Name, "name": u.Name,
"adopt_ip": u.AdoptIP, "adopt_ip": u.AdoptIP,
"adopt_url": u.AdoptURL, "adopt_url": u.AdoptURL,
@ -25,21 +25,21 @@ func (u USG) Points() ([]*influx.Point, error) {
"config_network_type": u.ConfigNetwork.Type, "config_network_type": u.ConfigNetwork.Type,
"connect_request_ip": u.ConnectRequestIP, "connect_request_ip": u.ConnectRequestIP,
"connect_request_port": u.ConnectRequestPort, "connect_request_port": u.ConnectRequestPort,
"default": strconv.FormatBool(u.Default), "default": u.Default.Txt,
"device_id": u.DeviceID, "device_id": u.DeviceID,
"discovered_via": u.DiscoveredVia, "discovered_via": u.DiscoveredVia,
"guest_token": u.GuestToken, "guest_token": u.GuestToken,
"inform_ip": u.InformIP, "inform_ip": u.InformIP,
"known_cfgversion": u.KnownCfgversion, "known_cfgversion": u.KnownCfgversion,
"led_override": u.LedOverride, "led_override": u.LedOverride,
"locating": strconv.FormatBool(u.Locating), "locating": u.Locating.Txt,
"model": u.Model, "model": u.Model,
"outdoor_mode_override": u.OutdoorModeOverride, "outdoor_mode_override": u.OutdoorModeOverride,
"serial": u.Serial, "serial": u.Serial,
"type": u.Type, "type": u.Type,
"version_incompatible": strconv.FormatBool(u.VersionIncompatible), "version_incompatible": u.VersionIncompatible.Txt,
"usg_caps": strconv.FormatFloat(u.UsgCaps, 'f', 6, 64), "usg_caps": strconv.FormatFloat(u.UsgCaps, 'f', 6, 64),
"speedtest-status-saved": strconv.FormatBool(u.SpeedtestStatusSaved), "speedtest-status-saved": u.SpeedtestStatusSaved.Txt,
} }
fields := map[string]interface{}{ fields := map[string]interface{}{
"ip": u.IP, "ip": u.IP,
@ -53,9 +53,9 @@ func (u USG) Points() ([]*influx.Point, error) {
"uptime": u.Uptime, "uptime": u.Uptime,
"considered_lost_at": u.ConsideredLostAt, "considered_lost_at": u.ConsideredLostAt,
"next_heartbeat_at": u.NextHeartbeatAt, "next_heartbeat_at": u.NextHeartbeatAt,
"roll_upgrade": u.Rollupgrade, "roll_upgrade": u.Rollupgrade.Txt,
"state": u.State, "state": u.State,
"upgradable": u.Upgradable, "upgradable": u.Upgradable.Txt,
"user-num_sta": u.UserNumSta, "user-num_sta": u.UserNumSta,
"version": u.Version, "version": u.Version,
"num_desktop": u.NumDesktop, "num_desktop": u.NumDesktop,
@ -74,7 +74,7 @@ func (u USG) Points() ([]*influx.Point, error) {
"config_network_wan_type": u.ConfigNetworkWan.Type, "config_network_wan_type": u.ConfigNetworkWan.Type,
"wan1_bytes-r": u.Wan1.BytesR, "wan1_bytes-r": u.Wan1.BytesR,
"wan1_enable": u.Wan1.Enable, "wan1_enable": u.Wan1.Enable,
"wan1_full_duplex": u.Wan1.FullDuplex, "wan1_full_duplex": u.Wan1.FullDuplex.Txt,
"wan1_purpose": "uplink", // because it should have a purpose. "wan1_purpose": "uplink", // because it should have a purpose.
"wan1_gateway": u.Wan1.Gateway, "wan1_gateway": u.Wan1.Gateway,
"wan1_ifname": u.Wan1.Ifname, "wan1_ifname": u.Wan1.Ifname,
@ -136,21 +136,21 @@ func (u USG) Points() ([]*influx.Point, error) {
"device_id": u.ID, "device_id": u.ID,
"device_mac": u.Mac, "device_mac": u.Mac,
"name": p.Name, "name": p.Name,
"dhcpd_dns_enabled": strconv.FormatBool(p.DhcpdDNSEnabled), "dhcpd_dns_enabled": p.DhcpdDNSEnabled.Txt,
"dhcpd_enabled": strconv.FormatBool(p.DhcpdEnabled), "dhcpd_enabled": p.DhcpdEnabled.Txt,
"dhcpd_ntp_enabled": strconv.FormatBool(p.DhcpdNtpEnabled), "dhcpd_ntp_enabled": p.DhcpdNtpEnabled.Txt,
"dhcpd_time_offset_enabled": strconv.FormatBool(p.DhcpdTimeOffsetEnabled), "dhcpd_time_offset_enabled": p.DhcpdTimeOffsetEnabled.Txt,
"dhcp_relay_enabledy": strconv.FormatBool(p.DhcpRelayEnabled), "dhcp_relay_enabledy": p.DhcpRelayEnabled.Txt,
"dhcpd_gateway_enabled": strconv.FormatBool(p.DhcpdGatewayEnabled), "dhcpd_gateway_enabled": p.DhcpdGatewayEnabled.Txt,
"dhcpd_wins_enabled": strconv.FormatBool(p.DhcpdWinsEnabled), "dhcpd_wins_enabled": p.DhcpdWinsEnabled.Txt,
"dhcpguard_enabled": strconv.FormatBool(p.DhcpguardEnabled), "dhcpguard_enabled": p.DhcpguardEnabled.Txt,
"enabled": strconv.FormatBool(p.Enabled), "enabled": p.Enabled.Txt,
"vlan_enabled": strconv.FormatBool(p.VlanEnabled), "vlan_enabled": p.VlanEnabled.Txt,
"attr_no_delete": strconv.FormatBool(p.AttrNoDelete), "attr_no_delete": p.AttrNoDelete.Txt,
"upnp_lan_enabled": strconv.FormatBool(p.UpnpLanEnabled), "upnp_lan_enabled": p.UpnpLanEnabled.Txt,
"igmp_snooping": strconv.FormatBool(p.IgmpSnooping), "igmp_snooping": p.IgmpSnooping.Txt,
"is_guest": strconv.FormatBool(p.IsGuest), "is_guest": p.IsGuest.Txt,
"is_nat": strconv.FormatBool(p.IsNat), "is_nat": p.IsNat.Txt,
"networkgroup": p.Networkgroup, "networkgroup": p.Networkgroup,
"site_id": p.SiteID, "site_id": p.SiteID,
} }

View File

@ -4,13 +4,13 @@ import "encoding/json"
// USG represents all the data from the Ubiquiti Controller for a Unifi Security Gateway. // USG represents all the data from the Ubiquiti Controller for a Unifi Security Gateway.
type USG struct { type USG struct {
ID string `json:"_id"` ID string `json:"_id"`
UUptime float64 `json:"_uptime"` UUptime float64 `json:"_uptime"`
AdoptIP string `json:"adopt_ip"` AdoptIP string `json:"adopt_ip"`
AdoptURL string `json:"adopt_url"` AdoptURL string `json:"adopt_url"`
Adopted bool `json:"adopted"` Adopted FlexBool `json:"adopted"`
Bytes float64 `json:"bytes"` Bytes float64 `json:"bytes"`
Cfgversion string `json:"cfgversion"` Cfgversion string `json:"cfgversion"`
ConfigNetwork struct { ConfigNetwork struct {
IP string `json:"ip"` IP string `json:"ip"`
Type string `json:"type"` Type string `json:"type"`
@ -18,48 +18,48 @@ type USG struct {
ConfigNetworkWan struct { ConfigNetworkWan struct {
Type string `json:"type"` Type string `json:"type"`
} `json:"config_network_wan"` } `json:"config_network_wan"`
ConnectRequestIP string `json:"connect_request_ip"` ConnectRequestIP string `json:"connect_request_ip"`
ConnectRequestPort string `json:"connect_request_port"` ConnectRequestPort string `json:"connect_request_port"`
ConsideredLostAt float64 `json:"considered_lost_at"` ConsideredLostAt float64 `json:"considered_lost_at"`
Default bool `json:"default"` Default FlexBool `json:"default"`
DeviceID string `json:"device_id"` DeviceID string `json:"device_id"`
DiscoveredVia string `json:"discovered_via"` DiscoveredVia string `json:"discovered_via"`
EthernetTable []struct { EthernetTable []struct {
Mac string `json:"mac"` Mac string `json:"mac"`
Name string `json:"name"` Name string `json:"name"`
NumPort float64 `json:"num_port"` NumPort float64 `json:"num_port"`
} `json:"ethernet_table"` } `json:"ethernet_table"`
FwCaps float64 `json:"fw_caps"` FwCaps float64 `json:"fw_caps"`
GuestNumSta float64 `json:"guest-num_sta"` GuestNumSta float64 `json:"guest-num_sta"`
GuestToken string `json:"guest_token"` GuestToken string `json:"guest_token"`
InformIP string `json:"inform_ip"` InformIP string `json:"inform_ip"`
InformURL string `json:"inform_url"` InformURL string `json:"inform_url"`
IP string `json:"ip"` IP string `json:"ip"`
KnownCfgversion string `json:"known_cfgversion"` KnownCfgversion string `json:"known_cfgversion"`
LastSeen float64 `json:"last_seen"` LastSeen float64 `json:"last_seen"`
LedOverride string `json:"led_override"` LedOverride string `json:"led_override"`
LicenseState string `json:"license_state"` LicenseState string `json:"license_state"`
Locating bool `json:"locating"` Locating FlexBool `json:"locating"`
Mac string `json:"mac"` Mac string `json:"mac"`
Model string `json:"model"` Model string `json:"model"`
Name string `json:"name"` Name string `json:"name"`
NetworkTable []struct { NetworkTable []struct {
ID string `json:"_id"` ID string `json:"_id"`
DhcpdDNSEnabled bool `json:"dhcpd_dns_enabled"` DhcpdDNSEnabled FlexBool `json:"dhcpd_dns_enabled"`
DhcpdEnabled bool `json:"dhcpd_enabled"` DhcpdEnabled FlexBool `json:"dhcpd_enabled"`
DhcpdIP1 string `json:"dhcpd_ip_1,omitempty"` DhcpdIP1 string `json:"dhcpd_ip_1,omitempty"`
DhcpdLeasetime json.Number `json:"dhcpd_leasetime,Number"` DhcpdLeasetime json.Number `json:"dhcpd_leasetime,Number"`
DhcpdStart string `json:"dhcpd_start"` DhcpdStart string `json:"dhcpd_start"`
DhcpdStop string `json:"dhcpd_stop"` DhcpdStop string `json:"dhcpd_stop"`
DhcpdWinsEnabled bool `json:"dhcpd_wins_enabled,omitempty"` DhcpdWinsEnabled FlexBool `json:"dhcpd_wins_enabled,omitempty"`
DhcpguardEnabled bool `json:"dhcpguard_enabled,omitempty"` DhcpguardEnabled FlexBool `json:"dhcpguard_enabled,omitempty"`
DomainName string `json:"domain_name"` DomainName string `json:"domain_name"`
Enabled bool `json:"enabled"` Enabled FlexBool `json:"enabled"`
IgmpSnooping bool `json:"igmp_snooping,omitempty"` IgmpSnooping FlexBool `json:"igmp_snooping,omitempty"`
IP string `json:"ip"` IP string `json:"ip"`
IPSubnet string `json:"ip_subnet"` IPSubnet string `json:"ip_subnet"`
IsGuest bool `json:"is_guest"` IsGuest FlexBool `json:"is_guest"`
IsNat bool `json:"is_nat"` IsNat FlexBool `json:"is_nat"`
Mac string `json:"mac"` Mac string `json:"mac"`
Name string `json:"name"` Name string `json:"name"`
Networkgroup string `json:"networkgroup"` Networkgroup string `json:"networkgroup"`
@ -72,17 +72,17 @@ type USG struct {
TxPackets float64 `json:"tx_packets"` TxPackets float64 `json:"tx_packets"`
Up FlexBool `json:"up"` Up FlexBool `json:"up"`
Vlan string `json:"vlan,omitempty"` Vlan string `json:"vlan,omitempty"`
VlanEnabled bool `json:"vlan_enabled"` VlanEnabled FlexBool `json:"vlan_enabled"`
DhcpRelayEnabled bool `json:"dhcp_relay_enabled,omitempty"` DhcpRelayEnabled FlexBool `json:"dhcp_relay_enabled,omitempty"`
DhcpdGatewayEnabled bool `json:"dhcpd_gateway_enabled,omitempty"` DhcpdGatewayEnabled FlexBool `json:"dhcpd_gateway_enabled,omitempty"`
DhcpdNtp1 string `json:"dhcpd_ntp_1,omitempty"` DhcpdNtp1 string `json:"dhcpd_ntp_1,omitempty"`
DhcpdNtpEnabled bool `json:"dhcpd_ntp_enabled,omitempty"` DhcpdNtpEnabled FlexBool `json:"dhcpd_ntp_enabled,omitempty"`
DhcpdTimeOffsetEnabled bool `json:"dhcpd_time_offset_enabled,omitempty"` DhcpdTimeOffsetEnabled FlexBool `json:"dhcpd_time_offset_enabled,omitempty"`
DhcpdUnifiController string `json:"dhcpd_unifi_controller,omitempty"` DhcpdUnifiController string `json:"dhcpd_unifi_controller,omitempty"`
Ipv6InterfaceType string `json:"ipv6_interface_type,omitempty"` Ipv6InterfaceType string `json:"ipv6_interface_type,omitempty"`
AttrHiddenID string `json:"attr_hidden_id,omitempty"` AttrHiddenID string `json:"attr_hidden_id,omitempty"`
AttrNoDelete bool `json:"attr_no_delete,omitempty"` AttrNoDelete FlexBool `json:"attr_no_delete,omitempty"`
UpnpLanEnabled bool `json:"upnp_lan_enabled,omitempty"` UpnpLanEnabled FlexBool `json:"upnp_lan_enabled,omitempty"`
} `json:"network_table"` } `json:"network_table"`
NextHeartbeatAt float64 `json:"next_heartbeat_at"` NextHeartbeatAt float64 `json:"next_heartbeat_at"`
NumDesktop float64 `json:"num_desktop"` NumDesktop float64 `json:"num_desktop"`
@ -92,8 +92,8 @@ type USG struct {
OutdoorModeOverride string `json:"outdoor_mode_override"` OutdoorModeOverride string `json:"outdoor_mode_override"`
PortTable []struct { PortTable []struct {
DNS []string `json:"dns,omitempty"` DNS []string `json:"dns,omitempty"`
Enable bool `json:"enable"` Enable FlexBool `json:"enable"`
FullDuplex bool `json:"full_duplex"` FullDuplex FlexBool `json:"full_duplex"`
Gateway string `json:"gateway,omitempty"` Gateway string `json:"gateway,omitempty"`
Ifname string `json:"ifname"` Ifname string `json:"ifname"`
IP string `json:"ip"` IP string `json:"ip"`
@ -112,10 +112,10 @@ type USG struct {
TxPackets float64 `json:"tx_packets"` TxPackets float64 `json:"tx_packets"`
Up FlexBool `json:"up"` Up FlexBool `json:"up"`
} `json:"port_table"` } `json:"port_table"`
Rollupgrade bool `json:"rollupgrade"` Rollupgrade FlexBool `json:"rollupgrade"`
RxBytes float64 `json:"rx_bytes"` RxBytes float64 `json:"rx_bytes"`
Serial string `json:"serial"` Serial string `json:"serial"`
SiteID string `json:"site_id"` SiteID string `json:"site_id"`
SpeedtestStatus struct { SpeedtestStatus struct {
Latency float64 `json:"latency"` Latency float64 `json:"latency"`
Rundate float64 `json:"rundate"` Rundate float64 `json:"rundate"`
@ -127,7 +127,7 @@ type USG struct {
XputDownload float64 `json:"xput_download"` XputDownload float64 `json:"xput_download"`
XputUpload float64 `json:"xput_upload"` XputUpload float64 `json:"xput_upload"`
} `json:"speedtest-status"` } `json:"speedtest-status"`
SpeedtestStatusSaved bool `json:"speedtest-status-saved"` SpeedtestStatusSaved FlexBool `json:"speedtest-status-saved"`
Stat struct { Stat struct {
Datetime string `json:"datetime"` Datetime string `json:"datetime"`
Duration float64 `json:"duration"` Duration float64 `json:"duration"`
@ -160,14 +160,14 @@ type USG struct {
Mem float64 `json:"mem,string"` Mem float64 `json:"mem,string"`
Uptime float64 `json:"uptime,string"` Uptime float64 `json:"uptime,string"`
} `json:"system-stats"` } `json:"system-stats"`
TxBytes float64 `json:"tx_bytes"` TxBytes float64 `json:"tx_bytes"`
Type string `json:"type"` Type string `json:"type"`
Upgradable bool `json:"upgradable"` Upgradable FlexBool `json:"upgradable"`
Uplink struct { Uplink struct {
BytesR float64 `json:"bytes-r"` BytesR float64 `json:"bytes-r"`
Drops float64 `json:"drops"` Drops float64 `json:"drops"`
Enable bool `json:"enable"` Enable FlexBool `json:"enable"`
FullDuplex bool `json:"full_duplex"` FullDuplex FlexBool `json:"full_duplex"`
Gateways []string `json:"gateways"` Gateways []string `json:"gateways"`
IP string `json:"ip"` IP string `json:"ip"`
Latency float64 `json:"latency"` Latency float64 `json:"latency"`
@ -198,16 +198,16 @@ type USG struct {
XputDown float64 `json:"xput_down"` XputDown float64 `json:"xput_down"`
XputUp float64 `json:"xput_up"` XputUp float64 `json:"xput_up"`
} `json:"uplink"` } `json:"uplink"`
Uptime float64 `json:"uptime"` Uptime float64 `json:"uptime"`
UserNumSta float64 `json:"user-num_sta"` UserNumSta float64 `json:"user-num_sta"`
UsgCaps float64 `json:"usg_caps"` UsgCaps float64 `json:"usg_caps"`
Version string `json:"version"` Version string `json:"version"`
VersionIncompatible bool `json:"version_incompatible"` VersionIncompatible FlexBool `json:"version_incompatible"`
Wan1 struct { Wan1 struct {
BytesR float64 `json:"bytes-r"` BytesR float64 `json:"bytes-r"`
DNS []string `json:"dns"` DNS []string `json:"dns"`
Enable bool `json:"enable"` Enable FlexBool `json:"enable"`
FullDuplex bool `json:"full_duplex"` FullDuplex FlexBool `json:"full_duplex"`
Gateway string `json:"gateway"` Gateway string `json:"gateway"`
Ifname string `json:"ifname"` Ifname string `json:"ifname"`
IP string `json:"ip"` IP string `json:"ip"`
@ -233,8 +233,8 @@ type USG struct {
Wan2 struct { Wan2 struct {
BytesR float64 `json:"bytes-r"` BytesR float64 `json:"bytes-r"`
DNS []string `json:"dns"` DNS []string `json:"dns"`
Enable bool `json:"enable"` Enable FlexBool `json:"enable"`
FullDuplex bool `json:"full_duplex"` FullDuplex FlexBool `json:"full_duplex"`
Gateway string `json:"gateway"` Gateway string `json:"gateway"`
Ifname string `json:"ifname"` Ifname string `json:"ifname"`
IP string `json:"ip"` IP string `json:"ip"`

View File

@ -1,7 +1,6 @@
package unifi package unifi
import ( import (
"strconv"
"time" "time"
influx "github.com/influxdata/influxdb1-client/v2" influx "github.com/influxdata/influxdb1-client/v2"
@ -17,7 +16,7 @@ func (u USW) Points() ([]*influx.Point, error) {
"device_oid": u.Stat.Oid, "device_oid": u.Stat.Oid,
"site_id": u.SiteID, "site_id": u.SiteID,
"name": u.Name, "name": u.Name,
"adopted": strconv.FormatBool(u.Adopted), "adopted": u.Adopted.Txt,
"adopt_ip": u.AdoptIP, "adopt_ip": u.AdoptIP,
"adopt_url": u.AdoptURL, "adopt_url": u.AdoptURL,
"cfgversion": u.Cfgversion, "cfgversion": u.Cfgversion,
@ -25,24 +24,24 @@ func (u USW) Points() ([]*influx.Point, error) {
"config_network_type": u.ConfigNetwork.Type, "config_network_type": u.ConfigNetwork.Type,
"connect_request_ip": u.ConnectRequestIP, "connect_request_ip": u.ConnectRequestIP,
"connect_request_port": u.ConnectRequestPort, "connect_request_port": u.ConnectRequestPort,
"default": strconv.FormatBool(u.Default), "default": u.Default.Txt,
"device_id": u.DeviceID, "device_id": u.DeviceID,
"discovered_via": u.DiscoveredVia, "discovered_via": u.DiscoveredVia,
"inform_ip": u.InformIP, "inform_ip": u.InformIP,
"last_uplink_mac": u.LastUplink.UplinkMac, "last_uplink_mac": u.LastUplink.UplinkMac,
"known_cfgversion": u.KnownCfgversion, "known_cfgversion": u.KnownCfgversion,
"led_override": u.LedOverride, "led_override": u.LedOverride,
"locating": strconv.FormatBool(u.Locating), "locating": u.Locating.Txt,
"model": u.Model, "model": u.Model,
"outdoor_mode_override": u.OutdoorModeOverride, "outdoor_mode_override": u.OutdoorModeOverride,
"serial": u.Serial, "serial": u.Serial,
"type": u.Type, "type": u.Type,
"version_incompatible": strconv.FormatBool(u.VersionIncompatible), "version_incompatible": u.VersionIncompatible.Txt,
"dot1x_portctrl_enabled": strconv.FormatBool(u.Dot1XPortctrlEnabled), "dot1x_portctrl_enabled": u.Dot1XPortctrlEnabled.Txt,
"flowctrl_enabled": strconv.FormatBool(u.FlowctrlEnabled), "flowctrl_enabled": u.FlowctrlEnabled.Txt,
"has_fan": strconv.FormatBool(u.HasFan), "has_fan": u.HasFan.Txt,
"has_temperature": strconv.FormatBool(u.HasTemperature), "has_temperature": u.HasTemperature.Txt,
"jumboframe_enabled": strconv.FormatBool(u.JumboframeEnabled), "jumboframe_enabled": u.JumboframeEnabled.Txt,
"stp_priority": u.StpPriority, "stp_priority": u.StpPriority,
"stp_version": u.StpVersion, "stp_version": u.StpVersion,
} }
@ -55,15 +54,15 @@ func (u USW) Points() ([]*influx.Point, error) {
"general_temperature": u.GeneralTemperature, "general_temperature": u.GeneralTemperature,
"last_seen": u.LastSeen, "last_seen": u.LastSeen,
"license_state": u.LicenseState, "license_state": u.LicenseState,
"overheating": u.Overheating, "overheating": u.Overheating.Txt,
"rx_bytes": u.RxBytes, "rx_bytes": u.RxBytes,
"tx_bytes": u.TxBytes, "tx_bytes": u.TxBytes,
"uptime": u.Uptime, "uptime": u.Uptime,
"considered_lost_at": u.ConsideredLostAt, "considered_lost_at": u.ConsideredLostAt,
"next_heartbeat_at": u.NextHeartbeatAt, "next_heartbeat_at": u.NextHeartbeatAt,
"roll_upgrade": u.Rollupgrade, "roll_upgrade": u.Rollupgrade.Txt,
"state": u.State, "state": u.State,
"upgradable": u.Upgradable, "upgradable": u.Upgradable.Txt,
"user-num_sta": u.UserNumSta, "user-num_sta": u.UserNumSta,
"version": u.Version, "version": u.Version,
"loadavg_1": u.SysStats.Loadavg1, "loadavg_1": u.SysStats.Loadavg1,
@ -107,7 +106,7 @@ func (u USW) Points() ([]*influx.Point, error) {
"stat_tx_errors": u.Stat.TxErrors, "stat_tx_errors": u.Stat.TxErrors,
"stat_tx_packets": u.Stat.TxPackets, "stat_tx_packets": u.Stat.TxPackets,
"stat_tx_retries": u.Stat.TxRetries, "stat_tx_retries": u.Stat.TxRetries,
"uplink_depth": strconv.FormatFloat(u.UplinkDepth, 'f', 6, 64), "uplink_depth": u.UplinkDepth,
// Add the port stats too. // Add the port stats too.
} }
pt, err := influx.NewPoint("usw", tags, fields, time.Now()) pt, err := influx.NewPoint("usw", tags, fields, time.Now())

View File

@ -2,14 +2,14 @@ package unifi
// USW represents all the data from the Ubiquiti Controller for a Unifi Switch. // USW represents all the data from the Ubiquiti Controller for a Unifi Switch.
type USW struct { type USW struct {
ID string `json:"_id"` ID string `json:"_id"`
UUptime float64 `json:"_uptime"` UUptime float64 `json:"_uptime"`
AdoptIP string `json:"adopt_ip"` AdoptIP string `json:"adopt_ip"`
AdoptURL string `json:"adopt_url"` AdoptURL string `json:"adopt_url"`
Adopted bool `json:"adopted"` Adopted FlexBool `json:"adopted"`
BoardRev float64 `json:"board_rev"` BoardRev float64 `json:"board_rev"`
Bytes float64 `json:"bytes"` Bytes float64 `json:"bytes"`
Cfgversion string `json:"cfgversion"` Cfgversion string `json:"cfgversion"`
ConfigNetwork struct { ConfigNetwork struct {
IP string `json:"ip"` IP string `json:"ip"`
Type string `json:"type"` Type string `json:"type"`
@ -17,48 +17,48 @@ type USW struct {
ConnectRequestIP string `json:"connect_request_ip"` ConnectRequestIP string `json:"connect_request_ip"`
ConnectRequestPort string `json:"connect_request_port"` ConnectRequestPort string `json:"connect_request_port"`
ConsideredLostAt float64 `json:"considered_lost_at"` ConsideredLostAt float64 `json:"considered_lost_at"`
Default bool `json:"default"` Default FlexBool `json:"default"`
DeviceID string `json:"device_id"` DeviceID string `json:"device_id"`
DhcpServerTable []interface{} `json:"dhcp_server_table"` DhcpServerTable []interface{} `json:"dhcp_server_table"`
DiscoveredVia string `json:"discovered_via"` DiscoveredVia string `json:"discovered_via"`
Dot1XPortctrlEnabled bool `json:"dot1x_portctrl_enabled"` Dot1XPortctrlEnabled FlexBool `json:"dot1x_portctrl_enabled"`
DownlinkTable []struct { DownlinkTable []struct {
FullDuplex bool `json:"full_duplex"` FullDuplex FlexBool `json:"full_duplex"`
Mac string `json:"mac"` Mac string `json:"mac"`
PortIdx float64 `json:"port_idx"` PortIdx float64 `json:"port_idx"`
Speed float64 `json:"speed"` Speed float64 `json:"speed"`
} `json:"downlink_table"` } `json:"downlink_table"`
EthernetTable []struct { EthernetTable []struct {
Mac string `json:"mac"` Mac string `json:"mac"`
Name string `json:"name"` Name string `json:"name"`
NumPort float64 `json:"num_port,omitempty"` NumPort float64 `json:"num_port,omitempty"`
} `json:"ethernet_table"` } `json:"ethernet_table"`
FanLevel float64 `json:"fan_level"` FanLevel float64 `json:"fan_level"`
FlowctrlEnabled bool `json:"flowctrl_enabled"` FlowctrlEnabled FlexBool `json:"flowctrl_enabled"`
FwCaps float64 `json:"fw_caps"` FwCaps float64 `json:"fw_caps"`
GeneralTemperature float64 `json:"general_temperature"` GeneralTemperature float64 `json:"general_temperature"`
GuestNumSta float64 `json:"guest-num_sta"` GuestNumSta float64 `json:"guest-num_sta"`
HasFan bool `json:"has_fan"` HasFan FlexBool `json:"has_fan"`
HasTemperature bool `json:"has_temperature"` HasTemperature FlexBool `json:"has_temperature"`
InformIP string `json:"inform_ip"` InformIP string `json:"inform_ip"`
InformURL string `json:"inform_url"` InformURL string `json:"inform_url"`
IP string `json:"ip"` IP string `json:"ip"`
JumboframeEnabled bool `json:"jumboframe_enabled"` JumboframeEnabled FlexBool `json:"jumboframe_enabled"`
KnownCfgversion string `json:"known_cfgversion"` KnownCfgversion string `json:"known_cfgversion"`
LastSeen float64 `json:"last_seen"` LastSeen float64 `json:"last_seen"`
LastUplink struct { LastUplink struct {
UplinkMac string `json:"uplink_mac"` UplinkMac string `json:"uplink_mac"`
} `json:"last_uplink"` } `json:"last_uplink"`
LedOverride string `json:"led_override"` LedOverride string `json:"led_override"`
LicenseState string `json:"license_state"` LicenseState string `json:"license_state"`
Locating bool `json:"locating"` Locating FlexBool `json:"locating"`
Mac string `json:"mac"` Mac string `json:"mac"`
Model string `json:"model"` Model string `json:"model"`
Name string `json:"name"` Name string `json:"name"`
NextHeartbeatAt float64 `json:"next_heartbeat_at"` NextHeartbeatAt float64 `json:"next_heartbeat_at"`
NumSta float64 `json:"num_sta"` NumSta float64 `json:"num_sta"`
OutdoorModeOverride string `json:"outdoor_mode_override"` OutdoorModeOverride string `json:"outdoor_mode_override"`
Overheating bool `json:"overheating"` Overheating FlexBool `json:"overheating"`
PortOverrides []struct { PortOverrides []struct {
Name string `json:"name,omitempty"` Name string `json:"name,omitempty"`
PoeMode string `json:"poe_mode,omitempty"` PoeMode string `json:"poe_mode,omitempty"`
@ -66,32 +66,32 @@ type USW struct {
PortconfID string `json:"portconf_id"` PortconfID string `json:"portconf_id"`
} `json:"port_overrides"` } `json:"port_overrides"`
PortTable []struct { PortTable []struct {
AggregatedBy bool `json:"aggregated_by"` AggregatedBy FlexBool `json:"aggregated_by"`
Autoneg bool `json:"autoneg"` Autoneg FlexBool `json:"autoneg"`
BytesR float64 `json:"bytes-r"` BytesR float64 `json:"bytes-r"`
Dot1XMode string `json:"dot1x_mode"` Dot1XMode string `json:"dot1x_mode"`
Dot1XStatus string `json:"dot1x_status"` Dot1XStatus string `json:"dot1x_status"`
Enable bool `json:"enable"` Enable FlexBool `json:"enable"`
FlowctrlRx bool `json:"flowctrl_rx"` FlowctrlRx FlexBool `json:"flowctrl_rx"`
FlowctrlTx bool `json:"flowctrl_tx"` FlowctrlTx FlexBool `json:"flowctrl_tx"`
FullDuplex bool `json:"full_duplex"` FullDuplex FlexBool `json:"full_duplex"`
IsUplink bool `json:"is_uplink"` IsUplink FlexBool `json:"is_uplink"`
Jumbo bool `json:"jumbo"` Jumbo FlexBool `json:"jumbo"`
LldpTable []interface{} `json:"lldp_table"` LldpTable []interface{} `json:"lldp_table"`
Masked bool `json:"masked"` Masked FlexBool `json:"masked"`
Media string `json:"media"` Media string `json:"media"`
Name string `json:"name"` Name string `json:"name"`
OpMode string `json:"op_mode"` OpMode string `json:"op_mode"`
PoeCaps float64 `json:"poe_caps"` PoeCaps float64 `json:"poe_caps"`
PoeClass string `json:"poe_class,omitempty"` PoeClass string `json:"poe_class,omitempty"`
PoeCurrent string `json:"poe_current,omitempty"` PoeCurrent string `json:"poe_current,omitempty"`
PoeEnable bool `json:"poe_enable,omitempty"` PoeEnable FlexBool `json:"poe_enable,omitempty"`
PoeGood bool `json:"poe_good,omitempty"` PoeGood FlexBool `json:"poe_good,omitempty"`
PoeMode string `json:"poe_mode,omitempty"` PoeMode string `json:"poe_mode,omitempty"`
PoePower string `json:"poe_power,omitempty"` PoePower string `json:"poe_power,omitempty"`
PoeVoltage string `json:"poe_voltage,omitempty"` PoeVoltage string `json:"poe_voltage,omitempty"`
PortIdx float64 `json:"port_idx"` PortIdx float64 `json:"port_idx"`
PortPoe bool `json:"port_poe"` PortPoe FlexBool `json:"port_poe"`
PortconfID string `json:"portconf_id"` PortconfID string `json:"portconf_id"`
RxBroadcast float64 `json:"rx_broadcast"` RxBroadcast float64 `json:"rx_broadcast"`
RxBytes float64 `json:"rx_bytes"` RxBytes float64 `json:"rx_bytes"`
@ -110,10 +110,10 @@ type USW struct {
TxErrors float64 `json:"tx_errors"` TxErrors float64 `json:"tx_errors"`
TxMulticast float64 `json:"tx_multicast"` TxMulticast float64 `json:"tx_multicast"`
TxPackets float64 `json:"tx_packets"` TxPackets float64 `json:"tx_packets"`
Up bool `json:"up"` Up FlexBool `json:"up"`
SfpFound bool `json:"sfp_found,omitempty"` SfpFound FlexBool `json:"sfp_found,omitempty"`
} `json:"port_table"` } `json:"port_table"`
Rollupgrade bool `json:"rollupgrade"` Rollupgrade FlexBool `json:"rollupgrade"`
RxBytes float64 `json:"rx_bytes"` RxBytes float64 `json:"rx_bytes"`
Serial string `json:"serial"` Serial string `json:"serial"`
SiteID string `json:"site_id"` SiteID string `json:"site_id"`
@ -378,38 +378,38 @@ type USW struct {
Mem float64 `json:"mem,string"` Mem float64 `json:"mem,string"`
Uptime float64 `json:"uptime,string"` Uptime float64 `json:"uptime,string"`
} `json:"system-stats"` } `json:"system-stats"`
TxBytes float64 `json:"tx_bytes"` TxBytes float64 `json:"tx_bytes"`
Type string `json:"type"` Type string `json:"type"`
Upgradable bool `json:"upgradable"` Upgradable FlexBool `json:"upgradable"`
Uplink struct { Uplink struct {
FullDuplex bool `json:"full_duplex"` FullDuplex FlexBool `json:"full_duplex"`
IP string `json:"ip"` IP string `json:"ip"`
Mac string `json:"mac"` Mac string `json:"mac"`
MaxSpeed float64 `json:"max_speed"` MaxSpeed float64 `json:"max_speed"`
Media string `json:"media"` Media string `json:"media"`
Name string `json:"name"` Name string `json:"name"`
Netmask string `json:"netmask"` Netmask string `json:"netmask"`
NumPort float64 `json:"num_port"` NumPort float64 `json:"num_port"`
PortIdx float64 `json:"port_idx"` PortIdx float64 `json:"port_idx"`
RxBytes float64 `json:"rx_bytes"` RxBytes float64 `json:"rx_bytes"`
RxBytesR float64 `json:"rx_bytes-r"` RxBytesR float64 `json:"rx_bytes-r"`
RxDropped float64 `json:"rx_dropped"` RxDropped float64 `json:"rx_dropped"`
RxErrors float64 `json:"rx_errors"` RxErrors float64 `json:"rx_errors"`
RxMulticast float64 `json:"rx_multicast"` RxMulticast float64 `json:"rx_multicast"`
RxPackets float64 `json:"rx_packets"` RxPackets float64 `json:"rx_packets"`
Speed float64 `json:"speed"` Speed float64 `json:"speed"`
TxBytes float64 `json:"tx_bytes"` TxBytes float64 `json:"tx_bytes"`
TxBytesR float64 `json:"tx_bytes-r"` TxBytesR float64 `json:"tx_bytes-r"`
TxDropped float64 `json:"tx_dropped"` TxDropped float64 `json:"tx_dropped"`
TxErrors float64 `json:"tx_errors"` TxErrors float64 `json:"tx_errors"`
TxPackets float64 `json:"tx_packets"` TxPackets float64 `json:"tx_packets"`
Type string `json:"type"` Type string `json:"type"`
Up bool `json:"up"` Up FlexBool `json:"up"`
UplinkMac string `json:"uplink_mac"` UplinkMac string `json:"uplink_mac"`
} `json:"uplink"` } `json:"uplink"`
UplinkDepth float64 `json:"uplink_depth"` UplinkDepth float64 `json:"uplink_depth"`
Uptime float64 `json:"uptime"` Uptime float64 `json:"uptime"`
UserNumSta float64 `json:"user-num_sta"` UserNumSta float64 `json:"user-num_sta"`
Version string `json:"version"` Version string `json:"version"`
VersionIncompatible bool `json:"version_incompatible"` VersionIncompatible FlexBool `json:"version_incompatible"`
} }