unpoller_unpoller/core/unifi
davidnewhall2 8be479e69e A bit of cleanup 2020-06-25 02:04:27 -07:00
..
examples add example 2020-06-21 00:57:46 -07:00
.gitignore Add dep constraints. 2019-01-23 23:50:59 -08:00
.travis.yml trim whitespace of client and device names 2020-06-13 19:05:10 -07:00
LICENSE update license text 2019-12-29 01:05:44 -08:00
README.md Move repo 2019-12-28 20:09:40 -08:00
clients.go Updates for Events 2020-06-19 02:20:06 -07:00
devices.go Updates for Events 2020-06-19 02:20:06 -07:00
dpi.go trim whitespace of client and device names 2020-06-13 19:05:10 -07:00
events.go A bit of cleanup 2020-06-25 02:04:27 -07:00
events_test.go add small test 2020-06-22 01:42:23 -07:00
go.mod trim whitespace of client and device names 2020-06-13 19:05:10 -07:00
go.sum trim whitespace of client and device names 2020-06-13 19:05:10 -07:00
ids.go A bit of cleanup 2020-06-25 02:04:27 -07:00
site.go add debug message 2020-06-23 01:08:00 -07:00
types.go A bit of cleanup 2020-06-25 02:04:27 -07:00
types_test.go add small test 2020-06-22 01:42:23 -07:00
uap.go trim whitespace of client and device names 2020-06-13 19:05:10 -07:00
uap_test.go trim whitespace of client and device names 2020-06-13 19:05:10 -07:00
udm.go better 2020-06-13 20:46:23 -07:00
unifi.go trim whitespace of client and device names 2020-06-13 19:05:10 -07:00
unifi_test.go trim whitespace of client and device names 2020-06-13 19:05:10 -07:00
usg.go Add source parameter 2019-12-15 13:41:09 -08:00
usg_test.go trim whitespace of client and device names 2020-06-13 19:05:10 -07:00
usw.go Add source parameter 2019-12-15 13:41:09 -08:00
usw_test.go trim whitespace of client and device names 2020-06-13 19:05:10 -07:00

README.md

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/unifi-poller/unifi"

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)
	}
}