update claude and readme
This commit is contained in:
87
README.md
87
README.md
@@ -1,6 +1,6 @@
|
||||
# ubiquiti-clients
|
||||
|
||||
Go client libraries for interacting with Ubiquiti network devices via their REST APIs.
|
||||
Go client libraries for interacting with Ubiquiti network devices via their REST APIs, plus a CLI tool.
|
||||
|
||||
**⚠️ 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.**
|
||||
|
||||
@@ -13,7 +13,7 @@ ToughSwitch POE Pro (TS-8-PRO)) via their internal REST API.
|
||||
|
||||
#### Features
|
||||
|
||||
- **Authentication**: Handles login and session token management automatically.
|
||||
- **Authentication**: Handles login and session token management automatically (or explicitly via `Login`).
|
||||
- **Multi-Device Support**: Manage multiple devices with a single client instance.
|
||||
- **Data Retrieval**:
|
||||
- **System Information**: Hostname, uptime, firmware version, etc.
|
||||
@@ -29,7 +29,7 @@ A client library for interacting with Ubiquiti EdgeOS devices (EdgeRouter, EdgeS
|
||||
|
||||
#### Features
|
||||
|
||||
- **Authentication**: Handles login and session management automatically.
|
||||
- **Authentication**: Handles login and session management automatically (or explicitly via `Login`).
|
||||
- **Multi-Device Support**: Manage multiple devices with a single client instance.
|
||||
- **Data Retrieval**:
|
||||
- **System Configuration**: Hostname, domain name, and other system settings.
|
||||
@@ -37,17 +37,70 @@ A client library for interacting with Ubiquiti EdgeOS devices (EdgeRouter, EdgeS
|
||||
- **VLAN Configuration**: VLAN assignments, PVID, and tagged VLANs.
|
||||
- **Device Information**: Model, ports, PoE capabilities, and features.
|
||||
|
||||
## Installation
|
||||
## CLI Tool
|
||||
|
||||
A command-line tool is included for quick device queries.
|
||||
|
||||
### Installation
|
||||
|
||||
```bash
|
||||
go install gitea.libretechconsulting.com/rmcguire/ubiquiti-clients/cmd@latest
|
||||
```
|
||||
|
||||
### Configuration
|
||||
|
||||
Create a config file (YAML or JSON):
|
||||
|
||||
```yaml
|
||||
logLevel: info
|
||||
logFormat: console
|
||||
|
||||
clients:
|
||||
- name: switch1
|
||||
type: toughswitch
|
||||
host: 192.168.1.1
|
||||
user: ubnt
|
||||
pass: password
|
||||
insecure: true
|
||||
timeout: 10s
|
||||
|
||||
- name: router1
|
||||
type: edgeos
|
||||
host: 192.168.1.2
|
||||
user: ubnt
|
||||
pass: password
|
||||
insecure: true
|
||||
timeout: 10s
|
||||
```
|
||||
|
||||
Environment variables can also be used (and take priority over config file):
|
||||
- `LOG_LEVEL`, `LOG_FORMAT` for top-level settings
|
||||
- `CLIENT_0_NAME`, `CLIENT_0_HOST`, `CLIENT_0_TYPE`, etc. for client array
|
||||
|
||||
### Usage
|
||||
|
||||
```bash
|
||||
# Get info from a single device
|
||||
cmd --config config.yaml get device switch1
|
||||
|
||||
# Get info from all configured devices
|
||||
cmd --config config.yaml get devices
|
||||
|
||||
# With flags
|
||||
cmd --config config.yaml get device switch1 --pretty --color
|
||||
```
|
||||
|
||||
## Library Installation
|
||||
|
||||
```bash
|
||||
# For ToughSwitch
|
||||
go get gitea.libretechconsulting.com/rmcguire/toughswitch-client/pkg/toughswitch
|
||||
go get gitea.libretechconsulting.com/rmcguire/ubiquiti-clients/pkg/toughswitch
|
||||
|
||||
# For EdgeOS
|
||||
go get gitea.libretechconsulting.com/rmcguire/toughswitch-client/pkg/edgeos
|
||||
go get gitea.libretechconsulting.com/rmcguire/ubiquiti-clients/pkg/edgeos
|
||||
```
|
||||
|
||||
## Usage
|
||||
## Library Usage
|
||||
|
||||
### ToughSwitch Basic Example
|
||||
|
||||
@@ -60,7 +113,7 @@ import (
|
||||
"log"
|
||||
"time"
|
||||
|
||||
"gitea.libretechconsulting.com/rmcguire/toughswitch-client/pkg/toughswitch"
|
||||
"gitea.libretechconsulting.com/rmcguire/ubiquiti-clients/pkg/toughswitch"
|
||||
)
|
||||
|
||||
func main() {
|
||||
@@ -80,6 +133,11 @@ func main() {
|
||||
// Initialize the client
|
||||
client := toughswitch.MustNew(ctx, configs)
|
||||
|
||||
// Optionally pre-authenticate (otherwise happens automatically on first request)
|
||||
if err := client.Login(ctx, "192.168.1.1"); err != nil {
|
||||
log.Fatalf("Failed to login: %v", err)
|
||||
}
|
||||
|
||||
// Fetch system information
|
||||
deviceHost := "192.168.1.1"
|
||||
system, err := client.GetSystem(ctx, deviceHost)
|
||||
@@ -116,7 +174,7 @@ import (
|
||||
"log"
|
||||
"time"
|
||||
|
||||
"gitea.libretechconsulting.com/rmcguire/toughswitch-client/pkg/edgeos"
|
||||
"gitea.libretechconsulting.com/rmcguire/ubiquiti-clients/pkg/edgeos"
|
||||
)
|
||||
|
||||
func main() {
|
||||
@@ -136,6 +194,11 @@ func main() {
|
||||
// Initialize the client
|
||||
client := edgeos.MustNew(ctx, configs)
|
||||
|
||||
// Optionally pre-authenticate (otherwise happens automatically on first request)
|
||||
if err := client.Login(ctx, "192.168.1.1"); err != nil {
|
||||
log.Fatalf("Failed to login: %v", err)
|
||||
}
|
||||
|
||||
// Fetch device information
|
||||
deviceHost := "192.168.1.1"
|
||||
authInfo, err := client.GetAuthInfo(ctx, deviceHost)
|
||||
@@ -240,6 +303,7 @@ for host, cfg := range allConfigs {
|
||||
|
||||
| Method | Description |
|
||||
|--------|-------------|
|
||||
| `Login` | Explicit authentication (also happens automatically on 401) |
|
||||
| `GetSystem` | General system configuration and status |
|
||||
| `GetInterfaces` | Interface configuration and status |
|
||||
| `GetVLANs` | VLAN and Trunk configuration |
|
||||
@@ -248,18 +312,19 @@ for host, cfg := range allConfigs {
|
||||
| `GetNeighbors` | Discovered UBNT neighbors |
|
||||
| `GetDevice` | Hardware and capabilities info |
|
||||
|
||||
All methods have corresponding `GetAll*` variants for multi-device operations.
|
||||
All `Get*` methods have corresponding `GetAll*` variants for multi-device operations.
|
||||
|
||||
### EdgeOS
|
||||
|
||||
| Method | Description |
|
||||
|--------|-------------|
|
||||
| `Login` | Explicit authentication (also happens automatically on 401) |
|
||||
| `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.
|
||||
All `Get*` methods have corresponding `GetAll*` variants for multi-device operations.
|
||||
|
||||
## License
|
||||
|
||||
|
||||
Reference in New Issue
Block a user