/
influx_usw.go
148 lines (145 loc) · 5.11 KB
/
influx_usw.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
package unifipoller
import (
"time"
influx "github.com/influxdata/influxdb1-client/v2"
"golift.io/unifi"
)
// USWPoints generates Unifi Switch datapoints for InfluxDB.
// These points can be passed directly to influx.
func USWPoints(u *unifi.USW, now time.Time) ([]*influx.Point, error) {
if u.Stat.Sw == nil {
u.Stat.Sw = &unifi.Sw{}
}
tags := map[string]string{
"id": u.ID,
"mac": u.Mac,
"device_oid": u.Stat.Oid,
"site_id": u.SiteID,
"site_name": u.SiteName,
"name": u.Name,
"adopted": u.Adopted.Txt,
"cfgversion": u.Cfgversion,
"config_network_ip": u.ConfigNetwork.IP,
"config_network_type": u.ConfigNetwork.Type,
"device_id": u.DeviceID,
"inform_ip": u.InformIP,
"known_cfgversion": u.KnownCfgversion,
"locating": u.Locating.Txt,
"model": u.Model,
"serial": u.Serial,
"type": u.Type,
"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_version": u.StpVersion,
}
fields := map[string]interface{}{
"fw_caps": u.FwCaps.Val,
"guest-num_sta": u.GuestNumSta.Val,
"ip": u.IP,
"bytes": u.Bytes.Val,
"fan_level": u.FanLevel.Val,
"general_temperature": u.GeneralTemperature.Val,
"last_seen": u.LastSeen.Val,
"license_state": u.LicenseState,
"overheating": u.Overheating.Val,
"rx_bytes": u.RxBytes.Val,
"tx_bytes": u.TxBytes.Val,
"uptime": u.Uptime.Val,
"state": u.State.Val,
"user-num_sta": u.UserNumSta.Val,
"version": u.Version,
"loadavg_1": u.SysStats.Loadavg1.Val,
"loadavg_5": u.SysStats.Loadavg5.Val,
"loadavg_15": u.SysStats.Loadavg15.Val,
"mem_buffer": u.SysStats.MemBuffer.Val,
"mem_used": u.SysStats.MemUsed.Val,
"mem_total": u.SysStats.MemTotal.Val,
"cpu": u.SystemStats.CPU.Val,
"mem": u.SystemStats.Mem.Val,
"stp_priority": u.StpPriority.Val,
"system_uptime": u.SystemStats.Uptime.Val,
"stat_bytes": u.Stat.Bytes.Val,
"stat_rx_bytes": u.Stat.RxBytes.Val,
"stat_rx_crypts": u.Stat.RxCrypts.Val,
"stat_rx_dropped": u.Stat.RxDropped.Val,
"stat_rx_errors": u.Stat.RxErrors.Val,
"stat_rx_frags": u.Stat.RxFrags.Val,
"stat_rx_packets": u.Stat.TxPackets.Val,
"stat_tx_bytes": u.Stat.TxBytes.Val,
"stat_tx_dropped": u.Stat.TxDropped.Val,
"stat_tx_errors": u.Stat.TxErrors.Val,
"stat_tx_packets": u.Stat.TxPackets.Val,
"stat_tx_retries": u.Stat.TxRetries.Val,
"uplink_depth": u.UplinkDepth.Txt,
}
pt, err := influx.NewPoint("usw", tags, fields, now)
if err != nil {
return nil, err
}
points := []*influx.Point{pt}
for _, p := range u.PortTable {
tags := map[string]string{
"site_id": u.SiteID,
"site_name": u.SiteName,
"device_name": u.Name,
"name": p.Name,
"enable": p.Enable.Txt,
"is_uplink": p.IsUplink.Txt,
"up": p.Up.Txt,
"portconf_id": p.PortconfID,
"dot1x_mode": p.Dot1XMode,
"dot1x_status": p.Dot1XStatus,
"stp_state": p.StpState,
"sfp_found": p.SfpFound.Txt,
"op_mode": p.OpMode,
"poe_mode": p.PoeMode,
"port_poe": p.PortPoe.Txt,
"port_idx": p.PortIdx.Txt,
"port_id": u.Name + " Port " + p.PortIdx.Txt,
"poe_enable": p.PoeEnable.Txt,
"flowctrl_rx": p.FlowctrlRx.Txt,
"flowctrl_tx": p.FlowctrlTx.Txt,
"autoneg": p.Autoneg.Txt,
"full_duplex": p.FullDuplex.Txt,
"jumbo": p.Jumbo.Txt,
"masked": p.Masked.Txt,
"poe_good": p.PoeGood.Txt,
"media": p.Media,
"poe_class": p.PoeClass,
"poe_caps": p.PoeCaps.Txt,
"aggregated_by": p.AggregatedBy.Txt,
}
fields := map[string]interface{}{
"dbytes_r": p.BytesR.Val,
"rx_broadcast": p.RxBroadcast.Val,
"rx_bytes": p.RxBytes.Val,
"rx_bytes-r": p.RxBytesR.Val,
"rx_dropped": p.RxDropped.Val,
"rx_errors": p.RxErrors.Val,
"rx_multicast": p.RxMulticast.Val,
"rx_packets": p.RxPackets.Val,
"speed": p.Speed.Val,
"stp_pathcost": p.StpPathcost.Val,
"tx_broadcast": p.TxBroadcast.Val,
"tx_bytes": p.TxBytes.Val,
"tx_bytes-r": p.TxBytesR.Val,
"tx_dropped": p.TxDropped.Val,
"tx_errors": p.TxErrors.Val,
"tx_multicast": p.TxMulticast.Val,
"tx_packets": p.TxPackets.Val,
"poe_current": p.PoeCurrent.Val,
"poe_power": p.PoePower.Val,
"poe_voltage": p.PoeVoltage.Val,
"full_duplex": p.FullDuplex.Val,
}
pt, err = influx.NewPoint("usw_ports", tags, fields, now)
if err != nil {
return points, err
}
points = append(points, pt)
}
return points, nil
}