This commit is contained in:
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`).
|
||||
- **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) |
|
||||
|
||||
|
||||
Reference in New Issue
Block a user