Skip to content

Commit 968c5bd

Browse files
updates lib for integration tests in unpoller + linting
1 parent cb0eebf commit 968c5bd

18 files changed

+641
-595
lines changed

alarms.go

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,51 +7,51 @@ import (
77
)
88

99
type Alarm struct {
10-
Archived FlexBool `json:"archived"`
11-
DestPort int `fake:"{port}" json:"dest_port"`
12-
SrcPort int `fake:"{port}" json:"src_port"`
13-
FlowID int64 `json:"flow_id"`
14-
InnerAlertGID int64 `json:"inner_alert_gid"`
15-
InnerAlertRev int64 `json:"inner_alert_rev"`
16-
InnerAlertSeverity int64 `json:"inner_alert_severity"`
17-
InnerAlertSignatureID int64 `json:"inner_alert_signature_id"`
18-
Time int64 `fake:"{timestamp}" json:"time"`
19-
Timestamp int64 `fake:"{timestamp}" json:"timestamp"`
20-
Datetime time.Time `json:"datetime"`
21-
HandledTime time.Time `json:"handled_time,omitempty"`
2210
AppProto string `json:"app_proto,omitempty"`
11+
Archived FlexBool `json:"archived"`
2312
Catname string `json:"catname"`
13+
Datetime time.Time `fake:"{recent_time}" json:"datetime"`
2414
DestIP string `fake:"{ipv4address}" json:"dest_ip"`
25-
DstMAC string `fake:"{macaddress}" json:"dst_mac"`
15+
DestIPGeo IPGeo `json:"dstipGeo"`
16+
DestPort int `fake:"{port}" json:"dest_port"`
2617
DstIPASN string `json:"dstipASN,omitempty"`
2718
DstIPCountry string `json:"dstipCountry,omitempty"`
19+
DstMAC string `fake:"{macaddress}" json:"dst_mac"`
2820
EventType string `json:"event_type"`
21+
FlowID int64 `json:"flow_id"`
2922
HandledAdminID string `json:"handled_admin_id,omitempty"`
23+
HandledTime time.Time `json:"handled_time,omitempty"`
3024
Host string `json:"host"`
3125
ID string `fake:"{uuid}" json:"_id"`
3226
InIface string `fake:"{randomstring:[eth0,eth1,lan1,wan1,wan2]}" json:"in_iface"`
3327
InnerAlertAction string `json:"inner_alert_action"`
3428
InnerAlertCategory string `json:"inner_alert_category"`
29+
InnerAlertGID int64 `json:"inner_alert_gid"`
30+
InnerAlertRev int64 `json:"inner_alert_rev"`
31+
InnerAlertSeverity int64 `json:"inner_alert_severity"`
3532
InnerAlertSignature string `json:"inner_alert_signature"`
33+
InnerAlertSignatureID int64 `json:"inner_alert_signature_id"`
3634
Key string `json:"key"`
3735
Msg string `fake:"{sentence:5}" json:"msg"`
3836
Proto string `json:"proto"`
3937
SiteID string `fake:"{uuid}" json:"site_id"`
4038
SiteName string `json:"-"`
39+
SourceIPGeo IPGeo `json:"usgipGeo"`
4140
SourceName string `json:"-"`
4241
SrcIP string `fake:"{ipv4address}" json:"src_ip"`
4342
SrcIPASN string `json:"srcipASN,omitempty"`
4443
SrcIPCountry string `json:"srcipCountry,omitempty"`
4544
SrcMAC string `fake:"{macaddress}" json:"src_mac"`
45+
SrcPort int `fake:"{port}" json:"src_port"`
4646
Subsystem string `json:"subsystem"`
47-
UniqueAlertID string `json:"unique_alertid"`
47+
Time int64 `fake:"{timestamp}" json:"time"`
48+
Timestamp int64 `fake:"{timestamp}" json:"timestamp"`
49+
TxID FlexInt `json:"tx_id,omitempty"`
4850
USGIP string `fake:"{ipv4address}" json:"usgip"`
4951
USGIPASN string `json:"usgipASN"`
5052
USGIPCountry string `json:"usgipCountry"`
51-
TxID FlexInt `json:"tx_id,omitempty"`
52-
DestIPGeo IPGeo `json:"dstipGeo"`
53-
SourceIPGeo IPGeo `json:"usgipGeo"`
5453
USGIPGeo IPGeo `json:"srcipGeo,omitempty"`
54+
UniqueAlertID string `json:"unique_alertid"`
5555
}
5656

5757
// GetAlarms returns Alarms for a list of Sites.

