diff --git a/CHANGELOG.md b/CHANGELOG.md index e32b17a..859fbd2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,22 @@ 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 ### Added - CLI tool (`cmd/`) for quick device queries using cobra diff --git a/README.md b/README.md index 58771ba..de7d399 100644 --- a/README.md +++ b/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`). - **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**: - **System Information**: Hostname, uptime, firmware version, etc. - **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`). - **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**: - **System Configuration**: Hostname, domain name, and other system settings. - **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 Both clients are designed to handle multiple devices concurrently. @@ -269,14 +299,14 @@ configs := []toughswitch.Config{ } client := toughswitch.MustNew(ctx, configs) -// Get info for all configured devices in parallel -allSystems, err := client.GetAllSystems(ctx) +// Get all data for all devices in parallel +allSwitches, err := client.GetAllToughSwitches(ctx) if err != nil { - log.Printf("Error fetching some systems: %v", err) + log.Printf("Error fetching some devices: %v", err) } -for host, sys := range allSystems { - fmt.Printf("[%s] Hostname: %s\n", host, sys.Hostname) +for host, ts := range allSwitches { + fmt.Printf("[%s] %s - %d interfaces\n", host, ts.System.Hostname, len(ts.Interfaces)) } // EdgeOS example @@ -286,14 +316,14 @@ edgeConfigs := []edgeos.Config{ } edgeClient := edgeos.MustNew(ctx, edgeConfigs) -// Get config for all configured devices in parallel -allConfigs, err := edgeClient.GetAllConfigs(ctx) +// Get all data for all devices in parallel +allEdge, err := edgeClient.GetAllEdgeOS(ctx) if err != nil { - log.Printf("Error fetching some configs: %v", err) + log.Printf("Error fetching some devices: %v", err) } -for host, cfg := range allConfigs { - fmt.Printf("[%s] Hostname: %s\n", host, cfg.System.HostName) +for host, eos := range allEdge { + 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 | |--------|-------------| | `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 | | `GetInterfaces` | Interface configuration and status | | `GetVLANs` | VLAN and Trunk configuration | | `GetServices` | State of running services (SSH, NTP, etc.) | | `GetStatistics` | Performance metrics | | `GetNeighbors` | Discovered UBNT neighbors | -| `GetDevice` | Hardware and capabilities info | 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 | |--------|-------------| | `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 | +| `GetConfig` | Complete device configuration | | `GetInterfaces` | Interface configuration (ethernet and switch) | | `GetSystem` | System configuration (hostname, domain) |