unpoller_unpoller/core/unifi
David Newhall II c5c1907be7 Wrap clients in a struct too. 2019-01-26 12:51:08 -08:00
..
.gitignore Add dep constraints. 2019-01-23 23:50:59 -08:00
Gopkg.lock Use new influx db lib path. Make Points() work with an interface. 2019-01-26 12:33:18 -08:00
Gopkg.toml Use new influx db lib path. Make Points() work with an interface. 2019-01-26 12:33:18 -08:00
LICENSE Initial commit 2019-01-23 18:10:28 -08:00
README.md type strings and fix readme. 2019-01-26 04:29:16 -08:00
clients.go Use new influx db lib path. Make Points() work with an interface. 2019-01-26 12:33:18 -08:00
clients_type.go Fix name. 2019-01-24 00:01:13 -08:00
uap.go Use new influx db lib path. Make Points() work with an interface. 2019-01-26 12:33:18 -08:00
uap_type.go Rename a few pieces. 2019-01-26 04:15:41 -08:00
unidev.go Wrap clients in a struct too. 2019-01-26 12:51:08 -08:00
unidev_test.go Use new influx db lib path. Make Points() work with an interface. 2019-01-26 12:33:18 -08:00
unifi.go Wrap clients in a struct too. 2019-01-26 12:51:08 -08:00
usg.go Use new influx db lib path. Make Points() work with an interface. 2019-01-26 12:33:18 -08:00
usg_type.go Rename a few pieces. 2019-01-26 04:15:41 -08:00
usw.go Use new influx db lib path. Make Points() work with an interface. 2019-01-26 12:33:18 -08:00
usw_type.go Rename a few pieces. 2019-01-26 04:15:41 -08: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.

Pull requests and feedback are welcomed!

Here's a working example:

package main

import "log"
import "github.com/golift/unifi"

func main() {
	username := "admin"
	password := "superSecret1234"
	URL := "https://127.0.0.1:8443/"
	uni, err := unifi.GetController(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
	clients, err := uni.GetClients()
	if err != nil {
		log.Fatalln("Error:", err)
	}
	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)
	}
	devices, err := uni.GetDevices()
	if err != nil {
		log.Fatalln("Error:", err)
	}
	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)
	}
}