Ubiquiti EdgeOS Go Client

This commit is contained in:
2026-01-04 13:26:40 -05:00
commit e0c0321bc9
7 changed files with 1076 additions and 0 deletions

364
pkg/edgeos/types.go Normal file
View File

@@ -0,0 +1,364 @@
package edgeos
// LoginResponse represents the response from the login endpoint.
type LoginResponse struct {
StatusCode int `json:"statusCode"`
Error int `json:"error"`
Detail string `json:"detail"`
Message string `json:"message"`
}
// InterfaceIdentification represents identification info for an interface.
type InterfaceIdentification struct {
ID string `json:"id"`
Name string `json:"name"`
Mac string `json:"mac"`
Type string `json:"type"`
}
// InterfaceStatus represents status info for an interface.
type InterfaceStatus struct {
Enabled bool `json:"enabled"`
Plugged bool `json:"plugged"`
CurrentSpeed string `json:"currentSpeed"`
Speed string `json:"speed"`
MTU int `json:"mtu"`
}
// InterfaceAddress represents an address on an interface.
type InterfaceAddress struct {
Type string `json:"type"`
Version string `json:"version"`
CIDR string `json:"cidr"`
EUI64 bool `json:"eui64"`
}
// InterfacePort represents port specific settings.
type InterfacePort struct {
STP PortSTP `json:"stp"`
POE string `json:"poe"`
FlowControl bool `json:"flowControl"`
Routed bool `json:"routed"`
PingWatchdog PingWatchdog `json:"pingWatchdog"`
}
// PortSTP represents STP settings for a port.
type PortSTP struct {
Enabled bool `json:"enabled"`
EdgePort string `json:"edgePort"`
PathCost int `json:"pathCost"`
PortPriority int `json:"portPriority"`
State string `json:"state"`
}
// PingWatchdog represents ping watchdog settings.
type PingWatchdog struct {
Enabled bool `json:"enabled"`
Address string `json:"address"`
FailureCount int `json:"failureCount"`
Interval int `json:"interval"`
OffDelay int `json:"offDelay"`
StartDelay int `json:"startDelay"`
}
// Interface represents a network interface.
type Interface struct {
Identification InterfaceIdentification `json:"identification"`
Status InterfaceStatus `json:"status"`
Addresses []InterfaceAddress `json:"addresses"`
Port InterfacePort `json:"port"`
}
// DeviceIdentification represents device identification.
type DeviceIdentification struct {
Mac string `json:"mac"`
Model string `json:"model"`
Family string `json:"family"`
SubsystemID string `json:"subsystemID"`
FirmwareVersion string `json:"firmwareVersion"`
Firmware string `json:"firmware"`
Product string `json:"product"`
ServerVersion string `json:"serverVersion"`
BridgeVersion string `json:"bridgeVersion"`
}
// DeviceCapabilityInterface represents interface capabilities.
type DeviceCapabilityInterface struct {
ID string `json:"id"`
Type string `json:"type"`
SupportBlock bool `json:"supportBlock"`
SupportDelete bool `json:"supportDelete"`
SupportReset bool `json:"supportReset"`
Configurable bool `json:"configurable"`
SupportDHCPSnooping bool `json:"supportDHCPSnooping"`
SupportIsolate bool `json:"supportIsolate"`
SupportAutoEdge bool `json:"supportAutoEdge"`
MaxMTU int `json:"maxMTU"`
SupportPOE bool `json:"supportPOE"`
SupportCableTest bool `json:"supportCableTest"`
POEValues []string `json:"poeValues"`
Media string `json:"media"`
SpeedValues []string `json:"speedValues"`
}
// DeviceCapabilities represents device capabilities.
type DeviceCapabilities struct {
Interfaces []DeviceCapabilityInterface `json:"interfaces"`
}
// Device represents the device info.
type Device struct {
ErrorCodes []any `json:"errorCodes"`
Identification DeviceIdentification `json:"identification"`
Capabilities DeviceCapabilities `json:"capabilities"`
}
// SystemSTP represents system STP settings.
type SystemSTP struct {
Enabled bool `json:"enabled"`
Version string `json:"version"`
MaxAge int `json:"maxAge"`
HelloTime int `json:"helloTime"`
ForwardDelay int `json:"forwardDelay"`
Priority int `json:"priority"`
}
// SystemUser represents a system user.
type SystemUser struct {
Username string `json:"username"`
ReadOnly bool `json:"readOnly"`
SSHKeys []any `json:"sshKeys"`
}
// SystemManagement represents management settings.
type SystemManagement struct {
VlanID int `json:"vlanID"`
ManagementPortOnly bool `json:"managementPortOnly"`
Addresses []InterfaceAddress `json:"addresses"`
}
// SystemAddress represents a system-level address configuration (DNS, Gateway).
type SystemAddress struct {
Type string `json:"type"`
Version string `json:"version"`
Address string `json:"address"`
}
// System represents system information.
type System struct {
Hostname string `json:"hostname"`
Timezone string `json:"timezone"`
DomainName string `json:"domainName"`
FactoryDefault bool `json:"factoryDefault"`
STP SystemSTP `json:"stp"`
AnalyticsEnabled bool `json:"analyticsEnabled"`
DNSServers []SystemAddress `json:"dnsServers"`
DefaultGateway []SystemAddress `json:"defaultGateway"`
Users []SystemUser `json:"users"`
Management SystemManagement `json:"management"`
}
// Trunk represents a VLAN trunk.
type Trunk struct {
Interface InterfaceIdentification `json:"interface"`
}
// VlanParticipation represents interface participation in a VLAN.
type VlanParticipation struct {
Interface InterfaceIdentification `json:"interface"`
Mode string `json:"mode"`
}
// Vlan represents a VLAN.
type Vlan struct {
Name string `json:"name"`
Type string `json:"type"`
ID int `json:"id"`
Participation []VlanParticipation `json:"participation"`
}
// VLANs represents the VLAN configuration.
type VLANs struct {
Trunks []Trunk `json:"trunks"`
Vlans []Vlan `json:"vlans"`
}
// ServiceDiscoveryResponder ...
type ServiceDiscoveryResponder struct {
Enabled bool `json:"enabled"`
}
// ServiceSSHServer ...
type ServiceSSHServer struct {
Enabled bool `json:"enabled"`
SSHPort int `json:"sshPort"`
PasswordAuthentication bool `json:"passwordAuthentication"`
}
// ServiceTelnetServer ...
type ServiceTelnetServer struct {
Enabled bool `json:"enabled"`
Port int `json:"port"`
}
// ServiceWebServer ...
type ServiceWebServer struct {
Enabled bool `json:"enabled"`
HTTPPort int `json:"httpPort"`
HTTPSPort int `json:"httpsPort"`
}
// ServiceSystemLog ...
type ServiceSystemLog struct {
Enabled bool `json:"enabled"`
Port int `json:"port"`
Server string `json:"server"`
Level string `json:"level"`
}
// ServiceNTPClient ...
type ServiceNTPClient struct {
Enabled bool `json:"enabled"`
NTPServers []string `json:"ntpServers"`
}
// ServiceUNMS ...
type ServiceUNMS struct {
Enabled bool `json:"enabled"`
Key string `json:"key"`
Status string `json:"status"`
}
// ServiceLLDP ...
type ServiceLLDP struct {
Enabled bool `json:"enabled"`
}
// ServiceSNMPAgent ...
type ServiceSNMPAgent struct {
Enabled bool `json:"enabled"`
Community string `json:"community"`
Contact string `json:"contact"`
Location string `json:"location"`
}
// DDNSClient represents a dynamic DNS client configuration.
type DDNSClient struct {
Hostname string `json:"hostname"`
Service string `json:"service"`
Username string `json:"username"`
Password string `json:"password"`
}
// ServiceDDNS represents dynamic DNS service configuration.
type ServiceDDNS struct {
Enabled bool `json:"enabled"`
Clients []DDNSClient `json:"clients"`
}
// Services represents services configuration.
type Services struct {
DiscoveryResponder ServiceDiscoveryResponder `json:"discoveryResponder"`
SSHServer ServiceSSHServer `json:"sshServer"`
TelnetServer ServiceTelnetServer `json:"telnetServer"`
WebServer ServiceWebServer `json:"webServer"`
SystemLog ServiceSystemLog `json:"systemLog"`
NTPClient ServiceNTPClient `json:"ntpClient"`
UNMS ServiceUNMS `json:"unms"`
LLDP ServiceLLDP `json:"lldp"`
SNMPAgent ServiceSNMPAgent `json:"snmpAgent"`
DDNS ServiceDDNS `json:"ddns"`
}
// InterfaceStatistics represents statistics for an interface.
type InterfaceStatistics struct {
Dropped int64 `json:"dropped"`
TxDropped int64 `json:"txDropped"`
RxDropped int64 `json:"rxDropped"`
Errors int64 `json:"errors"`
TxErrors int64 `json:"txErrors"`
RxErrors int64 `json:"rxErrors"`
Rate int64 `json:"rate"`
TxRate int64 `json:"txRate"`
RxRate int64 `json:"rxRate"`
Bytes int64 `json:"bytes"`
TxBytes int64 `json:"txBytes"`
RxBytes int64 `json:"rxBytes"`
Packets int64 `json:"packets"`
TxPackets int64 `json:"txPackets"`
RxPackets int64 `json:"rxPackets"`
PPS int64 `json:"pps"`
TxPPS int64 `json:"txPPS"`
RxPPS int64 `json:"rxPPS"`
TxBroadcast int64 `json:"txBroadcast"`
RxBroadcast int64 `json:"rxBroadcast"`
TxMulticast int64 `json:"txMulticast"`
RxMulticast int64 `json:"rxMulticast"`
}
// InterfaceWithStats represents an interface within the statistics response.
type InterfaceWithStats struct {
ID string `json:"id"`
Name string `json:"name"`
Statistics InterfaceStatistics `json:"statistics"`
}
// CPUStat represents CPU usage statistics.
type CPUStat struct {
Identifier string `json:"identifier"`
Usage int `json:"usage"`
}
// RAMStat represents RAM usage statistics.
type RAMStat struct {
Usage int64 `json:"usage"`
Free int64 `json:"free"`
Total int64 `json:"total"`
}
// StorageStat represents storage usage statistics.
type StorageStat struct {
Name string `json:"name"`
Type string `json:"type"`
SysName string `json:"sysName"`
Used int64 `json:"used"`
Size int64 `json:"size"`
}
// DeviceStats represents device level stats in the statistics response.
type DeviceStats struct {
CPU []CPUStat `json:"cpu"`
RAM RAMStat `json:"ram"`
Temperatures []any `json:"temperatures"`
Storage []StorageStat `json:"storage"`
Uptime int64 `json:"uptime"`
}
// Statistics represents a statistics entry.
type Statistics struct {
Timestamp int64 `json:"timestamp"`
Device DeviceStats `json:"device"`
Interfaces []InterfaceWithStats `json:"interfaces"`
}
// NeighborAddress represents an address of a neighbor.
type NeighborAddress struct {
Mac string `json:"mac"`
IP string `json:"ip"`
}
// Neighbor represents a discovered neighbor.
type Neighbor struct {
Mac string `json:"mac"`
Age int `json:"age"`
Protocol string `json:"protocol"`
FW string `json:"fw"`
Model string `json:"model"`
Product string `json:"product"`
Hostname string `json:"hostname"`
Uptime int64 `json:"uptime"`
Configured bool `json:"configured"`
IP string `json:"ip"`
ZoneID string `json:"zoneID"`
Addresses []NeighborAddress `json:"addresses"`
}