From 92361fbe344f2e8685bbe32b57dbaf1e6f91dea6 Mon Sep 17 00:00:00 2001 From: David Newhall II Date: Wed, 17 Apr 2019 02:38:57 -0700 Subject: [PATCH] FlexBool it up --- core/unifi/README.md | 1 + core/unifi/clients_influx.go | 22 +-- core/unifi/clients_type.go | 150 ++++++++--------- core/unifi/uap_influx.go | 34 ++-- core/unifi/uap_type.go | 310 +++++++++++++++++------------------ core/unifi/usg_influx.go | 46 +++--- core/unifi/usg_type.go | 126 +++++++------- core/unifi/usw_influx.go | 27 ++- core/unifi/usw_type.go | 168 +++++++++---------- 9 files changed, 442 insertions(+), 442 deletions(-) diff --git a/core/unifi/README.md b/core/unifi/README.md index 5ea77454..177519ef 100644 --- a/core/unifi/README.md +++ b/core/unifi/README.md @@ -44,6 +44,7 @@ func main() { log.Fatalln("Error:", err) } + log.Println(len(sites), "Unifi Sites Found: ", sites) log.Println(len(clients.UCLs), "Clients connected:") for i, client := range clients.UCLs { log.Println(i+1, client.ID, client.Hostname, client.IP, client.Name, client.LastSeen) diff --git a/core/unifi/clients_influx.go b/core/unifi/clients_influx.go index 70adf58f..f1dc92d7 100644 --- a/core/unifi/clients_influx.go +++ b/core/unifi/clients_influx.go @@ -42,17 +42,17 @@ func (c UCL) Points() ([]*influx.Point, error) { "dev_cat": strconv.Itoa(c.DevCat), "dev_id": strconv.Itoa(c.DevID), "dev_family": strconv.Itoa(c.DevFamily), - "authorized": strconv.FormatBool(c.Authorized), - "is_11r": strconv.FormatBool(c.Is11R), - "is_wired": strconv.FormatBool(c.IsWired), - "is_guest": strconv.FormatBool(c.IsGuest), - "is_guest_by_uap": strconv.FormatBool(c.IsGuestByUAP), - "is_guest_by_ugw": strconv.FormatBool(c.IsGuestByUGW), - "is_guest_by_usw": strconv.FormatBool(c.IsGuestByUSW), - "noted": strconv.FormatBool(c.Noted), - "powersave_enabled": strconv.FormatBool(c.PowersaveEnabled), - "qos_policy_applied": strconv.FormatBool(c.QosPolicyApplied), - "use_fixedip": strconv.FormatBool(c.UseFixedIP), + "authorized": c.Authorized.Txt, + "is_11r": c.Is11R.Txt, + "is_wired": c.IsWired.Txt, + "is_guest": c.IsGuest.Txt, + "is_guest_by_uap": c.IsGuestByUAP.Txt, + "is_guest_by_ugw": c.IsGuestByUGW.Txt, + "is_guest_by_usw": c.IsGuestByUSW.Txt, + "noted": c.Noted.Txt, + "powersave_enabled": c.PowersaveEnabled.Txt, + "qos_policy_applied": c.QosPolicyApplied.Txt, + "use_fixedip": c.UseFixedIP.Txt, "channel": strconv.Itoa(c.Channel), "vlan": strconv.Itoa(c.Vlan), } diff --git a/core/unifi/clients_type.go b/core/unifi/clients_type.go index 996c2493..2ad29ccf 100644 --- a/core/unifi/clients_type.go +++ b/core/unifi/clients_type.go @@ -2,26 +2,26 @@ package unifi // UCL defines all the data a connected-network client contains. type UCL struct { - ID string `json:"_id"` - IsGuestByUAP bool `json:"_is_guest_by_uap"` - IsGuestByUGW bool `json:"_is_guest_by_ugw"` - IsGuestByUSW bool `json:"_is_guest_by_usw"` - LastSeenByUAP int64 `json:"_last_seen_by_uap"` - LastSeenByUGW int64 `json:"_last_seen_by_ugw"` - LastSeenByUSW int64 `json:"_last_seen_by_usw"` - UptimeByUAP int64 `json:"_uptime_by_uap"` - UptimeByUGW int64 `json:"_uptime_by_ugw"` - UptimeByUSW int64 `json:"_uptime_by_usw"` - ApMac string `json:"ap_mac"` - AssocTime int64 `json:"assoc_time"` - Authorized bool `json:"authorized"` - Bssid string `json:"bssid"` - BytesR int64 `json:"bytes-r"` - Ccq int64 `json:"ccq"` - Channel int `json:"channel"` - DevCat int `json:"dev_cat"` - DevFamily int `json:"dev_family"` - DevID int `json:"dev_id"` + ID string `json:"_id"` + IsGuestByUAP FlexBool `json:"_is_guest_by_uap"` + IsGuestByUGW FlexBool `json:"_is_guest_by_ugw"` + IsGuestByUSW FlexBool `json:"_is_guest_by_usw"` + LastSeenByUAP int64 `json:"_last_seen_by_uap"` + LastSeenByUGW int64 `json:"_last_seen_by_ugw"` + LastSeenByUSW int64 `json:"_last_seen_by_usw"` + UptimeByUAP int64 `json:"_uptime_by_uap"` + UptimeByUGW int64 `json:"_uptime_by_ugw"` + UptimeByUSW int64 `json:"_uptime_by_usw"` + ApMac string `json:"ap_mac"` + AssocTime int64 `json:"assoc_time"` + Authorized FlexBool `json:"authorized"` + Bssid string `json:"bssid"` + BytesR int64 `json:"bytes-r"` + Ccq int64 `json:"ccq"` + Channel int `json:"channel"` + DevCat int `json:"dev_cat"` + DevFamily int `json:"dev_family"` + DevID int `json:"dev_id"` DpiStats struct { App int64 Cat int64 @@ -30,59 +30,59 @@ type UCL struct { TxBytes int64 TxPackets int64 } `json:"dpi_stats"` - DpiStatsLastUpdated int64 `json:"dpi_stats_last_updated"` - Essid string `json:"essid"` - FirstSeen int64 `json:"first_seen"` - FixedIP string `json:"fixed_ip"` - Hostname string `json:"hostname"` - GwMac string `json:"gw_mac"` - IdleTime int64 `json:"idle_time"` - IP string `json:"ip"` - Is11R bool `json:"is_11r"` - IsGuest bool `json:"is_guest"` - IsWired bool `json:"is_wired"` - LastSeen int64 `json:"last_seen"` - LatestAssocTime int64 `json:"latest_assoc_time"` - Mac string `json:"mac"` - Name string `json:"name"` - Network string `json:"network"` - NetworkID string `json:"network_id"` - Noise int64 `json:"noise"` - Note string `json:"note"` - Noted bool `json:"noted"` - OsClass int `json:"os_class"` - OsName int `json:"os_name"` - Oui string `json:"oui"` - PowersaveEnabled bool `json:"powersave_enabled"` - QosPolicyApplied bool `json:"qos_policy_applied"` - Radio string `json:"radio"` - RadioName string `json:"radio_name"` - RadioProto string `json:"radio_proto"` - RoamCount int64 `json:"roam_count"` - Rssi int64 `json:"rssi"` - RxBytes int64 `json:"rx_bytes"` - RxBytesR int64 `json:"rx_bytes-r"` - RxPackets int64 `json:"rx_packets"` - RxRate int64 `json:"rx_rate"` - Signal int64 `json:"signal"` - SiteID string `json:"site_id"` - SwDepth int `json:"sw_depth"` - SwMac string `json:"sw_mac"` - SwPort int `json:"sw_port"` - TxBytes int64 `json:"tx_bytes"` - TxBytesR int64 `json:"tx_bytes-r"` - TxPackets int64 `json:"tx_packets"` - TxPower int64 `json:"tx_power"` - TxRate int64 `json:"tx_rate"` - Uptime int64 `json:"uptime"` - UserID string `json:"user_id"` - UserGroupID string `json:"usergroup_id"` - UseFixedIP bool `json:"use_fixedip"` - Vlan int `json:"vlan"` - WiredRxBytes int64 `json:"wired-rx_bytes"` - WiredRxBytesR int64 `json:"wired-rx_bytes-r"` - WiredRxPackets int64 `json:"wired-rx_packets"` - WiredTxBytes int64 `json:"wired-tx_bytes"` - WiredTxBytesR int64 `json:"wired-tx_bytes-r"` - WiredTxPackets int64 `json:"wired-tx_packets"` + DpiStatsLastUpdated int64 `json:"dpi_stats_last_updated"` + Essid string `json:"essid"` + FirstSeen int64 `json:"first_seen"` + FixedIP string `json:"fixed_ip"` + Hostname string `json:"hostname"` + GwMac string `json:"gw_mac"` + IdleTime int64 `json:"idle_time"` + IP string `json:"ip"` + Is11R FlexBool `json:"is_11r"` + IsGuest FlexBool `json:"is_guest"` + IsWired FlexBool `json:"is_wired"` + LastSeen int64 `json:"last_seen"` + LatestAssocTime int64 `json:"latest_assoc_time"` + Mac string `json:"mac"` + Name string `json:"name"` + Network string `json:"network"` + NetworkID string `json:"network_id"` + Noise int64 `json:"noise"` + Note string `json:"note"` + Noted FlexBool `json:"noted"` + OsClass int `json:"os_class"` + OsName int `json:"os_name"` + Oui string `json:"oui"` + PowersaveEnabled FlexBool `json:"powersave_enabled"` + QosPolicyApplied FlexBool `json:"qos_policy_applied"` + Radio string `json:"radio"` + RadioName string `json:"radio_name"` + RadioProto string `json:"radio_proto"` + RoamCount int64 `json:"roam_count"` + Rssi int64 `json:"rssi"` + RxBytes int64 `json:"rx_bytes"` + RxBytesR int64 `json:"rx_bytes-r"` + RxPackets int64 `json:"rx_packets"` + RxRate int64 `json:"rx_rate"` + Signal int64 `json:"signal"` + SiteID string `json:"site_id"` + SwDepth int `json:"sw_depth"` + SwMac string `json:"sw_mac"` + SwPort int `json:"sw_port"` + TxBytes int64 `json:"tx_bytes"` + TxBytesR int64 `json:"tx_bytes-r"` + TxPackets int64 `json:"tx_packets"` + TxPower int64 `json:"tx_power"` + TxRate int64 `json:"tx_rate"` + Uptime int64 `json:"uptime"` + UserID string `json:"user_id"` + UserGroupID string `json:"usergroup_id"` + UseFixedIP FlexBool `json:"use_fixedip"` + Vlan int `json:"vlan"` + WiredRxBytes int64 `json:"wired-rx_bytes"` + WiredRxBytesR int64 `json:"wired-rx_bytes-r"` + WiredRxPackets int64 `json:"wired-rx_packets"` + WiredTxBytes int64 `json:"wired-tx_bytes"` + WiredTxBytesR int64 `json:"wired-tx_bytes-r"` + WiredTxPackets int64 `json:"wired-tx_packets"` } diff --git a/core/unifi/uap_influx.go b/core/unifi/uap_influx.go index 31b3f128..04811da4 100644 --- a/core/unifi/uap_influx.go +++ b/core/unifi/uap_influx.go @@ -21,7 +21,7 @@ func (u UAP) Points() ([]*influx.Point, error) { "device_ap": u.Stat.Ap, "site_id": u.SiteID, "name": u.Name, - "adopted": strconv.FormatBool(u.Adopted), + "adopted": u.Adopted.Txt, "bandsteering_mode": u.BandsteeringMode, "board_rev": strconv.Itoa(u.BoardRev), "cfgversion": u.Cfgversion, @@ -29,27 +29,27 @@ func (u UAP) Points() ([]*influx.Point, error) { "config_network_type": u.ConfigNetwork.Type, "connect_request_ip": u.ConnectRequestIP, "connect_request_port": u.ConnectRequestPort, - "default": strconv.FormatBool(u.Default), + "default": u.Default.Txt, "device_id": u.DeviceID, "discovered_via": u.DiscoveredVia, "fw_caps": strconv.Itoa(u.FwCaps), "guest-num_sta": strconv.Itoa(u.GuestNumSta), "guest_token": u.GuestToken, - "has_eth1": strconv.FormatBool(u.HasEth1), - "has_speaker": strconv.FormatBool(u.HasSpeaker), + "has_eth1": u.HasEth1.Txt, + "has_speaker": u.HasSpeaker.Txt, "inform_ip": u.InformIP, - "isolated": strconv.FormatBool(u.Isolated), + "isolated": u.Isolated.Txt, "last_uplink_mac": u.LastUplink.UplinkMac, "last_uplink_remote_port": strconv.Itoa(u.LastUplink.UplinkRemotePort), "known_cfgversion": u.KnownCfgversion, "led_override": u.LedOverride, - "locating": strconv.FormatBool(u.Locating), + "locating": u.Locating.Txt, "model": u.Model, "outdoor_mode_override": u.OutdoorModeOverride, "serial": u.Serial, "type": u.Type, - "version_incompatible": strconv.FormatBool(u.VersionIncompatible), - "vwireEnabled": strconv.FormatBool(u.VwireEnabled), + "version_incompatible": u.VersionIncompatible.Txt, + "vwireEnabled": u.VwireEnabled.Txt, "wifi_caps": strconv.Itoa(u.WifiCaps), } fields := map[string]interface{}{ @@ -65,11 +65,11 @@ func (u UAP) Points() ([]*influx.Point, error) { "uptime": u.Uptime.Val, "considered_lost_at": u.ConsideredLostAt, "next_heartbeat_at": u.NextHeartbeatAt, - "scanning": u.Scanning, + "scanning": u.Scanning.Txt, "spectrum_scanning": u.SpectrumScanning, - "roll_upgrade": u.Rollupgrade, + "roll_upgrade": u.Rollupgrade.Txt, "state": u.State, - "upgradable": u.Upgradable, + "upgradable": u.Upgradable.Txt, "user-num_sta": u.UserNumSta, "version": u.Version, "loadavg_1": u.SysStats.Loadavg1, @@ -187,12 +187,12 @@ func (u UAP) Points() ([]*influx.Point, error) { fields := map[string]interface{}{ "builtin_ant_gain": p.BuiltinAntGain, "current_antenna_gain": p.CurrentAntennaGain, - "has_dfs": p.HasDfs, - "has_fccdfs": p.HasFccdfs, + "has_dfs": p.HasDfs.Txt, + "has_fccdfs": p.HasFccdfs.Txt, "ht": p.Ht, - "is_11ac": p.Is11Ac, + "is_11ac": p.Is11Ac.Txt, "max_txpower": p.MaxTxpower, - "min_rssi_enabled": p.MinRssiEnabled, + "min_rssi_enabled": p.MinRssiEnabled.Txt, "min_txpower": p.MinTxpower, "nss": p.Nss, "radio_caps": p.RadioCaps, @@ -234,8 +234,8 @@ func (u UAP) Points() ([]*influx.Point, error) { fields["ccq"] = s.Ccq fields["essid"] = s.Essid fields["extchannel"] = s.Extchannel - fields["is_guest"] = s.IsGuest - fields["is_wep"] = s.IsWep + fields["is_guest"] = s.IsGuest.Txt + fields["is_wep"] = s.IsWep.Txt fields["mac_filter_rejections"] = s.MacFilterRejections fields["map_id"] = s.MapID fields["vap_rx_bytes"] = s.RxBytes diff --git a/core/unifi/uap_type.go b/core/unifi/uap_type.go index a6116eb6..5ceae3f4 100644 --- a/core/unifi/uap_type.go +++ b/core/unifi/uap_type.go @@ -7,11 +7,11 @@ type UAP struct { No ones feelings will be hurt if you want to break this up into multiple structs, and/or make it better in general. */ - ID string `json:"_id"` - UUptime float64 `json:"_uptime"` - AdoptIP string `json:"adopt_ip,omitempty"` - AdoptURL string `json:"adopt_url,omitempty"` - Adopted bool `json:"adopted"` + ID string `json:"_id"` + UUptime float64 `json:"_uptime"` + AdoptIP string `json:"adopt_ip,omitempty"` + AdoptURL string `json:"adopt_url,omitempty"` + Adopted FlexBool `json:"adopted"` AntennaTable []struct { ID float64 `json:"id"` Name string `json:"name"` @@ -32,7 +32,7 @@ type UAP struct { ConnectRequestPort string `json:"connect_request_port"` ConsideredLostAt float64 `json:"considered_lost_at"` CountrycodeTable []float64 `json:"countrycode_table"` - Default bool `json:"default,omitempty"` + Default FlexBool `json:"default,omitempty"` DeviceID string `json:"device_id"` DiscoveredVia string `json:"discovered_via,omitempty"` DownlinkTable []interface{} `json:"downlink_table"` @@ -41,52 +41,52 @@ type UAP struct { Name string `json:"name"` NumPort float64 `json:"num_port"` } `json:"ethernet_table"` - FwCaps int `json:"fw_caps"` - GuestNumSta int `json:"guest-num_sta"` - GuestToken string `json:"guest_token"` - HasEth1 bool `json:"has_eth1"` - HasSpeaker bool `json:"has_speaker"` - InformIP string `json:"inform_ip"` - InformURL string `json:"inform_url"` - IP string `json:"ip"` - Isolated bool `json:"isolated"` - KnownCfgversion string `json:"known_cfgversion"` - LastSeen float64 `json:"last_seen"` + FwCaps int `json:"fw_caps"` + GuestNumSta int `json:"guest-num_sta"` + GuestToken string `json:"guest_token"` + HasEth1 FlexBool `json:"has_eth1"` + HasSpeaker FlexBool `json:"has_speaker"` + InformIP string `json:"inform_ip"` + InformURL string `json:"inform_url"` + IP string `json:"ip"` + Isolated FlexBool `json:"isolated"` + KnownCfgversion string `json:"known_cfgversion"` + LastSeen float64 `json:"last_seen"` LastUplink struct { UplinkMac string `json:"uplink_mac"` UplinkRemotePort int `json:"uplink_remote_port"` } `json:"last_uplink"` - LedOverride string `json:"led_override"` - Locating bool `json:"locating"` - Mac string `json:"mac"` - Model string `json:"model"` - Name string `json:"name"` - NextHeartbeatAt float64 `json:"next_heartbeat_at"` - NumSta float64 `json:"num_sta"` - OutdoorModeOverride string `json:"outdoor_mode_override"` + LedOverride string `json:"led_override"` + Locating FlexBool `json:"locating"` + Mac string `json:"mac"` + Model string `json:"model"` + Name string `json:"name"` + NextHeartbeatAt float64 `json:"next_heartbeat_at"` + NumSta float64 `json:"num_sta"` + OutdoorModeOverride string `json:"outdoor_mode_override"` PortTable []struct { - AggregatedBy bool `json:"aggregated_by"` - AttrNoEdit bool `json:"attr_no_edit,omitempty"` - Autoneg bool `json:"autoneg"` - BytesR float64 `json:"bytes-r"` - Enable bool `json:"enable"` - FlowctrlRx bool `json:"flowctrl_rx"` - FlowctrlTx bool `json:"flowctrl_tx"` - FullDuplex bool `json:"full_duplex"` - IsUplink bool `json:"is_uplink"` - Jumbo bool `json:"jumbo"` + AggregatedBy FlexBool `json:"aggregated_by"` + AttrNoEdit FlexBool `json:"attr_no_edit,omitempty"` + Autoneg FlexBool `json:"autoneg"` + BytesR float64 `json:"bytes-r"` + Enable FlexBool `json:"enable"` + FlowctrlRx FlexBool `json:"flowctrl_rx"` + FlowctrlTx FlexBool `json:"flowctrl_tx"` + FullDuplex FlexBool `json:"full_duplex"` + IsUplink FlexBool `json:"is_uplink"` + Jumbo FlexBool `json:"jumbo"` MacTable []struct { - Age float64 `json:"age"` - Mac string `json:"mac"` - Static bool `json:"static"` - Uptime float64 `json:"uptime"` - Vlan float64 `json:"vlan"` + Age float64 `json:"age"` + Mac string `json:"mac"` + Static FlexBool `json:"static"` + Uptime float64 `json:"uptime"` + Vlan float64 `json:"vlan"` } `json:"mac_table"` - Masked bool `json:"masked"` - Media string `json:"media"` - Name string `json:"name"` - OpMode string `json:"op_mode"` - PoeCaps float64 `json:"poe_caps"` + Masked FlexBool `json:"masked"` + Media string `json:"media"` + Name string `json:"name"` + OpMode string `json:"op_mode"` + PoeCaps float64 `json:"poe_caps"` PortDelta struct { RxBytes float64 `json:"rx_bytes"` RxPackets float64 `json:"rx_packets"` @@ -94,47 +94,47 @@ type UAP struct { TxBytes float64 `json:"tx_bytes"` TxPackets float64 `json:"tx_packets"` } `json:"port_delta"` - PortIdx float64 `json:"port_idx"` - PortPoe bool `json:"port_poe"` - PortconfID string `json:"portconf_id"` - RxBroadcast float64 `json:"rx_broadcast"` - RxBytes float64 `json:"rx_bytes"` - RxBytesR float64 `json:"rx_bytes-r"` - RxDropped float64 `json:"rx_dropped"` - RxErrors float64 `json:"rx_errors"` - RxMulticast float64 `json:"rx_multicast"` - RxPackets float64 `json:"rx_packets"` - Speed float64 `json:"speed"` - StpPathcost float64 `json:"stp_pathcost"` - StpState string `json:"stp_state"` - TxBroadcast float64 `json:"tx_broadcast"` - TxBytes float64 `json:"tx_bytes"` - TxBytesR float64 `json:"tx_bytes-r"` - TxDropped float64 `json:"tx_dropped"` - TxErrors float64 `json:"tx_errors"` - TxMulticast float64 `json:"tx_multicast"` - TxPackets float64 `json:"tx_packets"` - Up bool `json:"up"` + PortIdx float64 `json:"port_idx"` + PortPoe FlexBool `json:"port_poe"` + PortconfID string `json:"portconf_id"` + RxBroadcast float64 `json:"rx_broadcast"` + RxBytes float64 `json:"rx_bytes"` + RxBytesR float64 `json:"rx_bytes-r"` + RxDropped float64 `json:"rx_dropped"` + RxErrors float64 `json:"rx_errors"` + RxMulticast float64 `json:"rx_multicast"` + RxPackets float64 `json:"rx_packets"` + Speed float64 `json:"speed"` + StpPathcost float64 `json:"stp_pathcost"` + StpState string `json:"stp_state"` + TxBroadcast float64 `json:"tx_broadcast"` + TxBytes float64 `json:"tx_bytes"` + TxBytesR float64 `json:"tx_bytes-r"` + TxDropped float64 `json:"tx_dropped"` + TxErrors float64 `json:"tx_errors"` + TxMulticast float64 `json:"tx_multicast"` + TxPackets float64 `json:"tx_packets"` + Up FlexBool `json:"up"` } `json:"port_table"` RadioTable []struct { - BuiltinAntGain float64 `json:"builtin_ant_gain"` - BuiltinAntenna bool `json:"builtin_antenna"` - Channel FlexInt `json:"channel"` - CurrentAntennaGain float64 `json:"current_antenna_gain"` - Ht string `json:"ht"` - MaxTxpower float64 `json:"max_txpower"` - MinRssiEnabled bool `json:"min_rssi_enabled"` - MinTxpower float64 `json:"min_txpower"` - Name string `json:"name"` - Nss float64 `json:"nss"` - Radio string `json:"radio"` - RadioCaps float64 `json:"radio_caps"` - TxPower FlexInt `json:"tx_power"` - TxPowerMode string `json:"tx_power_mode"` - WlangroupID string `json:"wlangroup_id"` - HasDfs bool `json:"has_dfs,omitempty"` - HasFccdfs bool `json:"has_fccdfs,omitempty"` - Is11Ac bool `json:"is_11ac,omitempty"` + BuiltinAntGain float64 `json:"builtin_ant_gain"` + BuiltinAntenna FlexBool `json:"builtin_antenna"` + Channel FlexInt `json:"channel"` + CurrentAntennaGain float64 `json:"current_antenna_gain"` + Ht string `json:"ht"` + MaxTxpower float64 `json:"max_txpower"` + MinRssiEnabled FlexBool `json:"min_rssi_enabled"` + MinTxpower float64 `json:"min_txpower"` + Name string `json:"name"` + Nss float64 `json:"nss"` + Radio string `json:"radio"` + RadioCaps float64 `json:"radio_caps"` + TxPower FlexInt `json:"tx_power"` + TxPowerMode string `json:"tx_power_mode"` + WlangroupID string `json:"wlangroup_id"` + HasDfs FlexBool `json:"has_dfs,omitempty"` + HasFccdfs FlexBool `json:"has_fccdfs,omitempty"` + Is11Ac FlexBool `json:"is_11ac,omitempty"` } `json:"radio_table"` RadioTableStats []struct { AstBeXmit float64 `json:"ast_be_xmit"` @@ -156,14 +156,14 @@ type UAP struct { TxRetries float64 `json:"tx_retries"` UserNumSta float64 `json:"user-num_sta"` } `json:"radio_table_stats"` - Rollupgrade bool `json:"rollupgrade"` + Rollupgrade FlexBool `json:"rollupgrade"` RxBytes float64 `json:"rx_bytes"` RxBytesD float64 `json:"rx_bytes-d"` ScanRadioTable []interface{} `json:"scan_radio_table"` - Scanning bool `json:"scanning"` + Scanning FlexBool `json:"scanning"` Serial string `json:"serial"` SiteID string `json:"site_id"` - SpectrumScanning bool `json:"spectrum_scanning"` + SpectrumScanning FlexBool `json:"spectrum_scanning"` SSHSessionTable []interface{} `json:"ssh_session_table"` Stat struct { Ap string `json:"ap"` @@ -274,82 +274,82 @@ type UAP struct { Mem float64 `json:"mem,string"` Uptime float64 `json:"uptime,string"` } `json:"system-stats"` - TxBytes float64 `json:"tx_bytes"` - TxBytesD float64 `json:"tx_bytes-d"` - Type string `json:"type"` - Upgradable bool `json:"upgradable"` + TxBytes float64 `json:"tx_bytes"` + TxBytesD float64 `json:"tx_bytes-d"` + Type string `json:"type"` + Upgradable FlexBool `json:"upgradable"` Uplink struct { - FullDuplex bool `json:"full_duplex"` - IP string `json:"ip"` - Mac string `json:"mac"` - MaxSpeed int `json:"max_speed"` - MaxVlan int `json:"max_vlan"` - Media string `json:"media"` - Name string `json:"name"` - Netmask string `json:"netmask"` - NumPort int `json:"num_port"` - RxBytes float64 `json:"rx_bytes"` - RxBytesR float64 `json:"rx_bytes-r"` - RxDropped float64 `json:"rx_dropped"` - RxErrors float64 `json:"rx_errors"` - RxMulticast float64 `json:"rx_multicast"` - RxPackets float64 `json:"rx_packets"` - Speed float64 `json:"speed"` - TxBytes float64 `json:"tx_bytes"` - TxBytesR float64 `json:"tx_bytes-r"` - TxDropped float64 `json:"tx_dropped"` - TxErrors float64 `json:"tx_errors"` - TxPackets float64 `json:"tx_packets"` - Type string `json:"type"` - Up bool `json:"up"` - UplinkMac string `json:"uplink_mac"` - UplinkRemotePort int `json:"uplink_remote_port"` + FullDuplex FlexBool `json:"full_duplex"` + IP string `json:"ip"` + Mac string `json:"mac"` + MaxSpeed int `json:"max_speed"` + MaxVlan int `json:"max_vlan"` + Media string `json:"media"` + Name string `json:"name"` + Netmask string `json:"netmask"` + NumPort int `json:"num_port"` + RxBytes float64 `json:"rx_bytes"` + RxBytesR float64 `json:"rx_bytes-r"` + RxDropped float64 `json:"rx_dropped"` + RxErrors float64 `json:"rx_errors"` + RxMulticast float64 `json:"rx_multicast"` + RxPackets float64 `json:"rx_packets"` + Speed float64 `json:"speed"` + TxBytes float64 `json:"tx_bytes"` + TxBytesR float64 `json:"tx_bytes-r"` + TxDropped float64 `json:"tx_dropped"` + TxErrors float64 `json:"tx_errors"` + TxPackets float64 `json:"tx_packets"` + Type string `json:"type"` + Up FlexBool `json:"up"` + UplinkMac string `json:"uplink_mac"` + UplinkRemotePort int `json:"uplink_remote_port"` } `json:"uplink"` UplinkTable []interface{} `json:"uplink_table"` Uptime FlexInt `json:"uptime"` UserNumSta int `json:"user-num_sta"` VapTable []struct { - ApMac string `json:"ap_mac"` - Bssid string `json:"bssid"` - Ccq int `json:"ccq"` - Channel int `json:"channel"` - Essid string `json:"essid"` - Extchannel int `json:"extchannel"` - ID string `json:"id"` - IsGuest bool `json:"is_guest"` - IsWep bool `json:"is_wep"` - MacFilterRejections int `json:"mac_filter_rejections"` - MapID string `json:"map_id"` - Name string `json:"name"` - NumSta int `json:"num_sta"` - Radio string `json:"radio"` - RadioName string `json:"radio_name"` - RxBytes float64 `json:"rx_bytes"` - RxCrypts float64 `json:"rx_crypts"` - RxDropped float64 `json:"rx_dropped"` - RxErrors float64 `json:"rx_errors"` - RxFrags float64 `json:"rx_frags"` - RxNwids float64 `json:"rx_nwids"` - RxPackets float64 `json:"rx_packets"` - SiteID string `json:"site_id"` - State string `json:"state"` - T string `json:"t"` - TxBytes float64 `json:"tx_bytes"` - TxDropped float64 `json:"tx_dropped"` - TxErrors float64 `json:"tx_errors"` - TxLatencyAvg float64 `json:"tx_latency_avg"` - TxLatencyMax float64 `json:"tx_latency_max"` - TxLatencyMin float64 `json:"tx_latency_min"` - TxPackets float64 `json:"tx_packets"` - TxPower FlexInt `json:"tx_power"` - TxRetries int `json:"tx_retries"` - Up bool `json:"up"` - Usage string `json:"usage"` - WlanconfID string `json:"wlanconf_id"` + ApMac string `json:"ap_mac"` + Bssid string `json:"bssid"` + Ccq int `json:"ccq"` + Channel int `json:"channel"` + Essid string `json:"essid"` + Extchannel int `json:"extchannel"` + ID string `json:"id"` + IsGuest FlexBool `json:"is_guest"` + IsWep FlexBool `json:"is_wep"` + MacFilterRejections int `json:"mac_filter_rejections"` + MapID string `json:"map_id"` + Name string `json:"name"` + NumSta int `json:"num_sta"` + Radio string `json:"radio"` + RadioName string `json:"radio_name"` + RxBytes float64 `json:"rx_bytes"` + RxCrypts float64 `json:"rx_crypts"` + RxDropped float64 `json:"rx_dropped"` + RxErrors float64 `json:"rx_errors"` + RxFrags float64 `json:"rx_frags"` + RxNwids float64 `json:"rx_nwids"` + RxPackets float64 `json:"rx_packets"` + SiteID string `json:"site_id"` + State string `json:"state"` + T string `json:"t"` + TxBytes float64 `json:"tx_bytes"` + TxDropped float64 `json:"tx_dropped"` + TxErrors float64 `json:"tx_errors"` + TxLatencyAvg float64 `json:"tx_latency_avg"` + TxLatencyMax float64 `json:"tx_latency_max"` + TxLatencyMin float64 `json:"tx_latency_min"` + TxPackets float64 `json:"tx_packets"` + TxPower FlexInt `json:"tx_power"` + TxRetries int `json:"tx_retries"` + Up FlexBool `json:"up"` + Usage string `json:"usage"` + WlanconfID string `json:"wlanconf_id"` } `json:"vap_table"` Version string `json:"version"` - VersionIncompatible bool `json:"version_incompatible"` - VwireEnabled bool `json:"vwireEnabled"` + VersionIncompatible FlexBool `json:"version_incompatible"` + VwireEnabled FlexBool `json:"vwireEnabled"` VwireTable []interface{} `json:"vwire_table"` VwireVapTable []struct { Bssid string `json:"bssid"` diff --git a/core/unifi/usg_influx.go b/core/unifi/usg_influx.go index a2a52779..a3f0c520 100644 --- a/core/unifi/usg_influx.go +++ b/core/unifi/usg_influx.go @@ -16,7 +16,7 @@ func (u USG) Points() ([]*influx.Point, error) { "device_type": u.Stat.O, "device_oid": u.Stat.Oid, "site_id": u.SiteID, - "adopted": strconv.FormatBool(u.Adopted), + "adopted": u.Adopted.Txt, "name": u.Name, "adopt_ip": u.AdoptIP, "adopt_url": u.AdoptURL, @@ -25,21 +25,21 @@ func (u USG) Points() ([]*influx.Point, error) { "config_network_type": u.ConfigNetwork.Type, "connect_request_ip": u.ConnectRequestIP, "connect_request_port": u.ConnectRequestPort, - "default": strconv.FormatBool(u.Default), + "default": u.Default.Txt, "device_id": u.DeviceID, "discovered_via": u.DiscoveredVia, "guest_token": u.GuestToken, "inform_ip": u.InformIP, "known_cfgversion": u.KnownCfgversion, "led_override": u.LedOverride, - "locating": strconv.FormatBool(u.Locating), + "locating": u.Locating.Txt, "model": u.Model, "outdoor_mode_override": u.OutdoorModeOverride, "serial": u.Serial, "type": u.Type, - "version_incompatible": strconv.FormatBool(u.VersionIncompatible), + "version_incompatible": u.VersionIncompatible.Txt, "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{}{ "ip": u.IP, @@ -53,9 +53,9 @@ func (u USG) Points() ([]*influx.Point, error) { "uptime": u.Uptime, "considered_lost_at": u.ConsideredLostAt, "next_heartbeat_at": u.NextHeartbeatAt, - "roll_upgrade": u.Rollupgrade, + "roll_upgrade": u.Rollupgrade.Txt, "state": u.State, - "upgradable": u.Upgradable, + "upgradable": u.Upgradable.Txt, "user-num_sta": u.UserNumSta, "version": u.Version, "num_desktop": u.NumDesktop, @@ -74,7 +74,7 @@ func (u USG) Points() ([]*influx.Point, error) { "config_network_wan_type": u.ConfigNetworkWan.Type, "wan1_bytes-r": u.Wan1.BytesR, "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_gateway": u.Wan1.Gateway, "wan1_ifname": u.Wan1.Ifname, @@ -136,21 +136,21 @@ func (u USG) Points() ([]*influx.Point, error) { "device_id": u.ID, "device_mac": u.Mac, "name": p.Name, - "dhcpd_dns_enabled": strconv.FormatBool(p.DhcpdDNSEnabled), - "dhcpd_enabled": strconv.FormatBool(p.DhcpdEnabled), - "dhcpd_ntp_enabled": strconv.FormatBool(p.DhcpdNtpEnabled), - "dhcpd_time_offset_enabled": strconv.FormatBool(p.DhcpdTimeOffsetEnabled), - "dhcp_relay_enabledy": strconv.FormatBool(p.DhcpRelayEnabled), - "dhcpd_gateway_enabled": strconv.FormatBool(p.DhcpdGatewayEnabled), - "dhcpd_wins_enabled": strconv.FormatBool(p.DhcpdWinsEnabled), - "dhcpguard_enabled": strconv.FormatBool(p.DhcpguardEnabled), - "enabled": strconv.FormatBool(p.Enabled), - "vlan_enabled": strconv.FormatBool(p.VlanEnabled), - "attr_no_delete": strconv.FormatBool(p.AttrNoDelete), - "upnp_lan_enabled": strconv.FormatBool(p.UpnpLanEnabled), - "igmp_snooping": strconv.FormatBool(p.IgmpSnooping), - "is_guest": strconv.FormatBool(p.IsGuest), - "is_nat": strconv.FormatBool(p.IsNat), + "dhcpd_dns_enabled": p.DhcpdDNSEnabled.Txt, + "dhcpd_enabled": p.DhcpdEnabled.Txt, + "dhcpd_ntp_enabled": p.DhcpdNtpEnabled.Txt, + "dhcpd_time_offset_enabled": p.DhcpdTimeOffsetEnabled.Txt, + "dhcp_relay_enabledy": p.DhcpRelayEnabled.Txt, + "dhcpd_gateway_enabled": p.DhcpdGatewayEnabled.Txt, + "dhcpd_wins_enabled": p.DhcpdWinsEnabled.Txt, + "dhcpguard_enabled": p.DhcpguardEnabled.Txt, + "enabled": p.Enabled.Txt, + "vlan_enabled": p.VlanEnabled.Txt, + "attr_no_delete": p.AttrNoDelete.Txt, + "upnp_lan_enabled": p.UpnpLanEnabled.Txt, + "igmp_snooping": p.IgmpSnooping.Txt, + "is_guest": p.IsGuest.Txt, + "is_nat": p.IsNat.Txt, "networkgroup": p.Networkgroup, "site_id": p.SiteID, } diff --git a/core/unifi/usg_type.go b/core/unifi/usg_type.go index e8bc453f..1dad0fca 100644 --- a/core/unifi/usg_type.go +++ b/core/unifi/usg_type.go @@ -4,13 +4,13 @@ import "encoding/json" // USG represents all the data from the Ubiquiti Controller for a Unifi Security Gateway. type USG struct { - ID string `json:"_id"` - UUptime float64 `json:"_uptime"` - AdoptIP string `json:"adopt_ip"` - AdoptURL string `json:"adopt_url"` - Adopted bool `json:"adopted"` - Bytes float64 `json:"bytes"` - Cfgversion string `json:"cfgversion"` + ID string `json:"_id"` + UUptime float64 `json:"_uptime"` + AdoptIP string `json:"adopt_ip"` + AdoptURL string `json:"adopt_url"` + Adopted FlexBool `json:"adopted"` + Bytes float64 `json:"bytes"` + Cfgversion string `json:"cfgversion"` ConfigNetwork struct { IP string `json:"ip"` Type string `json:"type"` @@ -18,48 +18,48 @@ type USG struct { ConfigNetworkWan struct { Type string `json:"type"` } `json:"config_network_wan"` - ConnectRequestIP string `json:"connect_request_ip"` - ConnectRequestPort string `json:"connect_request_port"` - ConsideredLostAt float64 `json:"considered_lost_at"` - Default bool `json:"default"` - DeviceID string `json:"device_id"` - DiscoveredVia string `json:"discovered_via"` + ConnectRequestIP string `json:"connect_request_ip"` + ConnectRequestPort string `json:"connect_request_port"` + ConsideredLostAt float64 `json:"considered_lost_at"` + Default FlexBool `json:"default"` + DeviceID string `json:"device_id"` + DiscoveredVia string `json:"discovered_via"` EthernetTable []struct { Mac string `json:"mac"` Name string `json:"name"` NumPort float64 `json:"num_port"` } `json:"ethernet_table"` - FwCaps float64 `json:"fw_caps"` - GuestNumSta float64 `json:"guest-num_sta"` - GuestToken string `json:"guest_token"` - InformIP string `json:"inform_ip"` - InformURL string `json:"inform_url"` - IP string `json:"ip"` - KnownCfgversion string `json:"known_cfgversion"` - LastSeen float64 `json:"last_seen"` - LedOverride string `json:"led_override"` - LicenseState string `json:"license_state"` - Locating bool `json:"locating"` - Mac string `json:"mac"` - Model string `json:"model"` - Name string `json:"name"` + FwCaps float64 `json:"fw_caps"` + GuestNumSta float64 `json:"guest-num_sta"` + GuestToken string `json:"guest_token"` + InformIP string `json:"inform_ip"` + InformURL string `json:"inform_url"` + IP string `json:"ip"` + KnownCfgversion string `json:"known_cfgversion"` + LastSeen float64 `json:"last_seen"` + LedOverride string `json:"led_override"` + LicenseState string `json:"license_state"` + Locating FlexBool `json:"locating"` + Mac string `json:"mac"` + Model string `json:"model"` + Name string `json:"name"` NetworkTable []struct { ID string `json:"_id"` - DhcpdDNSEnabled bool `json:"dhcpd_dns_enabled"` - DhcpdEnabled bool `json:"dhcpd_enabled"` + DhcpdDNSEnabled FlexBool `json:"dhcpd_dns_enabled"` + DhcpdEnabled FlexBool `json:"dhcpd_enabled"` DhcpdIP1 string `json:"dhcpd_ip_1,omitempty"` DhcpdLeasetime json.Number `json:"dhcpd_leasetime,Number"` DhcpdStart string `json:"dhcpd_start"` DhcpdStop string `json:"dhcpd_stop"` - DhcpdWinsEnabled bool `json:"dhcpd_wins_enabled,omitempty"` - DhcpguardEnabled bool `json:"dhcpguard_enabled,omitempty"` + DhcpdWinsEnabled FlexBool `json:"dhcpd_wins_enabled,omitempty"` + DhcpguardEnabled FlexBool `json:"dhcpguard_enabled,omitempty"` DomainName string `json:"domain_name"` - Enabled bool `json:"enabled"` - IgmpSnooping bool `json:"igmp_snooping,omitempty"` + Enabled FlexBool `json:"enabled"` + IgmpSnooping FlexBool `json:"igmp_snooping,omitempty"` IP string `json:"ip"` IPSubnet string `json:"ip_subnet"` - IsGuest bool `json:"is_guest"` - IsNat bool `json:"is_nat"` + IsGuest FlexBool `json:"is_guest"` + IsNat FlexBool `json:"is_nat"` Mac string `json:"mac"` Name string `json:"name"` Networkgroup string `json:"networkgroup"` @@ -72,17 +72,17 @@ type USG struct { TxPackets float64 `json:"tx_packets"` Up FlexBool `json:"up"` Vlan string `json:"vlan,omitempty"` - VlanEnabled bool `json:"vlan_enabled"` - DhcpRelayEnabled bool `json:"dhcp_relay_enabled,omitempty"` - DhcpdGatewayEnabled bool `json:"dhcpd_gateway_enabled,omitempty"` + VlanEnabled FlexBool `json:"vlan_enabled"` + DhcpRelayEnabled FlexBool `json:"dhcp_relay_enabled,omitempty"` + DhcpdGatewayEnabled FlexBool `json:"dhcpd_gateway_enabled,omitempty"` DhcpdNtp1 string `json:"dhcpd_ntp_1,omitempty"` - DhcpdNtpEnabled bool `json:"dhcpd_ntp_enabled,omitempty"` - DhcpdTimeOffsetEnabled bool `json:"dhcpd_time_offset_enabled,omitempty"` + DhcpdNtpEnabled FlexBool `json:"dhcpd_ntp_enabled,omitempty"` + DhcpdTimeOffsetEnabled FlexBool `json:"dhcpd_time_offset_enabled,omitempty"` DhcpdUnifiController string `json:"dhcpd_unifi_controller,omitempty"` Ipv6InterfaceType string `json:"ipv6_interface_type,omitempty"` AttrHiddenID string `json:"attr_hidden_id,omitempty"` - AttrNoDelete bool `json:"attr_no_delete,omitempty"` - UpnpLanEnabled bool `json:"upnp_lan_enabled,omitempty"` + AttrNoDelete FlexBool `json:"attr_no_delete,omitempty"` + UpnpLanEnabled FlexBool `json:"upnp_lan_enabled,omitempty"` } `json:"network_table"` NextHeartbeatAt float64 `json:"next_heartbeat_at"` NumDesktop float64 `json:"num_desktop"` @@ -92,8 +92,8 @@ type USG struct { OutdoorModeOverride string `json:"outdoor_mode_override"` PortTable []struct { DNS []string `json:"dns,omitempty"` - Enable bool `json:"enable"` - FullDuplex bool `json:"full_duplex"` + Enable FlexBool `json:"enable"` + FullDuplex FlexBool `json:"full_duplex"` Gateway string `json:"gateway,omitempty"` Ifname string `json:"ifname"` IP string `json:"ip"` @@ -112,10 +112,10 @@ type USG struct { TxPackets float64 `json:"tx_packets"` Up FlexBool `json:"up"` } `json:"port_table"` - Rollupgrade bool `json:"rollupgrade"` - RxBytes float64 `json:"rx_bytes"` - Serial string `json:"serial"` - SiteID string `json:"site_id"` + Rollupgrade FlexBool `json:"rollupgrade"` + RxBytes float64 `json:"rx_bytes"` + Serial string `json:"serial"` + SiteID string `json:"site_id"` SpeedtestStatus struct { Latency float64 `json:"latency"` Rundate float64 `json:"rundate"` @@ -127,7 +127,7 @@ type USG struct { XputDownload float64 `json:"xput_download"` XputUpload float64 `json:"xput_upload"` } `json:"speedtest-status"` - SpeedtestStatusSaved bool `json:"speedtest-status-saved"` + SpeedtestStatusSaved FlexBool `json:"speedtest-status-saved"` Stat struct { Datetime string `json:"datetime"` Duration float64 `json:"duration"` @@ -160,14 +160,14 @@ type USG struct { Mem float64 `json:"mem,string"` Uptime float64 `json:"uptime,string"` } `json:"system-stats"` - TxBytes float64 `json:"tx_bytes"` - Type string `json:"type"` - Upgradable bool `json:"upgradable"` + TxBytes float64 `json:"tx_bytes"` + Type string `json:"type"` + Upgradable FlexBool `json:"upgradable"` Uplink struct { BytesR float64 `json:"bytes-r"` Drops float64 `json:"drops"` - Enable bool `json:"enable"` - FullDuplex bool `json:"full_duplex"` + Enable FlexBool `json:"enable"` + FullDuplex FlexBool `json:"full_duplex"` Gateways []string `json:"gateways"` IP string `json:"ip"` Latency float64 `json:"latency"` @@ -198,16 +198,16 @@ type USG struct { XputDown float64 `json:"xput_down"` XputUp float64 `json:"xput_up"` } `json:"uplink"` - Uptime float64 `json:"uptime"` - UserNumSta float64 `json:"user-num_sta"` - UsgCaps float64 `json:"usg_caps"` - Version string `json:"version"` - VersionIncompatible bool `json:"version_incompatible"` + Uptime float64 `json:"uptime"` + UserNumSta float64 `json:"user-num_sta"` + UsgCaps float64 `json:"usg_caps"` + Version string `json:"version"` + VersionIncompatible FlexBool `json:"version_incompatible"` Wan1 struct { BytesR float64 `json:"bytes-r"` DNS []string `json:"dns"` - Enable bool `json:"enable"` - FullDuplex bool `json:"full_duplex"` + Enable FlexBool `json:"enable"` + FullDuplex FlexBool `json:"full_duplex"` Gateway string `json:"gateway"` Ifname string `json:"ifname"` IP string `json:"ip"` @@ -233,8 +233,8 @@ type USG struct { Wan2 struct { BytesR float64 `json:"bytes-r"` DNS []string `json:"dns"` - Enable bool `json:"enable"` - FullDuplex bool `json:"full_duplex"` + Enable FlexBool `json:"enable"` + FullDuplex FlexBool `json:"full_duplex"` Gateway string `json:"gateway"` Ifname string `json:"ifname"` IP string `json:"ip"` diff --git a/core/unifi/usw_influx.go b/core/unifi/usw_influx.go index 810148de..d4e3db0b 100644 --- a/core/unifi/usw_influx.go +++ b/core/unifi/usw_influx.go @@ -1,7 +1,6 @@ package unifi import ( - "strconv" "time" influx "github.com/influxdata/influxdb1-client/v2" @@ -17,7 +16,7 @@ func (u USW) Points() ([]*influx.Point, error) { "device_oid": u.Stat.Oid, "site_id": u.SiteID, "name": u.Name, - "adopted": strconv.FormatBool(u.Adopted), + "adopted": u.Adopted.Txt, "adopt_ip": u.AdoptIP, "adopt_url": u.AdoptURL, "cfgversion": u.Cfgversion, @@ -25,24 +24,24 @@ func (u USW) Points() ([]*influx.Point, error) { "config_network_type": u.ConfigNetwork.Type, "connect_request_ip": u.ConnectRequestIP, "connect_request_port": u.ConnectRequestPort, - "default": strconv.FormatBool(u.Default), + "default": u.Default.Txt, "device_id": u.DeviceID, "discovered_via": u.DiscoveredVia, "inform_ip": u.InformIP, "last_uplink_mac": u.LastUplink.UplinkMac, "known_cfgversion": u.KnownCfgversion, "led_override": u.LedOverride, - "locating": strconv.FormatBool(u.Locating), + "locating": u.Locating.Txt, "model": u.Model, "outdoor_mode_override": u.OutdoorModeOverride, "serial": u.Serial, "type": u.Type, - "version_incompatible": strconv.FormatBool(u.VersionIncompatible), - "dot1x_portctrl_enabled": strconv.FormatBool(u.Dot1XPortctrlEnabled), - "flowctrl_enabled": strconv.FormatBool(u.FlowctrlEnabled), - "has_fan": strconv.FormatBool(u.HasFan), - "has_temperature": strconv.FormatBool(u.HasTemperature), - "jumboframe_enabled": strconv.FormatBool(u.JumboframeEnabled), + "version_incompatible": u.VersionIncompatible.Txt, + "dot1x_portctrl_enabled": u.Dot1XPortctrlEnabled.Txt, + "flowctrl_enabled": u.FlowctrlEnabled.Txt, + "has_fan": u.HasFan.Txt, + "has_temperature": u.HasTemperature.Txt, + "jumboframe_enabled": u.JumboframeEnabled.Txt, "stp_priority": u.StpPriority, "stp_version": u.StpVersion, } @@ -55,15 +54,15 @@ func (u USW) Points() ([]*influx.Point, error) { "general_temperature": u.GeneralTemperature, "last_seen": u.LastSeen, "license_state": u.LicenseState, - "overheating": u.Overheating, + "overheating": u.Overheating.Txt, "rx_bytes": u.RxBytes, "tx_bytes": u.TxBytes, "uptime": u.Uptime, "considered_lost_at": u.ConsideredLostAt, "next_heartbeat_at": u.NextHeartbeatAt, - "roll_upgrade": u.Rollupgrade, + "roll_upgrade": u.Rollupgrade.Txt, "state": u.State, - "upgradable": u.Upgradable, + "upgradable": u.Upgradable.Txt, "user-num_sta": u.UserNumSta, "version": u.Version, "loadavg_1": u.SysStats.Loadavg1, @@ -107,7 +106,7 @@ func (u USW) Points() ([]*influx.Point, error) { "stat_tx_errors": u.Stat.TxErrors, "stat_tx_packets": u.Stat.TxPackets, "stat_tx_retries": u.Stat.TxRetries, - "uplink_depth": strconv.FormatFloat(u.UplinkDepth, 'f', 6, 64), + "uplink_depth": u.UplinkDepth, // Add the port stats too. } pt, err := influx.NewPoint("usw", tags, fields, time.Now()) diff --git a/core/unifi/usw_type.go b/core/unifi/usw_type.go index a0d6485c..a5ae6eca 100644 --- a/core/unifi/usw_type.go +++ b/core/unifi/usw_type.go @@ -2,14 +2,14 @@ package unifi // USW represents all the data from the Ubiquiti Controller for a Unifi Switch. type USW struct { - ID string `json:"_id"` - UUptime float64 `json:"_uptime"` - AdoptIP string `json:"adopt_ip"` - AdoptURL string `json:"adopt_url"` - Adopted bool `json:"adopted"` - BoardRev float64 `json:"board_rev"` - Bytes float64 `json:"bytes"` - Cfgversion string `json:"cfgversion"` + ID string `json:"_id"` + UUptime float64 `json:"_uptime"` + AdoptIP string `json:"adopt_ip"` + AdoptURL string `json:"adopt_url"` + Adopted FlexBool `json:"adopted"` + BoardRev float64 `json:"board_rev"` + Bytes float64 `json:"bytes"` + Cfgversion string `json:"cfgversion"` ConfigNetwork struct { IP string `json:"ip"` Type string `json:"type"` @@ -17,48 +17,48 @@ type USW struct { ConnectRequestIP string `json:"connect_request_ip"` ConnectRequestPort string `json:"connect_request_port"` ConsideredLostAt float64 `json:"considered_lost_at"` - Default bool `json:"default"` + Default FlexBool `json:"default"` DeviceID string `json:"device_id"` DhcpServerTable []interface{} `json:"dhcp_server_table"` DiscoveredVia string `json:"discovered_via"` - Dot1XPortctrlEnabled bool `json:"dot1x_portctrl_enabled"` + Dot1XPortctrlEnabled FlexBool `json:"dot1x_portctrl_enabled"` DownlinkTable []struct { - FullDuplex bool `json:"full_duplex"` - Mac string `json:"mac"` - PortIdx float64 `json:"port_idx"` - Speed float64 `json:"speed"` + FullDuplex FlexBool `json:"full_duplex"` + Mac string `json:"mac"` + PortIdx float64 `json:"port_idx"` + Speed float64 `json:"speed"` } `json:"downlink_table"` EthernetTable []struct { Mac string `json:"mac"` Name string `json:"name"` NumPort float64 `json:"num_port,omitempty"` } `json:"ethernet_table"` - FanLevel float64 `json:"fan_level"` - FlowctrlEnabled bool `json:"flowctrl_enabled"` - FwCaps float64 `json:"fw_caps"` - GeneralTemperature float64 `json:"general_temperature"` - GuestNumSta float64 `json:"guest-num_sta"` - HasFan bool `json:"has_fan"` - HasTemperature bool `json:"has_temperature"` - InformIP string `json:"inform_ip"` - InformURL string `json:"inform_url"` - IP string `json:"ip"` - JumboframeEnabled bool `json:"jumboframe_enabled"` - KnownCfgversion string `json:"known_cfgversion"` - LastSeen float64 `json:"last_seen"` + FanLevel float64 `json:"fan_level"` + FlowctrlEnabled FlexBool `json:"flowctrl_enabled"` + FwCaps float64 `json:"fw_caps"` + GeneralTemperature float64 `json:"general_temperature"` + GuestNumSta float64 `json:"guest-num_sta"` + HasFan FlexBool `json:"has_fan"` + HasTemperature FlexBool `json:"has_temperature"` + InformIP string `json:"inform_ip"` + InformURL string `json:"inform_url"` + IP string `json:"ip"` + JumboframeEnabled FlexBool `json:"jumboframe_enabled"` + KnownCfgversion string `json:"known_cfgversion"` + LastSeen float64 `json:"last_seen"` LastUplink struct { UplinkMac string `json:"uplink_mac"` } `json:"last_uplink"` - LedOverride string `json:"led_override"` - LicenseState string `json:"license_state"` - Locating bool `json:"locating"` - Mac string `json:"mac"` - Model string `json:"model"` - Name string `json:"name"` - NextHeartbeatAt float64 `json:"next_heartbeat_at"` - NumSta float64 `json:"num_sta"` - OutdoorModeOverride string `json:"outdoor_mode_override"` - Overheating bool `json:"overheating"` + LedOverride string `json:"led_override"` + LicenseState string `json:"license_state"` + Locating FlexBool `json:"locating"` + Mac string `json:"mac"` + Model string `json:"model"` + Name string `json:"name"` + NextHeartbeatAt float64 `json:"next_heartbeat_at"` + NumSta float64 `json:"num_sta"` + OutdoorModeOverride string `json:"outdoor_mode_override"` + Overheating FlexBool `json:"overheating"` PortOverrides []struct { Name string `json:"name,omitempty"` PoeMode string `json:"poe_mode,omitempty"` @@ -66,32 +66,32 @@ type USW struct { PortconfID string `json:"portconf_id"` } `json:"port_overrides"` PortTable []struct { - AggregatedBy bool `json:"aggregated_by"` - Autoneg bool `json:"autoneg"` + AggregatedBy FlexBool `json:"aggregated_by"` + Autoneg FlexBool `json:"autoneg"` BytesR float64 `json:"bytes-r"` Dot1XMode string `json:"dot1x_mode"` Dot1XStatus string `json:"dot1x_status"` - Enable bool `json:"enable"` - FlowctrlRx bool `json:"flowctrl_rx"` - FlowctrlTx bool `json:"flowctrl_tx"` - FullDuplex bool `json:"full_duplex"` - IsUplink bool `json:"is_uplink"` - Jumbo bool `json:"jumbo"` + Enable FlexBool `json:"enable"` + FlowctrlRx FlexBool `json:"flowctrl_rx"` + FlowctrlTx FlexBool `json:"flowctrl_tx"` + FullDuplex FlexBool `json:"full_duplex"` + IsUplink FlexBool `json:"is_uplink"` + Jumbo FlexBool `json:"jumbo"` LldpTable []interface{} `json:"lldp_table"` - Masked bool `json:"masked"` + Masked FlexBool `json:"masked"` Media string `json:"media"` Name string `json:"name"` OpMode string `json:"op_mode"` PoeCaps float64 `json:"poe_caps"` PoeClass string `json:"poe_class,omitempty"` PoeCurrent string `json:"poe_current,omitempty"` - PoeEnable bool `json:"poe_enable,omitempty"` - PoeGood bool `json:"poe_good,omitempty"` + PoeEnable FlexBool `json:"poe_enable,omitempty"` + PoeGood FlexBool `json:"poe_good,omitempty"` PoeMode string `json:"poe_mode,omitempty"` PoePower string `json:"poe_power,omitempty"` PoeVoltage string `json:"poe_voltage,omitempty"` PortIdx float64 `json:"port_idx"` - PortPoe bool `json:"port_poe"` + PortPoe FlexBool `json:"port_poe"` PortconfID string `json:"portconf_id"` RxBroadcast float64 `json:"rx_broadcast"` RxBytes float64 `json:"rx_bytes"` @@ -110,10 +110,10 @@ type USW struct { TxErrors float64 `json:"tx_errors"` TxMulticast float64 `json:"tx_multicast"` TxPackets float64 `json:"tx_packets"` - Up bool `json:"up"` - SfpFound bool `json:"sfp_found,omitempty"` + Up FlexBool `json:"up"` + SfpFound FlexBool `json:"sfp_found,omitempty"` } `json:"port_table"` - Rollupgrade bool `json:"rollupgrade"` + Rollupgrade FlexBool `json:"rollupgrade"` RxBytes float64 `json:"rx_bytes"` Serial string `json:"serial"` SiteID string `json:"site_id"` @@ -378,38 +378,38 @@ type USW struct { Mem float64 `json:"mem,string"` Uptime float64 `json:"uptime,string"` } `json:"system-stats"` - TxBytes float64 `json:"tx_bytes"` - Type string `json:"type"` - Upgradable bool `json:"upgradable"` + TxBytes float64 `json:"tx_bytes"` + Type string `json:"type"` + Upgradable FlexBool `json:"upgradable"` Uplink struct { - FullDuplex bool `json:"full_duplex"` - IP string `json:"ip"` - Mac string `json:"mac"` - MaxSpeed float64 `json:"max_speed"` - Media string `json:"media"` - Name string `json:"name"` - Netmask string `json:"netmask"` - NumPort float64 `json:"num_port"` - PortIdx float64 `json:"port_idx"` - RxBytes float64 `json:"rx_bytes"` - RxBytesR float64 `json:"rx_bytes-r"` - RxDropped float64 `json:"rx_dropped"` - RxErrors float64 `json:"rx_errors"` - RxMulticast float64 `json:"rx_multicast"` - RxPackets float64 `json:"rx_packets"` - Speed float64 `json:"speed"` - TxBytes float64 `json:"tx_bytes"` - TxBytesR float64 `json:"tx_bytes-r"` - TxDropped float64 `json:"tx_dropped"` - TxErrors float64 `json:"tx_errors"` - TxPackets float64 `json:"tx_packets"` - Type string `json:"type"` - Up bool `json:"up"` - UplinkMac string `json:"uplink_mac"` + FullDuplex FlexBool `json:"full_duplex"` + IP string `json:"ip"` + Mac string `json:"mac"` + MaxSpeed float64 `json:"max_speed"` + Media string `json:"media"` + Name string `json:"name"` + Netmask string `json:"netmask"` + NumPort float64 `json:"num_port"` + PortIdx float64 `json:"port_idx"` + RxBytes float64 `json:"rx_bytes"` + RxBytesR float64 `json:"rx_bytes-r"` + RxDropped float64 `json:"rx_dropped"` + RxErrors float64 `json:"rx_errors"` + RxMulticast float64 `json:"rx_multicast"` + RxPackets float64 `json:"rx_packets"` + Speed float64 `json:"speed"` + TxBytes float64 `json:"tx_bytes"` + TxBytesR float64 `json:"tx_bytes-r"` + TxDropped float64 `json:"tx_dropped"` + TxErrors float64 `json:"tx_errors"` + TxPackets float64 `json:"tx_packets"` + Type string `json:"type"` + Up FlexBool `json:"up"` + UplinkMac string `json:"uplink_mac"` } `json:"uplink"` - UplinkDepth float64 `json:"uplink_depth"` - Uptime float64 `json:"uptime"` - UserNumSta float64 `json:"user-num_sta"` - Version string `json:"version"` - VersionIncompatible bool `json:"version_incompatible"` + UplinkDepth float64 `json:"uplink_depth"` + Uptime float64 `json:"uptime"` + UserNumSta float64 `json:"user-num_sta"` + Version string `json:"version"` + VersionIncompatible FlexBool `json:"version_incompatible"` }