This commit is contained in:
16
CHANGELOG.md
16
CHANGELOG.md
@@ -2,6 +2,22 @@
|
|||||||
|
|
||||||
All notable changes to this project will be documented in this file.
|
All notable changes to this project will be documented in this file.
|
||||||
|
|
||||||
|
## v0.5.0 - 2026-01-19
|
||||||
|
### Added
|
||||||
|
- `ToughSwitch` consolidated type combining Device, System, Interfaces, VLANs, Services, Statistics, and Neighbors
|
||||||
|
- `GetToughSwitch(ctx, host)` method to fetch all data for a single ToughSwitch device in parallel
|
||||||
|
- `GetAllToughSwitches(ctx)` method to fetch consolidated data for all ToughSwitch devices
|
||||||
|
- `EdgeOS` consolidated type combining AuthInfo and Config
|
||||||
|
- `GetEdgeOS(ctx, host)` method to fetch all data for a single EdgeOS device in parallel
|
||||||
|
- `GetAllEdgeOS(ctx)` method to fetch consolidated data for all EdgeOS devices
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
- CLI `get device` and `get devices` commands now return full consolidated data for both device types
|
||||||
|
- EdgeOS CLI output now includes device model, ports, PoE capability, and features from AuthInfo
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
- Typo in ToughSwitch struct field name (`Statistucs` → `Statistics`)
|
||||||
|
|
||||||
## v0.4.0 - 2026-01-18
|
## v0.4.0 - 2026-01-18
|
||||||
### Added
|
### Added
|
||||||
- CLI tool (`cmd/`) for quick device queries using cobra
|
- CLI tool (`cmd/`) for quick device queries using cobra
|
||||||
|
|||||||
56
README.md
56
README.md
@@ -15,6 +15,7 @@ ToughSwitch POE Pro (TS-8-PRO)) via their internal REST API.
|
|||||||
|
|
||||||
- **Authentication**: Handles login and session token management automatically (or explicitly via `Login`).
|
- **Authentication**: Handles login and session token management automatically (or explicitly via `Login`).
|
||||||
- **Multi-Device Support**: Manage multiple devices with a single client instance.
|
- **Multi-Device Support**: Manage multiple devices with a single client instance.
|
||||||
|
- **Consolidated Data**: `GetToughSwitch` fetches all device data in a single call (Device, System, Interfaces, VLANs, Services, Statistics, Neighbors).
|
||||||
- **Data Retrieval**:
|
- **Data Retrieval**:
|
||||||
- **System Information**: Hostname, uptime, firmware version, etc.
|
- **System Information**: Hostname, uptime, firmware version, etc.
|
||||||
- **Interfaces**: Status, POE settings, link speed, statistics.
|
- **Interfaces**: Status, POE settings, link speed, statistics.
|
||||||
@@ -31,6 +32,7 @@ A client library for interacting with Ubiquiti EdgeOS devices (EdgeRouter, EdgeS
|
|||||||
|
|
||||||
- **Authentication**: Handles login and session management automatically (or explicitly via `Login`).
|
- **Authentication**: Handles login and session management automatically (or explicitly via `Login`).
|
||||||
- **Multi-Device Support**: Manage multiple devices with a single client instance.
|
- **Multi-Device Support**: Manage multiple devices with a single client instance.
|
||||||
|
- **Consolidated Data**: `GetEdgeOS` fetches all device data in a single call (AuthInfo and Config).
|
||||||
- **Data Retrieval**:
|
- **Data Retrieval**:
|
||||||
- **System Configuration**: Hostname, domain name, and other system settings.
|
- **System Configuration**: Hostname, domain name, and other system settings.
|
||||||
- **Interface Configuration**: Ethernet and switch interface settings, including PoE.
|
- **Interface Configuration**: Ethernet and switch interface settings, including PoE.
|
||||||
@@ -257,6 +259,34 @@ for _, stat := range stats {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Fetching All Device Data
|
||||||
|
|
||||||
|
Use the consolidated methods to fetch all device information in a single call:
|
||||||
|
|
||||||
|
```go
|
||||||
|
// ToughSwitch: Get everything at once
|
||||||
|
ts, err := client.GetToughSwitch(ctx, "192.168.1.1")
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Printf("Model: %s\n", ts.Device.Identification.Model)
|
||||||
|
fmt.Printf("Hostname: %s\n", ts.System.Hostname)
|
||||||
|
fmt.Printf("Interfaces: %d\n", len(ts.Interfaces))
|
||||||
|
fmt.Printf("VLANs: %d\n", len(ts.VLANs.Vlans))
|
||||||
|
fmt.Printf("Neighbors: %d\n", len(ts.Neighbors))
|
||||||
|
|
||||||
|
// EdgeOS: Get everything at once
|
||||||
|
eos, err := edgeClient.GetEdgeOS(ctx, "192.168.2.1")
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Printf("Model: %s (%s)\n", eos.AuthInfo.ModelName, eos.AuthInfo.Model)
|
||||||
|
fmt.Printf("Ports: %d, PoE: %v\n", eos.AuthInfo.Ports, eos.AuthInfo.PoE)
|
||||||
|
fmt.Printf("Hostname: %s\n", eos.Config.System.HostName)
|
||||||
|
```
|
||||||
|
|
||||||
### Working with Multiple Devices
|
### Working with Multiple Devices
|
||||||
|
|
||||||
Both clients are designed to handle multiple devices concurrently.
|
Both clients are designed to handle multiple devices concurrently.
|
||||||
@@ -269,14 +299,14 @@ configs := []toughswitch.Config{
|
|||||||
}
|
}
|
||||||
client := toughswitch.MustNew(ctx, configs)
|
client := toughswitch.MustNew(ctx, configs)
|
||||||
|
|
||||||
// Get info for all configured devices in parallel
|
// Get all data for all devices in parallel
|
||||||
allSystems, err := client.GetAllSystems(ctx)
|
allSwitches, err := client.GetAllToughSwitches(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Error fetching some systems: %v", err)
|
log.Printf("Error fetching some devices: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
for host, sys := range allSystems {
|
for host, ts := range allSwitches {
|
||||||
fmt.Printf("[%s] Hostname: %s\n", host, sys.Hostname)
|
fmt.Printf("[%s] %s - %d interfaces\n", host, ts.System.Hostname, len(ts.Interfaces))
|
||||||
}
|
}
|
||||||
|
|
||||||
// EdgeOS example
|
// EdgeOS example
|
||||||
@@ -286,14 +316,14 @@ edgeConfigs := []edgeos.Config{
|
|||||||
}
|
}
|
||||||
edgeClient := edgeos.MustNew(ctx, edgeConfigs)
|
edgeClient := edgeos.MustNew(ctx, edgeConfigs)
|
||||||
|
|
||||||
// Get config for all configured devices in parallel
|
// Get all data for all devices in parallel
|
||||||
allConfigs, err := edgeClient.GetAllConfigs(ctx)
|
allEdge, err := edgeClient.GetAllEdgeOS(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Error fetching some configs: %v", err)
|
log.Printf("Error fetching some devices: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
for host, cfg := range allConfigs {
|
for host, eos := range allEdge {
|
||||||
fmt.Printf("[%s] Hostname: %s\n", host, cfg.System.HostName)
|
fmt.Printf("[%s] %s (%d ports)\n", host, eos.AuthInfo.ModelName, eos.AuthInfo.Ports)
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -304,13 +334,14 @@ for host, cfg := range allConfigs {
|
|||||||
| Method | Description |
|
| Method | Description |
|
||||||
|--------|-------------|
|
|--------|-------------|
|
||||||
| `Login` | Explicit authentication (also happens automatically on 401) |
|
| `Login` | Explicit authentication (also happens automatically on 401) |
|
||||||
|
| `GetToughSwitch` | All device data combined (Device, System, Interfaces, VLANs, Services, Statistics, Neighbors) |
|
||||||
|
| `GetDevice` | Hardware and capabilities info |
|
||||||
| `GetSystem` | General system configuration and status |
|
| `GetSystem` | General system configuration and status |
|
||||||
| `GetInterfaces` | Interface configuration and status |
|
| `GetInterfaces` | Interface configuration and status |
|
||||||
| `GetVLANs` | VLAN and Trunk configuration |
|
| `GetVLANs` | VLAN and Trunk configuration |
|
||||||
| `GetServices` | State of running services (SSH, NTP, etc.) |
|
| `GetServices` | State of running services (SSH, NTP, etc.) |
|
||||||
| `GetStatistics` | Performance metrics |
|
| `GetStatistics` | Performance metrics |
|
||||||
| `GetNeighbors` | Discovered UBNT neighbors |
|
| `GetNeighbors` | Discovered UBNT neighbors |
|
||||||
| `GetDevice` | Hardware and capabilities info |
|
|
||||||
|
|
||||||
All `Get*` methods have corresponding `GetAll*` variants for multi-device operations.
|
All `Get*` methods have corresponding `GetAll*` variants for multi-device operations.
|
||||||
|
|
||||||
@@ -319,8 +350,9 @@ All `Get*` methods have corresponding `GetAll*` variants for multi-device operat
|
|||||||
| Method | Description |
|
| Method | Description |
|
||||||
|--------|-------------|
|
|--------|-------------|
|
||||||
| `Login` | Explicit authentication (also happens automatically on 401) |
|
| `Login` | Explicit authentication (also happens automatically on 401) |
|
||||||
| `GetConfig` | Complete device configuration |
|
| `GetEdgeOS` | All device data combined (AuthInfo and Config) |
|
||||||
| `GetAuthInfo` | Device authentication and feature information |
|
| `GetAuthInfo` | Device authentication and feature information |
|
||||||
|
| `GetConfig` | Complete device configuration |
|
||||||
| `GetInterfaces` | Interface configuration (ethernet and switch) |
|
| `GetInterfaces` | Interface configuration (ethernet and switch) |
|
||||||
| `GetSystem` | System configuration (hostname, domain) |
|
| `GetSystem` | System configuration (hostname, domain) |
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user