Skip to content

Commit

Permalink
Merge pull request #93 from unpoller/integration-testing-and-lint
Browse files Browse the repository at this point in the history
updates lib for integration tests in unpoller + linting
  • Loading branch information
platinummonkey committed Jul 31, 2023
2 parents cb0eebf + 968c5bd commit e1e5f22
Show file tree
Hide file tree
Showing 18 changed files with 641 additions and 595 deletions.
34 changes: 17 additions & 17 deletions alarms.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,51 +7,51 @@ import (
)

type Alarm struct {
Archived FlexBool `json:"archived"`
DestPort int `fake:"{port}" json:"dest_port"`
SrcPort int `fake:"{port}" json:"src_port"`
FlowID int64 `json:"flow_id"`
InnerAlertGID int64 `json:"inner_alert_gid"`
InnerAlertRev int64 `json:"inner_alert_rev"`
InnerAlertSeverity int64 `json:"inner_alert_severity"`
InnerAlertSignatureID int64 `json:"inner_alert_signature_id"`
Time int64 `fake:"{timestamp}" json:"time"`
Timestamp int64 `fake:"{timestamp}" json:"timestamp"`
Datetime time.Time `json:"datetime"`
HandledTime time.Time `json:"handled_time,omitempty"`
AppProto string `json:"app_proto,omitempty"`
Archived FlexBool `json:"archived"`
Catname string `json:"catname"`
Datetime time.Time `fake:"{recent_time}" json:"datetime"`
DestIP string `fake:"{ipv4address}" json:"dest_ip"`
DstMAC string `fake:"{macaddress}" json:"dst_mac"`
DestIPGeo IPGeo `json:"dstipGeo"`
DestPort int `fake:"{port}" json:"dest_port"`
DstIPASN string `json:"dstipASN,omitempty"`
DstIPCountry string `json:"dstipCountry,omitempty"`
DstMAC string `fake:"{macaddress}" json:"dst_mac"`
EventType string `json:"event_type"`
FlowID int64 `json:"flow_id"`
HandledAdminID string `json:"handled_admin_id,omitempty"`
HandledTime time.Time `json:"handled_time,omitempty"`
Host string `json:"host"`
ID string `fake:"{uuid}" json:"_id"`
InIface string `fake:"{randomstring:[eth0,eth1,lan1,wan1,wan2]}" json:"in_iface"`
InnerAlertAction string `json:"inner_alert_action"`
InnerAlertCategory string `json:"inner_alert_category"`
InnerAlertGID int64 `json:"inner_alert_gid"`
InnerAlertRev int64 `json:"inner_alert_rev"`
InnerAlertSeverity int64 `json:"inner_alert_severity"`
InnerAlertSignature string `json:"inner_alert_signature"`
InnerAlertSignatureID int64 `json:"inner_alert_signature_id"`
Key string `json:"key"`
Msg string `fake:"{sentence:5}" json:"msg"`
Proto string `json:"proto"`
SiteID string `fake:"{uuid}" json:"site_id"`
SiteName string `json:"-"`
SourceIPGeo IPGeo `json:"usgipGeo"`
SourceName string `json:"-"`
SrcIP string `fake:"{ipv4address}" json:"src_ip"`
SrcIPASN string `json:"srcipASN,omitempty"`
SrcIPCountry string `json:"srcipCountry,omitempty"`
SrcMAC string `fake:"{macaddress}" json:"src_mac"`
SrcPort int `fake:"{port}" json:"src_port"`
Subsystem string `json:"subsystem"`
UniqueAlertID string `json:"unique_alertid"`
Time int64 `fake:"{timestamp}" json:"time"`
Timestamp int64 `fake:"{timestamp}" json:"timestamp"`
TxID FlexInt `json:"tx_id,omitempty"`
USGIP string `fake:"{ipv4address}" json:"usgip"`
USGIPASN string `json:"usgipASN"`
USGIPCountry string `json:"usgipCountry"`
TxID FlexInt `json:"tx_id,omitempty"`
DestIPGeo IPGeo `json:"dstipGeo"`
SourceIPGeo IPGeo `json:"usgipGeo"`
USGIPGeo IPGeo `json:"srcipGeo,omitempty"`
UniqueAlertID string `json:"unique_alertid"`
}

