unpoller_unpoller/core/unifi
davidnewhall2 39c6f6801e Bug fix on FlexInt=nil/null, remove errors pkg, minor cleanup. 2019-08-24 01:32:12 -07: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 Add controller 5.11 support. 2019-07-07 15:23:02 -07:00
Gopkg.lock Bug fix on FlexInt=nil/null, remove errors pkg, minor cleanup. 2019-08-24 01:32:12 -07:00
Gopkg.toml Bug fix on FlexInt=nil/null, remove errors pkg, minor cleanup. 2019-08-24 01:32:12 -07:00
LICENSE fix license again. 2019-01-26 15:52:41 -08:00
README.md Update README.md 2019-07-20 02:21:56 -07:00
clients_influx.go Use pointers.... 2019-07-13 03:16:26 -07:00
clients_type.go Use pointers.... 2019-07-13 03:16:26 -07:00
devices.go Add UDM support. 2019-08-16 01:42:25 -07:00
ids.go Bug fix on FlexInt=nil/null, remove errors pkg, minor cleanup. 2019-08-24 01:32:12 -07:00
site_influx.go Use pointers.... 2019-07-13 03:16:26 -07:00
site_type.go Use pointers.... 2019-07-13 03:16:26 -07:00
types.go Bug fix on FlexInt=nil/null, remove errors pkg, minor cleanup. 2019-08-24 01:32:12 -07:00
types_test.go Re-arrange 2019-04-17 00:21:24 -07:00
uap_influx.go Add UDM support. 2019-08-16 01:42:25 -07:00
uap_influx_test.go Use pointers.... 2019-07-13 03:16:26 -07:00
uap_type.go Add UDM support. 2019-08-16 01:42:25 -07:00
uap_type_test.go Add controller 5.11 support. 2019-07-07 15:23:02 -07:00
udm_influx.go Add UDM support. 2019-08-16 01:42:25 -07:00
udm_type.go Add UDM support. 2019-08-16 01:42:25 -07:00
unifi.go Bug fix on FlexInt=nil/null, remove errors pkg, minor cleanup. 2019-08-24 01:32:12 -07:00
unifi_test.go Add site name to all assets. Include Travis build. 2019-06-05 17:12:59 -07:00
usg_influx.go Add UDM support. 2019-08-16 01:42:25 -07:00
usg_type.go Add UDM support. 2019-08-16 01:42:25 -07:00
usg_type_test.go Add controller 5.11 support. 2019-07-07 15:23:02 -07:00
usw_influx.go fix 2019-08-24 01:02:15 -07:00
usw_type.go fix 2019-08-24 01:02:15 -07:00
usw_type_test.go Add controller 5.11 support. 2019-07-07 15:23:02 -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 also contains methods to export the Unifi data in InfluxDB format, and this can be used as an example to base your own metrics collection methods.

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() {
	username := "admin"
	password := "superSecret1234"
	URL := "https://127.0.0.1:8443/"
	uni, err := unifi.NewUnifi(username, password, URL, false)
	if err != nil {
		log.Fatalln("Error:", err)
	}
	// Log with log.Printf or make your own interface that accepts (msg, fmt)
	uni.ErrorLog = log.Printf
	uni.DebugLog = log.Printf

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