Suck more data out of UAPs.

This commit is contained in:
DN2 2018-04-28 01:59:43 -07:00
parent 3d3d7866d8
commit 9951e4a46e
2 changed files with 183 additions and 90 deletions

View File

@ -8,7 +8,8 @@ import (
) )
// Points generates a device's datapoints for InfluxDB. // Points generates a device's datapoints for InfluxDB.
func (u UAP) Points() (points []*influx.Point, err error) { func (u UAP) Points() ([]*influx.Point, error) {
var points []*influx.Point
tags := map[string]string{ tags := map[string]string{
"id": u.ID, "id": u.ID,
"mac": u.Mac, "mac": u.Mac,
@ -35,7 +36,7 @@ func (u UAP) Points() (points []*influx.Point, err error) {
"has_speaker": strconv.FormatBool(u.HasSpeaker), "has_speaker": strconv.FormatBool(u.HasSpeaker),
"inform_ip": u.InformIP, "inform_ip": u.InformIP,
"isolated": strconv.FormatBool(u.Isolated), "isolated": strconv.FormatBool(u.Isolated),
"last_seen": strconv.Itoa(u.LastSeen), "last_seen": strconv.FormatFloat(u.LastSeen, 'f', 6, 64),
"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,
@ -165,6 +166,98 @@ func (u UAP) Points() (points []*influx.Point, err error) {
"stat_wifi1-tx_packets": u.Stat.Wifi1TxPackets, "stat_wifi1-tx_packets": u.Stat.Wifi1TxPackets,
"stat_wifi1-tx_retries": u.Stat.Wifi1TxRetries, "stat_wifi1-tx_retries": u.Stat.Wifi1TxRetries,
} }
points[0], err = influx.NewPoint("uap", tags, fields, time.Now()) pt, err := influx.NewPoint("uap", tags, fields, time.Now())
return if err != nil {
return nil, err
}
points = append(points, pt)
for _, p := range u.RadioTable {
tags := map[string]string{
"device_name": u.Name,
"device_id": u.ID,
"device_mac": u.Mac,
"name": p.Name,
"wlangroup_id": p.WlangroupID,
"channel": p.Channel, // not the channel #
"radio": p.Radio,
}
fields := map[string]interface{}{
"builtin_ant_gain": p.BuiltinAntGain,
"current_antenna_gain": p.CurrentAntennaGain,
"has_dfs": p.HasDfs,
"has_fccdfs": p.HasFccdfs,
"ht": p.Ht,
"is_11ac": p.Is11Ac,
"max_txpower": p.MaxTxpower,
"min_rssi_enabled": p.MinRssiEnabled,
"min_txpower": p.MinTxpower,
"nss": p.Nss,
"radio_caps": p.RadioCaps,
"tx_power": p.TxPower,
"tx_power_mode": p.TxPowerMode,
}
for _, s := range u.RadioTableStats {
// This may be a tad slower but it allows putting
// all the radio stats into one table.
if p.Name == s.Name {
fields["ast_be_xmit"] = s.AstBeXmit
fields["ast_cst"] = s.AstCst
fields["channel"] = s.Channel
fields["ast_txto"] = s.AstTxto
fields["cu_self_rx"] = s.CuSelfRx
fields["cu_self_tx"] = s.CuSelfTx
fields["cu_total"] = s.CuTotal
fields["extchannel"] = s.Extchannel
fields["gain"] = s.Gain
fields["guest-num_sta"] = s.GuestNumSta
fields["num_sta"] = s.NumSta
fields["radio"] = s.Radio
fields["state"] = s.State
fields["radio_tx_packets"] = s.TxPackets
fields["radio_tx_power"] = s.TxPower
fields["radio_tx_retries"] = s.TxRetries
fields["user-num_sta"] = s.UserNumSta
}
}
for _, s := range u.VapTable {
if p.Name == s.RadioName {
tags["ap_mac"] = s.ApMac
tags["bssid"] = s.Bssid
fields["ccq"] = s.Ccq
fields["essid"] = s.Essid
fields["extchannel"] = s.Extchannel
tags["vap_id"] = s.ID
fields["is_guest"] = s.IsGuest
fields["is_wep"] = s.IsWep
fields["mac_filter_rejections"] = s.MacFilterRejections
fields["map_id"] = s.MapID
tags["vap_name"] = s.Name
fields["rx_bytes"] = s.RxBytes
fields["rx_crypts"] = s.RxCrypts
fields["rx_dropped"] = s.RxDropped
fields["rx_errors"] = s.RxErrors
fields["rx_frags"] = s.RxFrags
fields["rx_nwids"] = s.RxNwids
fields["rx_packets"] = s.RxPackets
fields["tx_bytes"] = s.TxBytes
fields["tx_dropped"] = s.TxDropped
fields["tx_errors"] = s.TxErrors
fields["tx_latency_avg"] = s.TxLatencyAvg
fields["tx_latency_max"] = s.TxLatencyMax
fields["tx_latency_min"] = s.TxLatencyMin
fields["tx_packets"] = s.TxPackets
fields["tx_power"] = s.TxPower
fields["tx_retries"] = s.TxRetries
fields["usage"] = s.Usage
tags["wlanconf_id"] = s.WlanconfID
}
}
pt, err := influx.NewPoint("uap_radios", tags, fields, time.Now())
if err != nil {
return points, err
}
points = append(points, pt)
}
return points, nil
} }

View File

@ -36,17 +36,17 @@ 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 bool `json:"has_eth1"`
HasSpeaker bool `json:"has_speaker"` HasSpeaker bool `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 bool `json:"isolated"`
KnownCfgversion string `json:"known_cfgversion"` KnownCfgversion string `json:"known_cfgversion"`
LastSeen int `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"`
@ -132,28 +132,28 @@ type UAP struct {
Is11Ac bool `json:"is_11ac,omitempty"` Is11Ac bool `json:"is_11ac,omitempty"`
} `json:"radio_table"` } `json:"radio_table"`
RadioTableStats []struct { RadioTableStats []struct {
AstBeXmit interface{} `json:"ast_be_xmit"` AstBeXmit float64 `json:"ast_be_xmit"`
AstCst interface{} `json:"ast_cst"` AstCst float64 `json:"ast_cst"`
AstTxto interface{} `json:"ast_txto"` AstTxto float64 `json:"ast_txto"`
Channel float64 `json:"channel"` Channel float64 `json:"channel"`
CuSelfRx float64 `json:"cu_self_rx"` CuSelfRx float64 `json:"cu_self_rx"`
CuSelfTx float64 `json:"cu_self_tx"` CuSelfTx float64 `json:"cu_self_tx"`
CuTotal float64 `json:"cu_total"` CuTotal float64 `json:"cu_total"`
Extchannel float64 `json:"extchannel"` Extchannel float64 `json:"extchannel"`
Gain float64 `json:"gain"` Gain float64 `json:"gain"`
GuestNumSta float64 `json:"guest-num_sta"` GuestNumSta float64 `json:"guest-num_sta"`
Name string `json:"name"` Name string `json:"name"`
NumSta float64 `json:"num_sta"` NumSta float64 `json:"num_sta"`
Radio string `json:"radio"` Radio string `json:"radio"`
State string `json:"state"` State string `json:"state"`
TxPackets float64 `json:"tx_packets"` TxPackets float64 `json:"tx_packets"`
TxPower float64 `json:"tx_power"` TxPower float64 `json:"tx_power"`
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 bool `json:"rollupgrade"`
RxBytes int `json:"rx_bytes"` RxBytes float64 `json:"rx_bytes"`
RxBytesD int `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 bool `json:"scanning"`
Serial string `json:"serial"` Serial string `json:"serial"`
@ -257,12 +257,12 @@ type UAP struct {
} `json:"stat"` } `json:"stat"`
State int `json:"state"` State int `json:"state"`
SysStats struct { SysStats struct {
Loadavg1 string `json:"loadavg_1"` Loadavg1 string `json:"loadavg_1"`
Loadavg15 string `json:"loadavg_15"` Loadavg15 string `json:"loadavg_15"`
Loadavg5 string `json:"loadavg_5"` Loadavg5 string `json:"loadavg_5"`
MemBuffer int `json:"mem_buffer"` MemBuffer float64 `json:"mem_buffer"`
MemTotal int `json:"mem_total"` MemTotal float64 `json:"mem_total"`
MemUsed int `json:"mem_used"` MemUsed float64 `json:"mem_used"`
} `json:"sys_stats"` } `json:"sys_stats"`
SystemStats struct { SystemStats struct {
CPU string `json:"cpu"` CPU string `json:"cpu"`
@ -270,7 +270,7 @@ type UAP struct {
Uptime string `json:"uptime"` Uptime string `json:"uptime"`
} `json:"system-stats"` } `json:"system-stats"`
TxBytes float64 `json:"tx_bytes"` TxBytes float64 `json:"tx_bytes"`
TxBytesD int `json:"tx_bytes-d"` TxBytesD float64 `json:"tx_bytes-d"`
Type string `json:"type"` Type string `json:"type"`
Upgradable bool `json:"upgradable"` Upgradable bool `json:"upgradable"`
Uplink struct { Uplink struct {
@ -284,63 +284,63 @@ type UAP struct {
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 int `json:"rx_bytes-r"` RxBytesR float64 `json:"rx_bytes-r"`
RxDropped int `json:"rx_dropped"` RxDropped float64 `json:"rx_dropped"`
RxErrors int `json:"rx_errors"` RxErrors float64 `json:"rx_errors"`
RxMulticast int `json:"rx_multicast"` RxMulticast float64 `json:"rx_multicast"`
RxPackets int `json:"rx_packets"` RxPackets float64 `json:"rx_packets"`
Speed int `json:"speed"` Speed float64 `json:"speed"`
TxBytes float64 `json:"tx_bytes"` TxBytes float64 `json:"tx_bytes"`
TxBytesR int `json:"tx_bytes-r"` TxBytesR float64 `json:"tx_bytes-r"`
TxDropped int `json:"tx_dropped"` TxDropped float64 `json:"tx_dropped"`
TxErrors int `json:"tx_errors"` TxErrors float64 `json:"tx_errors"`
TxPackets int `json:"tx_packets"` TxPackets float64 `json:"tx_packets"`
Type string `json:"type"` Type string `json:"type"`
Up bool `json:"up"` Up bool `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 int `json:"uptime"` Uptime float64 `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 bool `json:"is_guest"`
IsWep bool `json:"is_wep"` IsWep bool `json:"is_wep"`
MacFilterRejections int `json:"mac_filter_rejections"` MacFilterRejections int `json:"mac_filter_rejections"`
MapID interface{} `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 int `json:"rx_bytes"` RxBytes float64 `json:"rx_bytes"`
RxCrypts int `json:"rx_crypts"` RxCrypts float64 `json:"rx_crypts"`
RxDropped int `json:"rx_dropped"` RxDropped float64 `json:"rx_dropped"`
RxErrors int `json:"rx_errors"` RxErrors float64 `json:"rx_errors"`
RxFrags int `json:"rx_frags"` RxFrags float64 `json:"rx_frags"`
RxNwids int `json:"rx_nwids"` RxNwids float64 `json:"rx_nwids"`
RxPackets int `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 int `json:"tx_bytes"` TxBytes float64 `json:"tx_bytes"`
TxDropped int `json:"tx_dropped"` TxDropped float64 `json:"tx_dropped"`
TxErrors int `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 int `json:"tx_packets"` TxPackets float64 `json:"tx_packets"`
TxPower int `json:"tx_power"` TxPower int `json:"tx_power"`
TxRetries int `json:"tx_retries"` TxRetries int `json:"tx_retries"`
Up bool `json:"up"` Up bool `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 bool `json:"version_incompatible"`