// GetAlarms returns Alarms for a list of Sites.
Expand Down
8 changes: 4 additions & 4 deletions anomalies.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ type anomaly struct {

// Anomaly is the reformatted data type that this library returns.
type Anomaly struct {
Datetime time.Time
SourceName string
SiteName string
// DeviceName string // we do not have this....
Anomaly string
Datetime time.Time `fake:"{recent_time}"`
DeviceMAC string `fake:"{macaddress}"`
// DeviceName string // we do not have this....
SiteName string
SourceName string
}

// GetAnomalies returns Anomalies for a list of Sites.
Expand Down
8 changes: 4 additions & 4 deletions clients.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ func (u *Unifi) GetClientsDPI(sites []*Site) ([]*DPITable, error) {

// Client defines all the data a connected-network client contains.
type Client struct {
SourceName string `json:"-"`
Anomalies FlexInt `json:"anomalies,omitempty"`
ApMac string `fake:"{macaddress}" json:"ap_mac"`
ApName string `json:"-"`
Expand All @@ -80,7 +79,6 @@ type Client struct {
DevID FlexInt `json:"dev_id"`
DevVendor FlexInt `json:"dev_vendor,omitempty"`
DhcpendTime FlexInt `json:"dhcpend_time,omitempty"`
Satisfaction FlexInt `json:"satisfaction,omitempty"`
Essid string `fake:"{macaddress}" json:"essid"`
FirstSeen FlexInt `json:"first_seen"`
FixedIP string `fake:"{ipv4address}" json:"fixed_ip"`
Expand Down Expand Up @@ -114,28 +112,30 @@ type Client struct {
PowersaveEnabled FlexBool `json:"powersave_enabled"`
QosPolicyApplied FlexBool `json:"qos_policy_applied"`
Radio string `json:"radio"`
RadioDescription string `json:"-"`
RadioName string `json:"radio_name"`
RadioProto string `json:"radio_proto"`
RadioDescription string `json:"-"`
RoamCount FlexInt `json:"roam_count"`
Rssi FlexInt `json:"rssi"`
RxBytes FlexInt `json:"rx_bytes"`
RxBytesR FlexInt `json:"rx_bytes-r"`
RxPackets FlexInt `json:"rx_packets"`
RxRate FlexInt `json:"rx_rate"`
Satisfaction FlexInt `json:"satisfaction,omitempty"`
Signal FlexInt `json:"signal"`
SiteID string `fake:"{uuid}" json:"site_id"`
SiteName string `json:"-"`
SourceName string `json:"-"`
SwDepth int `json:"sw_depth"`
SwMac string `fake:"{macaddress}" json:"sw_mac"`
SwName string `json:"-"`
SwPort FlexInt `json:"sw_port"`
TxBytes FlexInt `json:"tx_bytes"`
TxBytesR FlexInt `json:"tx_bytes-r"`
TxPackets FlexInt `json:"tx_packets"`
TxRetries FlexInt `json:"tx_retries"`
TxPower FlexInt `json:"tx_power"`
TxRate FlexInt `json:"tx_rate"`
TxRetries FlexInt `json:"tx_retries"`
Uptime FlexInt `json:"uptime"`
UptimeByUAP FlexInt `json:"_uptime_by_uap"`
UptimeByUGW FlexInt `json:"_uptime_by_ugw"`
Expand Down
4 changes: 2 additions & 2 deletions devmgr.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ const (
// devMgrCmd is the type marshalled and sent to APIDevMgrPath.
type devMgrCmd struct {
Cmd string `json:"cmd"` // Required.
Mac string `fake:"{macaddress}" json:"mac"` // Device MAC (required for most, but not all).
URL string `fake:"{url}" json:"url,omitempty"` // External Upgrade only.
Inform string `fake:"{url}" json:"inform_url,omitempty"` // Migration only.
Mac string `fake:"{macaddress}" json:"mac"` // Device MAC (required for most, but not all).
Port int `json:"port_idx,omitempty"` // Power Cycle only.
URL string `fake:"{url}" json:"url,omitempty"` // External Upgrade only.
}

// devMgrCommandReply is for commands with a return value.
Expand Down
20 changes: 10 additions & 10 deletions dpi.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,33 @@ import "strconv"

// DPITable contains DPI data for clients or sites, or .. things.
type DPITable struct {
SourceName string `json:"-"`
SiteName string `json:"-"`
Name string `json:"-"`
MAC string `fake:"{macaddress}" json:"mac"`
ByCat []DPIData `fakesize:"5" json:"by_cat"`
ByApp []DPIData `fakesize:"5" json:"by_app"`
ByCat []DPIData `fakesize:"5" json:"by_cat"`
LastUpdated FlexInt `json:"last_updated"`
MAC string `fake:"{macaddress}" json:"mac"`
Name string `json:"-"`
SiteName string `json:"-"`
SourceName string `json:"-"`
}

// DPIData is the DPI data in the DPI table.
type DPIData struct {
Cat FlexInt `json:"cat"`
App FlexInt `json:"app"`
Cat FlexInt `json:"cat"`
Clients []*DPIClient `fakesize:"5" json:"clients,omitempty"`
KnownClients FlexInt `json:"known_clients,omitempty"`
RxBytes FlexInt `json:"rx_bytes"`
TxBytes FlexInt `json:"tx_bytes"`
RxPackets FlexInt `json:"rx_packets"`
TxBytes FlexInt `json:"tx_bytes"`
TxPackets FlexInt `json:"tx_packets"`
Clients []*DPIClient `fakesize:"5" json:"clients,omitempty"`
KnownClients FlexInt `json:"known_clients,omitempty"`
}

// DPIClient data is sometimes included in ByApp output.
type DPIClient struct {
Mac string `fake:"{macaddress}" json:"mac"`
RxBytes FlexInt `json:"rx_bytes"`
TxBytes FlexInt `json:"tx_bytes"`
RxPackets FlexInt `json:"rx_packets"`
TxBytes FlexInt `json:"tx_bytes"`
TxPackets FlexInt `json:"tx_packets"`
}

Expand Down
52 changes: 26 additions & 26 deletions events.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,32 +72,25 @@ func (u *Unifi) GetSiteEvents(site *Site, hours time.Duration) ([]*Event, error)
// Event describes a UniFi Event.
// API Path: /api/s/default/stat/event.
type Event struct {
IsAdmin FlexBool `json:"is_admin"`
DestPort int `fake:"{port}" json:"dest_port"`
SrcPort int `fake:"{port}" json:"src_port"`
Bytes FlexInt `json:"bytes"`
Duration FlexInt `json:"duration"`
FlowID FlexInt `json:"flow_id"`
InnerAlertGID FlexInt `json:"inner_alert_gid"`
InnerAlertRev FlexInt `json:"inner_alert_rev"`
InnerAlertSeverity FlexInt `json:"inner_alert_severity"`
InnerAlertSignatureID FlexInt `json:"inner_alert_signature_id"`
Channel FlexInt `json:"channel"`
ChannelFrom FlexInt `json:"channel_from"`
ChannelTo FlexInt `json:"channel_to"`
Time int64 `fake:"{timestamp}" json:"time"`
Timestamp int64 `fake:"{timestamp}" json:"timestamp"`
Datetime time.Time `json:"datetime"`
Admin string `json:"admin"`
Ap string `json:"ap"`
ApFrom string `json:"ap_from"`
ApName string `json:"ap_name"`
ApTo string `json:"ap_to"`
AppProto string `json:"app_proto"`
Bytes FlexInt `json:"bytes"`
Catname string `json:"catname"`
Channel FlexInt `json:"channel"`
ChannelFrom FlexInt `json:"channel_from"`
ChannelTo FlexInt `json:"channel_to"`
Datetime time.Time `fake:"{recent_time}" json:"datetime"`
DestIP string `fake:"{ipv4address}" json:"dest_ip"`
DestIPGeo IPGeo `json:"dstipGeo"`
DestPort int `fake:"{port}" json:"dest_port"`
DstMAC string `fake:"{macaddress}" json:"dst_mac"`
Duration FlexInt `json:"duration"`
EventType string `json:"event_type"`
FlowID FlexInt `json:"flow_id"`
Guest string `json:"guest"`
Gw string `json:"gw"`
GwName string `json:"gw_name"`
Expand All @@ -108,45 +101,52 @@ type Event struct {
InIface string `json:"in_iface"`
InnerAlertAction string `json:"inner_alert_action"`
InnerAlertCategory string `json:"inner_alert_category"`
InnerAlertGID FlexInt `json:"inner_alert_gid"`
InnerAlertRev FlexInt `json:"inner_alert_rev"`
InnerAlertSeverity FlexInt `json:"inner_alert_severity"`
InnerAlertSignature string `json:"inner_alert_signature"`
InnerAlertSignatureID FlexInt `json:"inner_alert_signature_id"`
IsAdmin FlexBool `json:"is_admin"`
Key string `fake:"{uuid}" json:"key"`
Msg string `fake:"{buzzword}" json:"msg"`
Network string `json:"network"`
Proto string `json:"proto"`
Radio string `json:"radio"`
RadioFrom string `json:"radio_from"`
RadioTo string `json:"radio_to"`
SSID string `fake:"{macaddress}" json:"ssid"`
SiteID string `fake:"{}" json:"site_id"`
SiteName string `json:"-"`
SourceIPGeo IPGeo `json:"srcipGeo"`
SourceName string `json:"-"`
SrcIP string `fake:"{ipv4address}" json:"src_ip"`
SrcMAC string `fake:"{macaddress}" json:"src_mac"`
SrcIPASN string `fake:"{address}" json:"srcipASN"`
SrcIPCountry string `fake:"{country}" json:"srcipCountry"`
SSID string `fake:"{macaddress}" json:"ssid"`
SrcMAC string `fake:"{macaddress}" json:"src_mac"`
SrcPort int `fake:"{port}" json:"src_port"`
Subsystem string `json:"subsystem"`
Sw string `json:"sw"`
SwName string `json:"sw_name"`
UniqueAlertID string `json:"unique_alertid"`
User string `json:"user"`
Time int64 `fake:"{timestamp}" json:"time"`
Timestamp int64 `fake:"{timestamp}" json:"timestamp"`
USGIP string `fake:"{ipv4address}" json:"usgip"`
USGIPASN string `fake:"{address}" json:"usgipASN"`
USGIPCountry string `fake:"{country}" json:"usgipCountry"`
DestIPGeo IPGeo `json:"dstipGeo"`
SourceIPGeo IPGeo `json:"srcipGeo"`
USGIPGeo IPGeo `json:"usgipGeo"`
UniqueAlertID string `json:"unique_alertid"`
User string `json:"user"`
}

// IPGeo is part of the UniFi Event data. Each event may have up to three of these.
// One for source, one for dest and one for the USG location.
type IPGeo struct {
Asn int64 `json:"asn"`
Latitude float64 `fake:"{latitude}" json:"latitude"`
Longitude float64 `fake:"{longitude}" json:"longitude"`
City string `fake:"{city}" json:"city"`
ContinentCode string `json:"continent_code"`
CountryCode string `fake:"{countryabr}" json:"country_code"`
CountryName string `fake:"{country}" json:"country_name"`
Latitude float64 `fake:"{latitude}" json:"latitude"`
Longitude float64 `fake:"{longitude}" json:"longitude"`
Organization string `fake:"{company}" json:"organization"`
}

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

g := struct {
Asn int64 `json:"asn"`
Latitude float64 `json:"latitude"`
Longitude float64 `json:"longitude"`
City string `json:"city"`
ContinentCode string `json:"continent_code"`
CountryCode string `json:"country_code"`
CountryName string `json:"country_name"`
Latitude float64 `json:"latitude"`
Longitude float64 `json:"longitude"`
Organization string `json:"organization"`
}{}

Expand Down
Loading

0 comments on commit e1e5f22

Please sign in to comment.