unpoller_unpoller/core/unifi
spsobole fae86101e7 Update tests to use new org import path 2021-08-13 15:58:42 -06:00
..
examples add example 2020-06-21 00:57:46 -07:00
.gitignore add networks 2020-09-08 00:22:46 -07:00
.travis.yml lint fix, go upgrade 2021-04-17 13:45:16 -07:00
LICENSE update license text 2019-12-29 01:05:44 -08:00
README.md update org name 2021-06-23 03:03:14 -07:00
alarms.go site name is wrong 2021-04-17 13:41:24 -07:00
anomalies.go site name is wrong 2021-04-17 13:41:24 -07:00
clients.go site name is wrong 2021-04-17 13:41:24 -07:00
devices.go site name is wrong 2021-04-17 13:41:24 -07:00
devmgr.go fix build 2021-03-14 14:48:55 -07:00
dpi.go Add UXG, UDM storage, minor lint fixups. 2021-03-07 17:23:31 -08:00
events.go site name is wrong 2021-04-17 13:41:24 -07:00
events_test.go Update tests to use new org import path 2021-08-13 15:58:42 -06:00
go.mod update org name 2021-06-23 03:03:14 -07:00
go.sum lint fix, go upgrade 2021-04-17 13:45:16 -07:00
ids.go site name is wrong 2021-04-17 13:41:24 -07:00
networks.go fix all lint 2021-03-07 18:23:16 -08:00
site.go site name is wrong 2021-04-17 13:41:24 -07:00
types.go style fixes per lint warnings 2021-08-13 12:20:20 -06:00
types_test.go Update tests to use new org import path 2021-08-13 15:58:42 -06:00
uap.go site name is wrong 2021-04-17 13:41:24 -07:00
uap_test.go trim whitespace of client and device names 2020-06-13 19:05:10 -07:00
udm.go with controller on site do not need it per device 2021-03-14 15:12:28 -07:00
unifi.go Fix missing consumption of params in UniReqPost 2021-08-13 15:40:34 -06:00
unifi_test.go a fe wmore tweaks to align outputs.a 2021-03-07 17:57:16 -08:00
users.go style fixes per lint warnings 2021-08-13 12:20:20 -06:00
usg.go Merge pull request #45 from unifi-poller/dn2_power_cycle 2021-03-22 03:05:36 -07:00
usg_test.go trim whitespace of client and device names 2020-06-13 19:05:10 -07:00
usw.go Merge pull request #45 from unifi-poller/dn2_power_cycle 2021-03-22 03:05:36 -07:00
usw_test.go trim whitespace of client and device names 2020-06-13 19:05:10 -07:00
uxg.go Merge pull request #45 from unifi-poller/dn2_power_cycle 2021-03-22 03:05:36 -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/unpoller/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)
	}
}