GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - unpoller/unifi: Go Library (w/ structures) to grab data from a Ubiquiti UniFi Controller

BranchesTags
Open more actions menu

Latest commit

 

History

655 Commits
655 Commits

Folders and files

NameName
Last commit message
Last commit date
.cursor/rules
.cursor/rules
 
 
.github
.github
 
 
endpoints_data
endpoints_data
 
 
examples
examples
 
 
main
main
 
 
mocks
mocks
 
 
.ai-context.md
.ai-context.md
 
 
.gitignore
.gitignore
 
 
.golangci.yaml
.golangci.yaml
 
 
.goreleaser.yaml
.goreleaser.yaml
 
 
CLAUDE.md
CLAUDE.md
 
 
CONVENTIONS.md
CONVENTIONS.md
 
 
LICENSE
LICENSE
 
 
POTENTIAL_FEATURES.md
POTENTIAL_FEATURES.md
 
 
README.md
README.md
 
 
WAN_METRICS.md
WAN_METRICS.md
 
 
acl_rules.go
acl_rules.go
 
 
acl_rules_test.go
acl_rules_test.go
 
 
alarms.go
alarms.go
 
 
anomalies.go
anomalies.go
 
 
clients.go
clients.go
 
 
clients_test.go
clients_test.go
 
 
console.go
console.go
 
 
console_test.go
console_test.go
 
 
countries.go
countries.go
 
 
countries_test.go
countries_test.go
 
 
devices.go
devices.go
 
 
devices_skip_tags_test.go
devices_skip_tags_test.go
 
 
devices_test.go
devices_test.go
 
 
devmgr.go
devmgr.go
 
 
dhcp_leases.go
dhcp_leases.go
 
 
discover.go
discover.go
 
 
dns_policies.go
dns_policies.go
 
 
dns_policies_test.go
dns_policies_test.go
 
 
dpi.go
dpi.go
 
 
dpi_catalogue.go
dpi_catalogue.go
 
 
dpi_catalogue_test.go
dpi_catalogue_test.go
 
 
events.go
events.go
 
 
events_test.go
events_test.go
 
 
firewall_not_configured_test.go
firewall_not_configured_test.go
 
 
firewall_policies.go
firewall_policies.go
 
 
firewall_zones.go
firewall_zones.go
 
 
firewall_zones_test.go
firewall_zones_test.go
 
 
go.mod
go.mod
 
 
go.sum
go.sum
 
 
hotspot_vouchers.go
hotspot_vouchers.go
 
 
hotspot_vouchers_test.go
hotspot_vouchers_test.go
 
 
ids.go
ids.go
 
 
integration.go
integration.go
 
 
integration_devices.go
integration_devices.go
 
 
integration_devices_test.go
integration_devices_test.go
 
 
integration_networks.go
integration_networks.go
 
 
integration_networks_test.go
integration_networks_test.go
 
 
integration_sites.go
integration_sites.go
 
 
integration_source_test.go
integration_source_test.go
 
 
integration_wans.go
integration_wans.go
 
 
integration_wans_test.go
integration_wans_test.go
 
 
networks.go
networks.go
 
 
pdu.go
pdu.go
 
 
pdu_test.go
pdu_test.go
 
 
pending_devices.go
pending_devices.go
 
 
pending_devices_test.go
pending_devices_test.go
 
 
port_anomalies.go
port_anomalies.go
 
 
port_forwards.go
port_forwards.go
 
 
port_forwards_test.go
port_forwards_test.go
 
 
protect.go
protect.go
 
 
protect_log.go
protect_log.go
 
 
protect_test.go
protect_test.go
 
 
radius_profiles.go
radius_profiles.go
 
 
radius_profiles_test.go
radius_profiles_test.go
 
 
remote.go
remote.go
 
 
remote_test.go
remote_test.go
 
 
site.go
site.go
 
 
ssl_cert.go
ssl_cert.go
 
 
ssl_cert_test.go
ssl_cert_test.go
 
 
stamgr.go
stamgr.go
 
 
stamgr_test.go
stamgr_test.go
 
 
switching.go
switching.go
 
 
switching_test.go
switching_test.go
 
 
sysinfo.go
sysinfo.go
 
 
sysinfo_test.go
sysinfo_test.go
 
 
system_log.go
system_log.go
 
 
topology.go
topology.go
 
 
traffic.go
traffic.go
 
 
traffic_matching_lists.go
traffic_matching_lists.go
 
 
traffic_matching_lists_test.go
traffic_matching_lists_test.go
 
 
traffic_test.go
traffic_test.go
 
 
types.go
types.go
 
 
types_test.go
types_test.go
 
 
uap.go
uap.go
 
 
uap_test.go
uap_test.go
 
 
ubb.go
ubb.go
 
 
ubb_issue_test.go
ubb_issue_test.go
 
 
ubb_test.go
ubb_test.go
 
 
uci.go
uci.go
 
 
uci_test.go
uci_test.go
 
 
udb.go
udb.go
 
 
udb_test.go
udb_test.go
 
 
udm.go
udm.go
 
 
udm_test.go
udm_test.go
 
 