anomalies.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ type anomaly struct {
1717

1818
// Anomaly is the reformatted data type that this library returns.
1919
type Anomaly struct {
20-
Datetime time.Time
21-
SourceName string
22-
SiteName string
20+
// DeviceName string // we do not have this....
2321
Anomaly string
22+
Datetime time.Time `fake:"{recent_time}"`
2423
DeviceMAC string `fake:"{macaddress}"`
25-
// DeviceName string // we do not have this....
24+
SiteName string
25+
SourceName string
2626
}
2727

2828
// GetAnomalies returns Anomalies for a list of Sites.

clients.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ func (u *Unifi) GetClientsDPI(sites []*Site) ([]*DPITable, error) {
6565

6666
// Client defines all the data a connected-network client contains.
6767
type Client struct {
68-
SourceName string `json:"-"`
6968
Anomalies FlexInt `json:"anomalies,omitempty"`
7069
ApMac string `fake:"{macaddress}" json:"ap_mac"`
7170
ApName string `json:"-"`
@@ -80,7 +79,6 @@ type Client struct {
8079
DevID FlexInt `json:"dev_id"`
8180
DevVendor FlexInt `json:"dev_vendor,omitempty"`
8281
DhcpendTime FlexInt `json:"dhcpend_time,omitempty"`
83-
Satisfaction FlexInt `json:"satisfaction,omitempty"`
8482
Essid string `fake:"{macaddress}" json:"essid"`
8583
FirstSeen FlexInt `json:"first_seen"`
8684
FixedIP string `fake:"{ipv4address}" json:"fixed_ip"`
@@ -114,28 +112,30 @@ type Client struct {
114112
PowersaveEnabled FlexBool `json:"powersave_enabled"`
115113
QosPolicyApplied FlexBool `json:"qos_policy_applied"`
116114
Radio string `json:"radio"`
115+
RadioDescription string `json:"-"`
117116
RadioName string `json:"radio_name"`
118117
RadioProto string `json:"radio_proto"`
119-
RadioDescription string `json:"-"`
120118
RoamCount FlexInt `json:"roam_count"`
121119
Rssi FlexInt `json:"rssi"`
122120
RxBytes FlexInt `json:"rx_bytes"`
123121
RxBytesR FlexInt `json:"rx_bytes-r"`
124122
RxPackets FlexInt `json:"rx_packets"`
125123
RxRate FlexInt `json:"rx_rate"`
124+
Satisfaction FlexInt `json:"satisfaction,omitempty"`
126125
Signal FlexInt `json:"signal"`
127126
SiteID string `fake:"{uuid}" json:"site_id"`
128127
SiteName string `json:"-"`
128+
SourceName string `json:"-"`
129129
SwDepth int `json:"sw_depth"`
130130
SwMac string `fake:"{macaddress}" json:"sw_mac"`
131131
SwName string `json:"-"`
132132
SwPort FlexInt `json:"sw_port"`
133133
TxBytes FlexInt `json:"tx_bytes"`
134134
TxBytesR FlexInt `json:"tx_bytes-r"`
135135
TxPackets FlexInt `json:"tx_packets"`
136-
TxRetries FlexInt `json:"tx_retries"`
137136
TxPower FlexInt `json:"tx_power"`
138137
TxRate FlexInt `json:"tx_rate"`
138+
TxRetries FlexInt `json:"tx_retries"`
139139
Uptime FlexInt `json:"uptime"`
140140
UptimeByUAP FlexInt `json:"_uptime_by_uap"`
141141
UptimeByUGW FlexInt `json:"_uptime_by_ugw"`

devmgr.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ const (
2727
// devMgrCmd is the type marshalled and sent to APIDevMgrPath.
2828
type devMgrCmd struct {
2929
Cmd string `json:"cmd"` // Required.
30-
Mac string `fake:"{macaddress}" json:"mac"` // Device MAC (required for most, but not all).
31-
URL string `fake:"{url}" json:"url,omitempty"` // External Upgrade only.
3230
Inform string `fake:"{url}" json:"inform_url,omitempty"` // Migration only.
31+
Mac string `fake:"{macaddress}" json:"mac"` // Device MAC (required for most, but not all).
3332
Port int `json:"port_idx,omitempty"` // Power Cycle only.
33+
URL string `fake:"{url}" json:"url,omitempty"` // External Upgrade only.
3434
}
3535

3636
// devMgrCommandReply is for commands with a return value.

dpi.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,33 +4,33 @@ import "strconv"
44

55
// DPITable contains DPI data for clients or sites, or .. things.
66
type DPITable struct {
7-
SourceName string `json:"-"`
8-
SiteName string `json:"-"`
9-
Name string `json:"-"`
10-
MAC string `fake:"{macaddress}" json:"mac"`
11-
ByCat []DPIData `fakesize:"5" json:"by_cat"`
127
ByApp []DPIData `fakesize:"5" json:"by_app"`
8+
ByCat []DPIData `fakesize:"5" json:"by_cat"`
139
LastUpdated FlexInt `json:"last_updated"`
10+
MAC string `fake:"{macaddress}" json:"mac"`
11+
Name string `json:"-"`
12+
SiteName string `json:"-"`
13+
SourceName string `json:"-"`
1414
}
1515

1616
// DPIData is the DPI data in the DPI table.
1717
type DPIData struct {
18-
Cat FlexInt `json:"cat"`
1918
App FlexInt `json:"app"`
19+
Cat FlexInt `json:"cat"`
20+
Clients []*DPIClient `fakesize:"5" json:"clients,omitempty"`
21+
KnownClients FlexInt `json:"known_clients,omitempty"`
2022
RxBytes FlexInt `json:"rx_bytes"`
21-
TxBytes FlexInt `json:"tx_bytes"`
2223
RxPackets FlexInt `json:"rx_packets"`
24+
TxBytes FlexInt `json:"tx_bytes"`
2325
TxPackets FlexInt `json:"tx_packets"`
24-
Clients []*DPIClient `fakesize:"5" json:"clients,omitempty"`
25-
KnownClients FlexInt `json:"known_clients,omitempty"`
2626
}
2727

2828
// DPIClient data is sometimes included in ByApp output.
2929
type DPIClient struct {
3030
Mac string `fake:"{macaddress}" json:"mac"`
3131
RxBytes FlexInt `json:"rx_bytes"`
32-
TxBytes FlexInt `json:"tx_bytes"`
3332
RxPackets FlexInt `json:"rx_packets"`
33+
TxBytes FlexInt `json:"tx_bytes"`
3434
TxPackets FlexInt `json:"tx_packets"`
3535
}
3636

events.go

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -72,32 +72,25 @@ func (u *Unifi) GetSiteEvents(site *Site, hours time.Duration) ([]*Event, error)
7272
// Event describes a UniFi Event.
7373
// API Path: /api/s/default/stat/event.
7474
type Event struct {
75-
IsAdmin FlexBool `json:"is_admin"`
76-
DestPort int `fake:"{port}" json:"dest_port"`
77-
SrcPort int `fake:"{port}" json:"src_port"`
78-
Bytes FlexInt `json:"bytes"`
79-
Duration FlexInt `json:"duration"`
80-
FlowID FlexInt `json:"flow_id"`
81-
InnerAlertGID FlexInt `json:"inner_alert_gid"`
82-
InnerAlertRev FlexInt `json:"inner_alert_rev"`
83-
InnerAlertSeverity FlexInt `json:"inner_alert_severity"`
84-
InnerAlertSignatureID FlexInt `json:"inner_alert_signature_id"`
85-
Channel FlexInt `json:"channel"`
86-
ChannelFrom FlexInt `json:"channel_from"`
87-
ChannelTo FlexInt `json:"channel_to"`
88-
Time int64 `fake:"{timestamp}" json:"time"`
89-
Timestamp int64 `fake:"{timestamp}" json:"timestamp"`
90-
Datetime time.Time `json:"datetime"`
9175
Admin string `json:"admin"`
9276
Ap string `json:"ap"`
9377
ApFrom string `json:"ap_from"`
9478
ApName string `json:"ap_name"`
9579
ApTo string `json:"ap_to"`
9680
AppProto string `json:"app_proto"`
81+
Bytes FlexInt `json:"bytes"`
9782
Catname string `json:"catname"`
83+
Channel FlexInt `json:"channel"`
84+
ChannelFrom FlexInt `json:"channel_from"`
85+
ChannelTo FlexInt `json:"channel_to"`
86+
Datetime time.Time `fake:"{recent_time}" json:"datetime"`
9887
DestIP string `fake:"{ipv4address}" json:"dest_ip"`
88+
DestIPGeo IPGeo `json:"dstipGeo"`
89+
DestPort int `fake:"{port}" json:"dest_port"`
9990
DstMAC string `fake:"{macaddress}" json:"dst_mac"`
91+
Duration FlexInt `json:"duration"`
10092
EventType string `json:"event_type"`
93+
FlowID FlexInt `json:"flow_id"`
10194
Guest string `json:"guest"`
10295
Gw string `json:"gw"`
10396
GwName string `json:"gw_name"`
@@ -108,45 +101,52 @@ type Event struct {
108101
InIface string `json:"in_iface"`
109102
InnerAlertAction string `json:"inner_alert_action"`
110103
InnerAlertCategory string `json:"inner_alert_category"`
104+
InnerAlertGID FlexInt `json:"inner_alert_gid"`
105+
InnerAlertRev FlexInt `json:"inner_alert_rev"`
106+
InnerAlertSeverity FlexInt `json:"inner_alert_severity"`
111107
InnerAlertSignature string `json:"inner_alert_signature"`
108+
InnerAlertSignatureID FlexInt `json:"inner_alert_signature_id"`
109+
IsAdmin FlexBool `json:"is_admin"`
112110
Key string `fake:"{uuid}" json:"key"`
113111
Msg string `fake:"{buzzword}" json:"msg"`
114112
Network string `json:"network"`
115113
Proto string `json:"proto"`
116114
Radio string `json:"radio"`
117115
RadioFrom string `json:"radio_from"`
118116
RadioTo string `json:"radio_to"`
117+
SSID string `fake:"{macaddress}" json:"ssid"`
119118
SiteID string `fake:"{}" json:"site_id"`
120119
SiteName string `json:"-"`
120+
SourceIPGeo IPGeo `json:"srcipGeo"`
121121
SourceName string `json:"-"`
122122
SrcIP string `fake:"{ipv4address}" json:"src_ip"`
123-
SrcMAC string `fake:"{macaddress}" json:"src_mac"`
124123
SrcIPASN string `fake:"{address}" json:"srcipASN"`
125124
SrcIPCountry string `fake:"{country}" json:"srcipCountry"`
126-
SSID string `fake:"{macaddress}" json:"ssid"`
125+
SrcMAC string `fake:"{macaddress}" json:"src_mac"`
126+
SrcPort int `fake:"{port}" json:"src_port"`
127127
Subsystem string `json:"subsystem"`
128128
Sw string `json:"sw"`
129129
SwName string `json:"sw_name"`
130-
UniqueAlertID string `json:"unique_alertid"`
131-
User string `json:"user"`
130+
Time int64 `fake:"{timestamp}" json:"time"`
131+
Timestamp int64 `fake:"{timestamp}" json:"timestamp"`
132132
USGIP string `fake:"{ipv4address}" json:"usgip"`
133133
USGIPASN string `fake:"{address}" json:"usgipASN"`
134134
USGIPCountry string `fake:"{country}" json:"usgipCountry"`
135-
DestIPGeo IPGeo `json:"dstipGeo"`
136-
SourceIPGeo IPGeo `json:"srcipGeo"`
137135
USGIPGeo IPGeo `json:"usgipGeo"`
136+
UniqueAlertID string `json:"unique_alertid"`
137+
User string `json:"user"`
138138
}
139139

140140
// IPGeo is part of the UniFi Event data. Each event may have up to three of these.
141141
// One for source, one for dest and one for the USG location.
142142
type IPGeo struct {
143143
Asn int64 `json:"asn"`
144-
Latitude float64 `fake:"{latitude}" json:"latitude"`
145-
Longitude float64 `fake:"{longitude}" json:"longitude"`
146144
City string `fake:"{city}" json:"city"`
147145
ContinentCode string `json:"continent_code"`
148146
CountryCode string `fake:"{countryabr}" json:"country_code"`
149147
CountryName string `fake:"{country}" json:"country_name"`
148+
Latitude float64 `fake:"{latitude}" json:"latitude"`
149+
Longitude float64 `fake:"{longitude}" json:"longitude"`
150150
Organization string `fake:"{company}" json:"organization"`
151151
}
152152

@@ -177,12 +177,12 @@ func (v *IPGeo) UnmarshalJSON(data []byte) error {
177177

178178
g := struct {
179179
Asn int64 `json:"asn"`
180-
Latitude float64 `json:"latitude"`
181-
Longitude float64 `json:"longitude"`
182180
City string `json:"city"`
183181
ContinentCode string `json:"continent_code"`
184182
CountryCode string `json:"country_code"`
185183
CountryName string `json:"country_name"`
184+
Latitude float64 `json:"latitude"`
185+
Longitude float64 `json:"longitude"`
186186
Organization string `json:"organization"`
187187
}{}
188188

0 commit comments

Comments
 (0)