move to ubiquiti-clients, add edgeos
This commit is contained in:
140
README.md
140
README.md
@@ -1,11 +1,17 @@
|
||||
# toughswitch
|
||||
# ubiquiti-clients
|
||||
|
||||
A Go client library for interacting with Ubiquiti toughswitch devices (specifically tested with
|
||||
Go client libraries for interacting with Ubiquiti network devices via their REST APIs.
|
||||
|
||||
**⚠️ Disclaimer: These libraries are based on reverse-engineered API calls. They are not official Ubiquiti products and are subject to change if the device firmware changes.**
|
||||
|
||||
## Packages
|
||||
|
||||
### toughswitch
|
||||
|
||||
A client library for interacting with Ubiquiti ToughSwitch devices (specifically tested with
|
||||
ToughSwitch POE Pro (TS-8-PRO)) via their internal REST API.
|
||||
|
||||
**⚠️ Disclaimer: This library is based on reverse-engineered API calls. It is not an official Ubiquiti product and is subject to change if the device firmware changes.**
|
||||
|
||||
## Features
|
||||
#### Features
|
||||
|
||||
- **Authentication**: Handles login and session token management automatically.
|
||||
- **Multi-Device Support**: Manage multiple devices with a single client instance.
|
||||
@@ -17,15 +23,33 @@ ToughSwitch POE Pro (TS-8-PRO)) via their internal REST API.
|
||||
- **Statistics**: Real-time throughput, errors, and resource usage.
|
||||
- **Discovery**: Neighbor discovery via UBNT protocol.
|
||||
|
||||
### edgeos
|
||||
|
||||
A client library for interacting with Ubiquiti EdgeOS devices (EdgeRouter, EdgeSwitch) via their REST API.
|
||||
|
||||
#### Features
|
||||
|
||||
- **Authentication**: Handles login and session management automatically.
|
||||
- **Multi-Device Support**: Manage multiple devices with a single client instance.
|
||||
- **Data Retrieval**:
|
||||
- **System Configuration**: Hostname, domain name, and other system settings.
|
||||
- **Interface Configuration**: Ethernet and switch interface settings, including PoE.
|
||||
- **VLAN Configuration**: VLAN assignments, PVID, and tagged VLANs.
|
||||
- **Device Information**: Model, ports, PoE capabilities, and features.
|
||||
|
||||
## Installation
|
||||
|
||||
```bash
|
||||
# For ToughSwitch
|
||||
go get gitea.libretechconsulting.com/rmcguire/toughswitch-client/pkg/toughswitch
|
||||
|
||||
# For EdgeOS
|
||||
go get gitea.libretechconsulting.com/rmcguire/toughswitch-client/pkg/edgeos
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
### Basic Example
|
||||
### ToughSwitch Basic Example
|
||||
|
||||
```go
|
||||
package main
|
||||
@@ -81,7 +105,73 @@ func main() {
|
||||
}
|
||||
```
|
||||
|
||||
### Retrieving Statistics
|
||||
### EdgeOS Basic Example
|
||||
|
||||
```go
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"log"
|
||||
"time"
|
||||
|
||||
"gitea.libretechconsulting.com/rmcguire/toughswitch-client/pkg/edgeos"
|
||||
)
|
||||
|
||||
func main() {
|
||||
ctx := context.Background()
|
||||
|
||||
// Configure your device(s)
|
||||
configs := []edgeos.Config{
|
||||
{
|
||||
Host: "192.168.1.1",
|
||||
Username: "ubnt",
|
||||
Password: "ubnt",
|
||||
Insecure: true, // Set to true if using self-signed certs
|
||||
Timeout: 10 * time.Second,
|
||||
},
|
||||
}
|
||||
|
||||
// Initialize the client
|
||||
client := edgeos.MustNew(ctx, configs)
|
||||
|
||||
// Fetch device information
|
||||
deviceHost := "192.168.1.1"
|
||||
authInfo, err := client.GetAuthInfo(ctx, deviceHost)
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to get auth info: %v", err)
|
||||
}
|
||||
|
||||
fmt.Printf("Connected to: %s (%s) with %d ports\n",
|
||||
authInfo.ModelName, authInfo.Model, authInfo.Ports)
|
||||
|
||||
// Fetch system configuration
|
||||
system, err := client.GetSystem(ctx, deviceHost)
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to get system config: %v", err)
|
||||
}
|
||||
|
||||
fmt.Printf("Hostname: %s, Domain: %s\n", system.HostName, system.DomainName)
|
||||
|
||||
// Fetch interfaces
|
||||
interfaces, err := client.GetInterfaces(ctx, deviceHost)
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to get interfaces: %v", err)
|
||||
}
|
||||
|
||||
for name, config := range interfaces.Ethernet {
|
||||
fmt.Printf("Interface %s: %s (Speed: %s, Duplex: %s)\n",
|
||||
name,
|
||||
config.Description,
|
||||
config.Speed,
|
||||
config.Duplex,
|
||||
)
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### ToughSwitch: Retrieving Statistics
|
||||
|
||||
```go
|
||||
stats, err := client.GetStatistics(ctx, "192.168.1.1")
|
||||
@@ -106,9 +196,10 @@ for _, stat := range stats {
|
||||
|
||||
### Working with Multiple Devices
|
||||
|
||||
The client is designed to handle multiple devices concurrently.
|
||||
Both clients are designed to handle multiple devices concurrently.
|
||||
|
||||
```go
|
||||
// ToughSwitch example
|
||||
configs := []toughswitch.Config{
|
||||
{Host: "192.168.1.1", ...},
|
||||
{Host: "192.168.1.2", ...},
|
||||
@@ -118,17 +209,35 @@ client := toughswitch.MustNew(ctx, configs)
|
||||
// Get info for all configured devices in parallel
|
||||
allSystems, err := client.GetAllSystems(ctx)
|
||||
if err != nil {
|
||||
// Note: This returns partial results if available, check implementation
|
||||
log.Printf("Error fetching some systems: %v", err)
|
||||
}
|
||||
|
||||
for host, sys := range allSystems {
|
||||
fmt.Printf("[%s] Hostname: %s\n", host, sys.Hostname)
|
||||
}
|
||||
|
||||
// EdgeOS example
|
||||
edgeConfigs := []edgeos.Config{
|
||||
{Host: "192.168.2.1", ...},
|
||||
{Host: "192.168.2.2", ...},
|
||||
}
|
||||
edgeClient := edgeos.MustNew(ctx, edgeConfigs)
|
||||
|
||||
// Get config for all configured devices in parallel
|
||||
allConfigs, err := edgeClient.GetAllConfigs(ctx)
|
||||
if err != nil {
|
||||
log.Printf("Error fetching some configs: %v", err)
|
||||
}
|
||||
|
||||
for host, cfg := range allConfigs {
|
||||
fmt.Printf("[%s] Hostname: %s\n", host, cfg.System.HostName)
|
||||
}
|
||||
```
|
||||
|
||||
## Supported Endpoints
|
||||
|
||||
### ToughSwitch
|
||||
|
||||
| Method | Description |
|
||||
|--------|-------------|
|
||||
| `GetSystem` | General system configuration and status |
|
||||
@@ -139,6 +248,19 @@ for host, sys := range allSystems {
|
||||
| `GetNeighbors` | Discovered UBNT neighbors |
|
||||
| `GetDevice` | Hardware and capabilities info |
|
||||
|
||||
All methods have corresponding `GetAll*` variants for multi-device operations.
|
||||
|
||||
### EdgeOS
|
||||
|
||||
| Method | Description |
|
||||
|--------|-------------|
|
||||
| `GetConfig` | Complete device configuration |
|
||||
| `GetAuthInfo` | Device authentication and feature information |
|
||||
| `GetInterfaces` | Interface configuration (ethernet and switch) |
|
||||
| `GetSystem` | System configuration (hostname, domain) |
|
||||
|
||||
All methods have corresponding `GetAll*` variants for multi-device operations.
|
||||
|
||||
## License
|
||||
|
||||
MIT
|
||||
|
||||
Reference in New Issue
Block a user