Repository files navigation

Go Library: unifi

It connects to a Unifi Controller, given a url, username and password. Returns an authenticated http Client you may use to query the device for data. Also contains some built-in methods for de-serializing common client and device data. The data is provided in a large struct you can consume in your application.

This library is designed to PULL data FROM the controller. It has no methods that update settings or change things on the controller. Someone expressed interest in adding methods to update data, and I'm okay with that. I'll even help add them. Tell me what you want to do, and we'll make it happen.

Pull requests, feature requests, code reviews and feedback are welcomed!

Here's a working example:

package main

import "log"
import "github.com/unpoller/unifi/v6"

func main() {
	c := *unifi.Config{
		User: "admin",
		Pass: "superSecret1234",
		URL:  "https://127.0.0.1:8443/",
		// Log with log.Printf or make your own interface that accepts (msg, fmt)
		ErrorLog: log.Printf,
		DebugLog: log.Printf,
	}
	uni, err := unifi.NewUnifi(c)
	if err != nil {
		log.Fatalln("Error:", err)
	}

	sites, err := uni.GetSites()
	if err != nil {
		log.Fatalln("Error:", err)
	}
	clients, err := uni.GetClients(sites)
	if err != nil {
		log.Fatalln("Error:", err)
	}
	devices, err := uni.GetDevices(sites)
	if err != nil {
		log.Fatalln("Error:", err)
	}

	log.Println(len(sites), "Unifi Sites Found: ", sites)
	log.Println(len(clients), "Clients connected:")
	for i, client := range clients {
		log.Println(i+1, client.ID, client.Hostname, client.IP, client.Name, client.LastSeen)
	}

	log.Println(len(devices.USWs), "Unifi Switches Found")
	log.Println(len(devices.USGs), "Unifi Gateways Found")

	log.Println(len(devices.UAPs), "Unifi Wireless APs Found:")
	for i, uap := range devices.UAPs {
		log.Println(i+1, uap.Name, uap.IP)
	}
}

UniFi OS console system information

GetConsoleSystem() reads /api/system using the existing local console session. This console-wide endpoint returns broader system information independently of Network sites. The current ConsoleSystem model exposes only the verified devices.unifiOS[] firmware fields from a UCG Fiber response; other fields are ignored. Additional typed sections can be added as representative responses and their meanings are validated. GetJSON(APIConsoleSystemPath) provides access to the full JSON response when fields are not yet modeled.

The endpoint is a private UniFi OS API; it may be absent or forbidden for some controllers/accounts. Community UNAS and gateway references describe broader identity, hardware, uptime and application data, and responses that vary with authentication. These are compatibility references, not a complete vendor schema or a claim of support for those fields. API-key and remote access have not been validated by this implementation.

Valid partial JSON objects are accepted even when devices.unifiOS is absent, null or empty. Callers must check for firmware entries before using them; missing data does not mean no update. A JSON null response, malformed data, and request failures still return errors. This information is separate from GetSysinfo() and the Network application's update flags.

ConsoleFirmware.UpdateStatus() returns (available, known). An offered version or firmwareStatus: "updateAvailable" means an update is available; "upToDate" without an offered version means no update. Missing/null versions alone and unrecognized firmware states are unknown. Callers should omit unknown readings, and handle collection errors without treating them as a no-update result.

Endpoint discovery (--discover)

The main CLI (in main/) supports a discover mode that probes known API endpoints on your controller and writes a shareable report. Use the same credentials you use with unpoller (from your config file or env).

With a config file (JSON with url, user, pass; optional api_key):

go run ./main --discover --config /path/to/unifi-config.json --output api_endpoints_discovery.md

With environment variables (same as unpoller: GOLIFT_UNIFI_URL, GOLIFT_UNIFI_USER, GOLIFT_UNIFI_PASS):

export GOLIFT_UNIFI_URL=https://192.168.1.1:8443
export GOLIFT_UNIFI_USER=admin
export GOLIFT_UNIFI_PASS=yourpassword
go run ./main --discover --output api_endpoints_discovery.md

The report lists each endpoint and its HTTP status (200, 404, etc.). Share the generated file with maintainers when reporting API or 404 issues (e.g. unpoller#935).

About

Go Library (w/ structures) to grab data from a Ubiquiti UniFi Controller

golift.io/discord

Topics

go-modulesgo-unifiunifi-apiunifi-controllerunifi-poller

Resources

Readme
MIT license
Activity
Custom properties

Stars

155 stars

Watchers

10 watching

Forks

48 forks
Report repository

Releases

Used by

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.