unpoller_unpoller/core/unifi
davidnewhall2 83c54b2b62 change channel to float 2019-12-03 12:06:03 -08:00
..
examples Add IDS data to the library. 2019-07-10 23:43:03 -07:00
.gitignore Add dep constraints. 2019-01-23 23:50:59 -08:00
.travis.yml Re-do structs to support UDM w/ UAP. 2019-09-02 23:58:27 -07:00
Gopkg.lock Remove influx and add Config input struct 2019-08-25 03:20:01 -07:00
Gopkg.toml Remove influx and add Config input struct 2019-08-25 03:20:01 -07:00
LICENSE fix license again. 2019-01-26 15:52:41 -08:00
README.md Update readme 2019-08-25 03:29:26 -07:00
clients.go add missing members 2019-11-28 04:18:28 -08:00
devices.go Add two debug messages, fix tests, and move methods verbatim. 2019-09-03 01:01:37 -07:00
ids.go Remove influx and add Config input struct 2019-08-25 03:20:01 -07:00
site.go Add two debug messages, fix tests, and move methods verbatim. 2019-09-03 01:01:37 -07:00
types.go whatever 2019-11-29 23:00:31 -08:00
types_test.go whatever 2019-11-29 23:00:31 -08:00
uap.go change channel to float 2019-12-03 12:06:03 -08:00
uap_test.go Re-do structs to support UDM w/ UAP. 2019-09-02 23:58:27 -07:00
udm.go Add missing items to udm 2019-12-02 22:10:25 -08:00
unifi.go Add missing items to udm 2019-12-02 22:10:25 -08:00
unifi_test.go Add two debug messages, fix tests, and move methods verbatim. 2019-09-03 01:01:37 -07:00
usg.go Re-do structs to support UDM w/ UAP. 2019-09-02 23:58:27 -07:00
usg_test.go Re-do structs to support UDM w/ UAP. 2019-09-02 23:58:27 -07:00
usw.go StpPriority -> FlexInt 2019-09-14 01:43:52 -07:00
usw_test.go Re-do structs to support UDM w/ UAP. 2019-09-02 23:58:27 -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.

If more features are requested, I'll certainly consider them. Do you need to do more than just collect data? Let me know! Pull requests and feedback are welcomed!

Here's a working example:

package main

import "log"
import "golift.io/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)
	}
}