unifi

package module
v3.4.0+incompatible Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 24, 2019 License: MIT Imports: 13 Imported by: 0

README

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

Documentation

Overview

Package unifi provides a set of types to unload (unmarshal) Ubiquiti UniFi controller data. Also provided are methods to easily get data for devices - things like access points and switches, and for clients - the things connected to those access points and switches. As a bonus, each device and client type provided has an attached method to create InfluxDB datapoints.

Index

Constants

View Source
const (
	// StatusPath shows Controller version.
	StatusPath string = "/status"
	// SiteList is the path to the api site list.
	SiteList string = "/api/stat/sites"
	// ClientPath is Unifi Clients API Path
	ClientPath string = "/api/s/%s/stat/sta"
	// DevicePath is where we get data about Unifi devices.
	DevicePath string = "/api/s/%s/stat/device"
	// NetworkPath contains network-configuration data. Not really graphable.
	NetworkPath string = "/api/s/%s/rest/networkconf"
	// UserGroupPath contains usergroup configurations.
	UserGroupPath string = "/api/s/%s/rest/usergroup"
	// LoginPath is Unifi Controller Login API Path
	LoginPath string = "/api/login"
	// IPSEvents returns Intrusion Detection Systems Events
	IPSEvents string = "/api/s/%s/stat/ips/event"
)

This is a list of unifi API paths. The %s in each string must be replaced with a Site.Name.

Variables

This section is empty.

Functions

func DiscardLogs

func DiscardLogs(msg string, v ...interface{})

DiscardLogs is the default debug logger.

Types

type Client

type Client struct {
	Anomalies   int64   `json:"anomalies,omitempty"`
	ApMac       string  `json:"ap_mac"`
	ApName      string  `json:"-"`
	AssocTime   int64   `json:"assoc_time"`
	Blocked     bool    `json:"blocked,omitempty"`
	Bssid       string  `json:"bssid"`
	BytesR      int64   `json:"bytes-r"`
	Ccq         int64   `json:"ccq"`
	Channel     FlexInt `json:"channel"`
	DevCat      FlexInt `json:"dev_cat"`
	DevFamily   FlexInt `json:"dev_family"`
	DevID       FlexInt `json:"dev_id"`
	DevVendor   FlexInt `json:"dev_vendor,omitempty"`
	DhcpendTime int     `json:"dhcpend_time,omitempty"`
	DpiStats    struct {
		App       FlexInt
		Cat       FlexInt
		RxBytes   FlexInt
		RxPackets FlexInt
		TxBytes   FlexInt
		TxPackets FlexInt
	} `json:"dpi_stats"`
	DpiStatsLastUpdated int64    `json:"dpi_stats_last_updated"`
	Essid               string   `json:"essid"`
	FirstSeen           int64    `json:"first_seen"`
	FixedIP             string   `json:"fixed_ip"`
	GwMac               string   `json:"gw_mac"`
	GwName              string   `json:"-"`
	Hostname            string   `json:"hostname"`
	ID                  string   `json:"_id"`
	IP                  string   `json:"ip"`
	IdleTime            int64    `json:"idle_time"`
	Is11R               FlexBool `json:"is_11r"`
	IsGuest             FlexBool `json:"is_guest"`
	IsGuestByUAP        FlexBool `json:"_is_guest_by_uap"`
	IsGuestByUGW        FlexBool `json:"_is_guest_by_ugw"`
	IsGuestByUSW        FlexBool `json:"_is_guest_by_usw"`
	IsWired             FlexBool `json:"is_wired"`
	LastSeen            int64    `json:"last_seen"`
	LastSeenByUAP       int64    `json:"_last_seen_by_uap"`
	LastSeenByUGW       int64    `json:"_last_seen_by_ugw"`
	LastSeenByUSW       int64    `json:"_last_seen_by_usw"`
	LatestAssocTime     int64    `json:"latest_assoc_time"`
	Mac                 string   `json:"mac"`
	Name                string   `json:"name"`
	Network             string   `json:"network"`
	NetworkID           string   `json:"network_id"`
	Noise               int64    `json:"noise"`
	Note                string   `json:"note"`
	Noted               FlexBool `json:"noted"`
	OsClass             FlexInt  `json:"os_class"`
	OsName              FlexInt  `json:"os_name"`
	Oui                 string   `json:"oui"`
	PowersaveEnabled    FlexBool `json:"powersave_enabled"`
	QosPolicyApplied    FlexBool `json:"qos_policy_applied"`
	Radio               string   `json:"radio"`
	RadioName           string   `json:"radio_name"`
	RadioProto          string   `json:"radio_proto"`
	RoamCount           int64    `json:"roam_count"`
	Rssi                int64    `json:"rssi"`
	RxBytes             int64    `json:"rx_bytes"`
	RxBytesR            int64    `json:"rx_bytes-r"`
	RxPackets           int64    `json:"rx_packets"`
	RxRate              int64    `json:"rx_rate"`
	Signal              int64    `json:"signal"`
	SiteID              string   `json:"site_id"`
	SiteName            string   `json:"-"`
	SwDepth             int      `json:"sw_depth"`
	SwMac               string   `json:"sw_mac"`
	SwName              string   `json:"-"`
	SwPort              FlexInt  `json:"sw_port"`
	TxBytes             int64    `json:"tx_bytes"`
	TxBytesR            int64    `json:"tx_bytes-r"`
	TxPackets           int64    `json:"tx_packets"`
	TxPower             int64    `json:"tx_power"`
	TxRate              int64    `json:"tx_rate"`
	Uptime              int64    `json:"uptime"`
	UptimeByUAP         int64    `json:"_uptime_by_uap"`
	UptimeByUGW         int64    `json:"_uptime_by_ugw"`
	UptimeByUSW         int64    `json:"_uptime_by_usw"`
	UseFixedIP          FlexBool `json:"use_fixedip"`
	UserGroupID         string   `json:"usergroup_id"`
	UserID              string   `json:"user_id"`
	Vlan                FlexInt  `json:"vlan"`
	WifiTxAttempts      int64    `json:"wifi_tx_attempts"`
	WiredRxBytes        int64    `json:"wired-rx_bytes"`
	WiredRxBytesR       int64    `json:"wired-rx_bytes-r"`
	WiredRxPackets      int64    `json:"wired-rx_packets"`
	WiredTxBytes        int64    `json:"wired-tx_bytes"`
	WiredTxBytesR       int64    `json:"wired-tx_bytes-r"`
	WiredTxPackets      int64    `json:"wired-tx_packets"`
}

Client defines all the data a connected-network client contains.

func (*Client) Points

func (c *Client) Points() ([]*influx.Point, error)

Points generates Unifi Client datapoints for InfluxDB. These points can be passed directly to influx.

func (*Client) PointsAt

func (c *Client) PointsAt(now time.Time) ([]*influx.Point, error)

PointsAt generates Unifi Client datapoints for InfluxDB. These points can be passed directly to influx. This is just like Points(), but specify when points were created.

type Clients

type Clients []*Client

Clients contains a list that contains all of the unifi clients from a controller.

type Devices

type Devices struct {
	UAPs []*UAP
	USGs []*USG
	USWs []*USW
	UDMs []*UDM
}

Devices contains a list of all the unifi devices from a controller. Contains Access points, security gateways and switches.

type FlexBool added in v1.0.1

type FlexBool struct {
	Val bool
	Txt string
}

FlexBool provides a container and unmarshalling for fields that may be boolean or strings in the Unifi API.

func (*FlexBool) UnmarshalJSON added in v1.0.1

func (f *FlexBool) UnmarshalJSON(b []byte) error

UnmarshalJSON method converts armed/disarmed, yes/no, active/inactive or 0/1 to true/false. Really it converts ready, ok, up, t, armed, yes, active, enabled, 1, true to true. Anything else is false.

type FlexInt

type FlexInt struct {
	Val float64
	Txt string
}

FlexInt provides a container and unmarshalling for fields that may be numbers or strings in the Unifi API.

func (*FlexInt) UnmarshalJSON

func (f *FlexInt) UnmarshalJSON(b []byte) error

UnmarshalJSON converts a string or number to an integer. Generally, do call this directly, it's used in the json interface.

type IDS

type IDS struct {
	ID            string   `json:"_id"`
	Archived      FlexBool `json:"archived"`
	Timestamp     int64    `json:"timestamp"`
	FlowID        int64    `json:"flow_id"`
	InIface       string   `json:"in_iface"`
	EventType     string   `json:"event_type"`
	SrcIP         string   `json:"src_ip"`
	SrcMac        string   `json:"src_mac"`
	SrcPort       int      `json:"src_port,omitempty"`
	DestIP        string   `json:"dest_ip"`
	DstMac        string   `json:"dst_mac"`
	DestPort      int      `json:"dest_port,omitempty"`
	Proto         string   `json:"proto"`
	AppProto      string   `json:"app_proto,omitempty"`
	Host          string   `json:"host"`
	Usgip         string   `json:"usgip"`
	UniqueAlertid string   `json:"unique_alertid"`
	SrcipCountry  string   `json:"srcipCountry"`
	DstipCountry  FlexBool `json:"dstipCountry"`
	UsgipCountry  string   `json:"usgipCountry"`
	SrcipGeo      struct {
		ContinentCode string  `json:"continent_code"`
		CountryCode   string  `json:"country_code"`
		CountryCode3  string  `json:"country_code3"`
		CountryName   string  `json:"country_name"`
		Region        string  `json:"region"`
		City          string  `json:"city"`
		PostalCode    string  `json:"postal_code"`
		Latitude      float64 `json:"latitude"`
		Longitude     float64 `json:"longitude"`
		DmaCode       int64   `json:"dma_code"`
		AreaCode      int64   `json:"area_code"`
	} `json:"srcipGeo"`
	DstipGeo bool `json:"dstipGeo"`
	UsgipGeo struct {
		ContinentCode string  `json:"continent_code"`
		CountryCode   string  `json:"country_code"`
		CountryCode3  string  `json:"country_code3"`
		CountryName   string  `json:"country_name"`
		Region        string  `json:"region"`
		City          string  `json:"city"`
		PostalCode    string  `json:"postal_code"`
		Latitude      float64 `json:"latitude"`
		Longitude     float64 `json:"longitude"`
		DmaCode       int64   `json:"dma_code"`
		AreaCode      int64   `json:"area_code"`
	} `json:"usgipGeo"`
	SrcipASN              string    `json:"srcipASN"`
	DstipASN              string    `json:"dstipASN"`
	UsgipASN              string    `json:"usgipASN"`
	Catname               string    `json:"catname"`
	InnerAlertAction      string    `json:"inner_alert_action"`
	InnerAlertGid         int64     `json:"inner_alert_gid"`
	InnerAlertSignatureID int64     `json:"inner_alert_signature_id"`
	InnerAlertRev         int64     `json:"inner_alert_rev"`
	InnerAlertSignature   string    `json:"inner_alert_signature"`
	InnerAlertCategory    string    `json:"inner_alert_category"`
	InnerAlertSeverity    int64     `json:"inner_alert_severity"`
	Key                   string    `json:"key"`
	Subsystem             string    `json:"subsystem"`
	SiteID                string    `json:"site_id"`
	SiteName              string    `json:"-"`
	Time                  int64     `json:"time"`
	Datetime              time.Time `json:"datetime"`
	Msg                   string    `json:"msg"`
	IcmpType              int64     `json:"icmp_type,omitempty"`
	IcmpCode              int64     `json:"icmp_code,omitempty"`
}

IDS holds an Intrusion Prevention System Event.

func (*IDS) Points

func (i *IDS) Points() ([]*influx.Point, error)

Points generates intrusion detection datapoints for InfluxDB. These points can be passed directly to influx.

func (*IDS) PointsAt

func (i *IDS) PointsAt(now time.Time) ([]*influx.Point, error)

PointsAt has no usefulness. It is provided to satisfy external interfaces. These events have a timestamp, so that is used instead of any passed-in value. This method generates intrusion detection datapoints for InfluxDB. These points can be passed directly to influx.

type IDSList

type IDSList []*IDS

IDSList contains a list that contains all of the IDS Events on a controller.

type Logger

type Logger func(msg string, fmt ...interface{})

Logger is a base type to deal with changing log outputs. Create a logger that matches this interface to capture debug and error logs.

type Port

type Port struct {
	AggregatedBy FlexBool `json:"aggregated_by"`
	Autoneg      FlexBool `json:"autoneg,omitempty"`
	BytesR       FlexInt  `json:"bytes-r"`
	DNS          []string `json:"dns,omitempty"`
	Dot1XMode    string   `json:"dot1x_mode"`
	Dot1XStatus  string   `json:"dot1x_status"`
	Enable       FlexBool `json:"enable"`
	FlowctrlRx   FlexBool `json:"flowctrl_rx"`
	FlowctrlTx   FlexBool `json:"flowctrl_tx"`
	FullDuplex   FlexBool `json:"full_duplex"`
	IP           string   `json:"ip,omitempty"`
	Ifname       string   `json:"ifname,omitempty"`
	IsUplink     FlexBool `json:"is_uplink"`
	Mac          string   `json:"mac,omitempty"`
	Jumbo        FlexBool `json:"jumbo,omitempty"`
	Masked       FlexBool `json:"masked"`
	Media        string   `json:"media"`
	Name         string   `json:"name"`
	NetworkName  string   `json:"network_name,omitempty"`
	NumPort      int      `json:"num_port,omitempty"`
	OpMode       string   `json:"op_mode"`
	PoeCaps      FlexInt  `json:"poe_caps"`
	PoeClass     string   `json:"poe_class,omitempty"`
	PoeCurrent   FlexInt  `json:"poe_current,omitempty"`
	PoeEnable    FlexBool `json:"poe_enable,omitempty"`
	PoeGood      FlexBool `json:"poe_good,omitempty"`
	PoeMode      string   `json:"poe_mode,omitempty"`
	PoePower     FlexInt  `json:"poe_power,omitempty"`
	PoeVoltage   FlexInt  `json:"poe_voltage,omitempty"`
	PortDelta    struct {
		TimeDelta int64 `json:"time_delta"`
	} `json:"port_delta,omitempty"`
	PortIdx      FlexInt  `json:"port_idx"`
	PortPoe      FlexBool `json:"port_poe"`
	PortconfID   string   `json:"portconf_id"`
	RxBroadcast  FlexInt  `json:"rx_broadcast"`
	RxBytes      FlexInt  `json:"rx_bytes"`
	RxBytesR     FlexInt  `json:"rx_bytes-r"`
	RxDropped    FlexInt  `json:"rx_dropped"`
	RxErrors     FlexInt  `json:"rx_errors"`
	RxMulticast  FlexInt  `json:"rx_multicast"`
	RxPackets    FlexInt  `json:"rx_packets"`
	Satisfaction FlexInt  `json:"satisfaction,omitempty"`
	SfpFound     FlexBool `json:"sfp_found,omitempty"`
	Speed        FlexInt  `json:"speed"`
	SpeedCaps    FlexInt  `json:"speed_caps"`
	StpPathcost  FlexInt  `json:"stp_pathcost"`
	StpState     string   `json:"stp_state"`
	TxBroadcast  FlexInt  `json:"tx_broadcast"`
	TxBytes      FlexInt  `json:"tx_bytes"`
	TxBytesR     FlexInt  `json:"tx_bytes-r"`
	TxDropped    FlexInt  `json:"tx_dropped"`
	TxErrors     FlexInt  `json:"tx_errors"`
	TxMulticast  FlexInt  `json:"tx_multicast"`
	TxPackets    FlexInt  `json:"tx_packets"`
	Type         string   `json:"type,omitempty"`
	Up           FlexBool `json:"up"`
}

Port is a physical connection on a USW or UDM.

type Site

type Site struct {
	ID           string   `json:"_id"`
	Name         string   `json:"name"`
	Desc         string   `json:"desc"`
	SiteName     string   `json:"-"`
	AttrHiddenID string   `json:"attr_hidden_id"`
	AttrNoDelete FlexBool `json:"attr_no_delete"`
	Health       []struct {
		Subsystem       string   `json:"subsystem"`
		NumUser         FlexInt  `json:"num_user,omitempty"`
		NumGuest        FlexInt  `json:"num_guest,omitempty"`
		NumIot          FlexInt  `json:"num_iot,omitempty"`
		TxBytesR        FlexInt  `json:"tx_bytes-r,omitempty"`
		RxBytesR        FlexInt  `json:"rx_bytes-r,omitempty"`
		Status          string   `json:"status"`
		NumAp           FlexInt  `json:"num_ap,omitempty"`
		NumAdopted      FlexInt  `json:"num_adopted,omitempty"`
		NumDisabled     FlexInt  `json:"num_disabled,omitempty"`
		NumDisconnected FlexInt  `json:"num_disconnected,omitempty"`
		NumPending      FlexInt  `json:"num_pending,omitempty"`
		NumGw           FlexInt  `json:"num_gw,omitempty"`
		WanIP           string   `json:"wan_ip,omitempty"`
		Gateways        []string `json:"gateways,omitempty"`
		Netmask         string   `json:"netmask,omitempty"`
		Nameservers     []string `json:"nameservers,omitempty"`
		NumSta          FlexInt  `json:"num_sta,omitempty"`
		GwMac           string   `json:"gw_mac,omitempty"`
		GwName          string   `json:"gw_name,omitempty"`
		GwSystemStats   struct {
			CPU    FlexInt `json:"cpu"`
			Mem    FlexInt `json:"mem"`
			Uptime FlexInt `json:"uptime"`
		} `json:"gw_system-stats,omitempty"`
		GwVersion             string   `json:"gw_version,omitempty"`
		Latency               FlexInt  `json:"latency,omitempty"`
		Uptime                FlexInt  `json:"uptime,omitempty"`
		Drops                 FlexInt  `json:"drops,omitempty"`
		XputUp                FlexInt  `json:"xput_up,omitempty"`
		XputDown              FlexInt  `json:"xput_down,omitempty"`
		SpeedtestStatus       string   `json:"speedtest_status,omitempty"`
		SpeedtestLastrun      FlexInt  `json:"speedtest_lastrun,omitempty"`
		SpeedtestPing         FlexInt  `json:"speedtest_ping,omitempty"`
		LanIP                 string   `json:"lan_ip,omitempty"`
		NumSw                 FlexInt  `json:"num_sw,omitempty"`
		RemoteUserEnabled     FlexBool `json:"remote_user_enabled,omitempty"`
		RemoteUserNumActive   FlexInt  `json:"remote_user_num_active,omitempty"`
		RemoteUserNumInactive FlexInt  `json:"remote_user_num_inactive,omitempty"`
		RemoteUserRxBytes     FlexInt  `json:"remote_user_rx_bytes,omitempty"`
		RemoteUserTxBytes     FlexInt  `json:"remote_user_tx_bytes,omitempty"`
		RemoteUserRxPackets   FlexInt  `json:"remote_user_rx_packets,omitempty"`
		RemoteUserTxPackets   FlexInt  `json:"remote_user_tx_packets,omitempty"`
		SiteToSiteEnabled     FlexBool `json:"site_to_site_enabled,omitempty"`
	} `json:"health"`
	NumNewAlarms FlexInt `json:"num_new_alarms"`
}

Site represents a site's data.

func (*Site) Points

func (u *Site) Points() ([]*influx.Point, error)

Points generates Unifi Sites' datapoints for InfluxDB. These points can be passed directly to influx.

func (*Site) PointsAt

func (u *Site) PointsAt(now time.Time) ([]*influx.Point, error)

PointsAt generates Unifi Sites' datapoints for InfluxDB. These points can be passed directly to influx. This is just like Points(), but specify when points were created.

type Sites

type Sites []*Site

Sites is a struct to match Devices and Clients.

type SpeedtestStatus

type SpeedtestStatus struct {
	Latency        FlexInt `json:"latency"`
	Rundate        FlexInt `json:"rundate"`
	Runtime        FlexInt `json:"runtime"`
	ServerDesc     string  `json:"server_desc,omitempty"`
	StatusDownload FlexInt `json:"status_download"`
	StatusPing     FlexInt `json:"status_ping"`
	StatusSummary  FlexInt `json:"status_summary"`
	StatusUpload   FlexInt `json:"status_upload"`
	XputDownload   FlexInt `json:"xput_download"`
	XputUpload     FlexInt `json:"xput_upload"`
}

SpeedtestStatus is the speed test info on a USG or UDM.

type SysStats

type SysStats struct {
	Loadavg1  FlexInt `json:"loadavg_1"`
	Loadavg15 FlexInt `json:"loadavg_15"`
	Loadavg5  FlexInt `json:"loadavg_5"`
	MemBuffer FlexInt `json:"mem_buffer"`
	MemTotal  FlexInt `json:"mem_total"`
	MemUsed   FlexInt `json:"mem_used"`
}

SysStats is load info for a UDM, USG, USW.

type SystemStats

type SystemStats struct {
	CPU    FlexInt `json:"cpu"`
	Mem    FlexInt `json:"mem"`
	Uptime FlexInt `json:"uptime"`
}

SystemStats is system info for a UDM, USG, USW.

type UAP

type UAP struct {
	/* This was auto generated and then slowly edited by hand
	   to get all the data types right and graphable.
	*/
	ID           string   `json:"_id"`
	Adopted      FlexBool `json:"adopted"`
	AntennaTable []struct {
		Default   FlexBool `json:"default"`
		ID        FlexInt  `json:"id"`
		Name      string   `json:"name"`
		Wifi0Gain FlexInt  `json:"wifi0_gain"`
		Wifi1Gain FlexInt  `json:"wifi1_gain"`
	} `json:"antenna_table"`
	BandsteeringMode string `json:"bandsteering_mode,omitempty"`
	BoardRev         int    `json:"board_rev"`
	Cfgversion       string `json:"cfgversion"`
	ConfigNetwork    struct {
		Type string `json:"type"`
		IP   string `json:"ip"`
	} `json:"config_network"`
	CountrycodeTable []int `json:"countrycode_table"`
	EthernetTable    []struct {
		Mac     string  `json:"mac"`
		NumPort FlexInt `json:"num_port"`
		Name    string  `json:"name"`
	} `json:"ethernet_table"`
	FwCaps              int      `json:"fw_caps"`
	HasEth1             FlexBool `json:"has_eth1"`
	HasSpeaker          FlexBool `json:"has_speaker"`
	InformIP            string   `json:"inform_ip"`
	InformURL           string   `json:"inform_url"`
	IP                  string   `json:"ip"`
	LedOverride         string   `json:"led_override"`
	Mac                 string   `json:"mac"`
	MeshStaVapEnabled   FlexBool `json:"mesh_sta_vap_enabled"`
	Model               string   `json:"model"`
	Name                string   `json:"name"`
	OutdoorModeOverride string   `json:"outdoor_mode_override"`
	PortTable           []Port   `json:"port_table"`
	RadioTable          []struct {
		Radio              string   `json:"radio"`
		Name               string   `json:"name"`
		Channel            FlexInt  `json:"channel"`
		Ht                 string   `json:"ht"`
		TxPowerMode        string   `json:"tx_power_mode"`
		TxPower            FlexInt  `json:"tx_power"`
		MaxTxpower         FlexInt  `json:"max_txpower"`
		MinTxpower         FlexInt  `json:"min_txpower"`
		Nss                FlexInt  `json:"nss"`
		MinRssiEnabled     FlexBool `json:"min_rssi_enabled"`
		BuiltinAntenna     FlexBool `json:"builtin_antenna"`
		BuiltinAntGain     FlexInt  `json:"builtin_ant_gain"`
		CurrentAntennaGain FlexInt  `json:"current_antenna_gain"`
		RadioCaps          FlexInt  `json:"radio_caps"`
		WlangroupID        string   `json:"wlangroup_id"`
		Is11Ac             FlexBool `json:"is_11ac,omitempty"`
		HasDfs             FlexBool `json:"has_dfs,omitempty"`
		HasFccdfs          FlexBool `json:"has_fccdfs,omitempty"`
	} `json:"radio_table"`
	ScanRadioTable        []interface{} `json:"scan_radio_table"`
	Serial                string        `json:"serial"`
	SiteID                string        `json:"site_id"`
	SiteName              string        `json:"-"`
	Type                  string        `json:"type"`
	Version               string        `json:"version"`
	VwireTable            []interface{} `json:"vwire_table"`
	WifiCaps              int           `json:"wifi_caps"`
	WlangroupIDNa         string        `json:"wlangroup_id_na"`
	WlangroupIDNg         string        `json:"wlangroup_id_ng"`
	RequiredVersion       string        `json:"required_version"`
	HwCaps                int           `json:"hw_caps"`
	Unsupported           FlexBool      `json:"unsupported"`
	UnsupportedReason     FlexInt       `json:"unsupported_reason"`
	SysErrorCaps          int           `json:"sys_error_caps"`
	HasFan                FlexBool      `json:"has_fan"`
	HasTemperature        FlexBool      `json:"has_temperature"`
	DeviceID              string        `json:"device_id"`
	State                 int           `json:"state"`
	LastSeen              FlexInt       `json:"last_seen"`
	Upgradable            FlexBool      `json:"upgradable"`
	AdoptableWhenUpgraded FlexBool      `json:"adoptable_when_upgraded"`
	Rollupgrade           FlexBool      `json:"rollupgrade"`
	KnownCfgversion       string        `json:"known_cfgversion"`
	Uptime                FlexInt       `json:"uptime"`
	UUptime               FlexInt       `json:"_uptime"`
	Locating              FlexBool      `json:"locating"`
	ConnectRequestIP      string        `json:"connect_request_ip"`
	ConnectRequestPort    string        `json:"connect_request_port"`
	SysStats              SysStats      `json:"sys_stats"`
	SystemStats           SystemStats   `json:"system-stats"`
	SSHSessionTable       []interface{} `json:"ssh_session_table"`
	Scanning              FlexBool      `json:"scanning"`
	SpectrumScanning      FlexBool      `json:"spectrum_scanning"`
	GuestToken            string        `json:"guest_token"`
	Meshv3PeerMac         string        `json:"meshv3_peer_mac"`
	Satisfaction          FlexInt       `json:"satisfaction"`
	Isolated              FlexBool      `json:"isolated"`
	RadioTableStats       []struct {
		Name        string      `json:"name"`
		Channel     FlexInt     `json:"channel"`
		Radio       string      `json:"radio"`
		AstTxto     interface{} `json:"ast_txto"`
		AstCst      interface{} `json:"ast_cst"`
		AstBeXmit   FlexInt     `json:"ast_be_xmit"`
		CuTotal     FlexInt     `json:"cu_total"`
		CuSelfRx    FlexInt     `json:"cu_self_rx"`
		CuSelfTx    FlexInt     `json:"cu_self_tx"`
		Gain        FlexInt     `json:"gain"`
		State       string      `json:"state"`
		Extchannel  FlexInt     `json:"extchannel"`
		TxPower     FlexInt     `json:"tx_power"`
		TxPackets   FlexInt     `json:"tx_packets"`
		TxRetries   FlexInt     `json:"tx_retries"`
		NumSta      FlexInt     `json:"num_sta"`
		GuestNumSta FlexInt     `json:"guest-num_sta"`
		UserNumSta  FlexInt     `json:"user-num_sta"`
	} `json:"radio_table_stats"`
	Uplink struct {
		FullDuplex       FlexBool `json:"full_duplex"`
		IP               string   `json:"ip"`
		Mac              string   `json:"mac"`
		MaxVlan          int      `json:"max_vlan"`
		Name             string   `json:"name"`
		Netmask          string   `json:"netmask"`
		NumPort          int      `json:"num_port"`
		RxBytes          FlexInt  `json:"rx_bytes"`
		RxDropped        FlexInt  `json:"rx_dropped"`
		RxErrors         FlexInt  `json:"rx_errors"`
		RxMulticast      FlexInt  `json:"rx_multicast"`
		RxPackets        FlexInt  `json:"rx_packets"`
		Speed            FlexInt  `json:"speed"`
		TxBytes          FlexInt  `json:"tx_bytes"`
		TxDropped        FlexInt  `json:"tx_dropped"`
		TxErrors         FlexInt  `json:"tx_errors"`
		TxPackets        FlexInt  `json:"tx_packets"`
		Up               FlexBool `json:"up"`
		MaxSpeed         FlexInt  `json:"max_speed"`
		Type             string   `json:"type"`
		TxBytesR         FlexInt  `json:"tx_bytes-r"`
		RxBytesR         FlexInt  `json:"rx_bytes-r"`
		UplinkMac        string   `json:"uplink_mac"`
		UplinkRemotePort int      `json:"uplink_remote_port"`
	} `json:"uplink"`
	VapTable []struct {
		AnomaliesBarChart struct {
			HighTCPLatency    FlexInt `json:"high_tcp_latency"`
			HighTCPPacketLoss FlexInt `json:"high_tcp_packet_loss"`
			HighWifiLatency   FlexInt `json:"high_wifi_latency"`
			HighWifiRetries   FlexInt `json:"high_wifi_retries"`
			LowPhyRate        FlexInt `json:"low_phy_rate"`
			PoorStreamEff     FlexInt `json:"poor_stream_eff"`
			SleepyClient      FlexInt `json:"sleepy_client"`
			StaArpTimeout     FlexInt `json:"sta_arp_timeout"`
			StaDNSTimeout     FlexInt `json:"sta_dns_timeout"`
			StaIPTimeout      FlexInt `json:"sta_ip_timeout"`
			WeakSignal        FlexInt `json:"weak_signal"`
		} `json:"anomalies_bar_chart"`
		AnomaliesBarChartNow struct {
			HighTCPLatency    FlexInt `json:"high_tcp_latency"`
			HighTCPPacketLoss FlexInt `json:"high_tcp_packet_loss"`
			HighWifiLatency   FlexInt `json:"high_wifi_latency"`
			HighWifiRetries   FlexInt `json:"high_wifi_retries"`
			LowPhyRate        FlexInt `json:"low_phy_rate"`
			PoorStreamEff     FlexInt `json:"poor_stream_eff"`
			SleepyClient      FlexInt `json:"sleepy_client"`
			StaArpTimeout     FlexInt `json:"sta_arp_timeout"`
			StaDNSTimeout     FlexInt `json:"sta_dns_timeout"`
			StaIPTimeout      FlexInt `json:"sta_ip_timeout"`
			WeakSignal        FlexInt `json:"weak_signal"`
		} `json:"anomalies_bar_chart_now"`
		AvgClientSignal     FlexInt `json:"avg_client_signal"`
		Bssid               string  `json:"bssid"`
		Ccq                 int     `json:"ccq"`
		Channel             int     `json:"channel"`
		Essid               string  `json:"essid"`
		Extchannel          int     `json:"extchannel"`
		ID                  string  `json:"id"`
		MacFilterRejections int     `json:"mac_filter_rejections"`
		Name                string  `json:"name"`
		NumSatisfactionSta  FlexInt `json:"num_satisfaction_sta"`
		NumSta              int     `json:"num_sta"`
		Radio               string  `json:"radio"`
		RadioName           string  `json:"radio_name"`
		ReasonsBarChart     struct {
			PhyRate       FlexInt `json:"phy_rate"`
			Signal        FlexInt `json:"signal"`
			SleepyClient  FlexInt `json:"sleepy_client"`
			StaArpTimeout FlexInt `json:"sta_arp_timeout"`
			StaDNSTimeout FlexInt `json:"sta_dns_timeout"`
			StaIPTimeout  FlexInt `json:"sta_ip_timeout"`
			StreamEff     FlexInt `json:"stream_eff"`
			TCPLatency    FlexInt `json:"tcp_latency"`
			TCPPacketLoss FlexInt `json:"tcp_packet_loss"`
			WifiLatency   FlexInt `json:"wifi_latency"`
			WifiRetries   FlexInt `json:"wifi_retries"`
		} `json:"reasons_bar_chart"`
		ReasonsBarChartNow struct {
			PhyRate       FlexInt `json:"phy_rate"`
			Signal        FlexInt `json:"signal"`
			SleepyClient  FlexInt `json:"sleepy_client"`
			StaArpTimeout FlexInt `json:"sta_arp_timeout"`
			StaDNSTimeout FlexInt `json:"sta_dns_timeout"`
			StaIPTimeout  FlexInt `json:"sta_ip_timeout"`
			StreamEff     FlexInt `json:"stream_eff"`
			TCPLatency    FlexInt `json:"tcp_latency"`
			TCPPacketLoss FlexInt `json:"tcp_packet_loss"`
			WifiLatency   FlexInt `json:"wifi_latency"`
			WifiRetries   FlexInt `json:"wifi_retries"`
		} `json:"reasons_bar_chart_now"`
		RxBytes    FlexInt `json:"rx_bytes"`
		RxCrypts   FlexInt `json:"rx_crypts"`
		RxDropped  FlexInt `json:"rx_dropped"`
		RxErrors   FlexInt `json:"rx_errors"`
		RxFrags    FlexInt `json:"rx_frags"`
		RxNwids    FlexInt `json:"rx_nwids"`
		RxPackets  FlexInt `json:"rx_packets"`
		RxTCPStats struct {
			Goodbytes FlexInt `json:"goodbytes"`
			LatAvg    FlexInt `json:"lat_avg"`
			LatMax    FlexInt `json:"lat_max"`
			LatMin    FlexInt `json:"lat_min"`
			Stalls    FlexInt `json:"stalls"`
		} `json:"rx_tcp_stats"`
		Satisfaction      FlexInt `json:"satisfaction"`
		SatisfactionNow   FlexInt `json:"satisfaction_now"`
		State             string  `json:"state"`
		TxBytes           FlexInt `json:"tx_bytes"`
		TxCombinedRetries FlexInt `json:"tx_combined_retries"`
		TxDataMpduBytes   FlexInt `json:"tx_data_mpdu_bytes"`
		TxDropped         FlexInt `json:"tx_dropped"`
		TxErrors          FlexInt `json:"tx_errors"`
		TxPackets         FlexInt `json:"tx_packets"`
		TxPower           FlexInt `json:"tx_power"`
		TxRetries         FlexInt `json:"tx_retries"`
		TxRtsRetries      FlexInt `json:"tx_rts_retries"`
		TxSuccess         FlexInt `json:"tx_success"`
		TxTCPStats        struct {
			Goodbytes FlexInt `json:"goodbytes"`
			LatAvg    FlexInt `json:"lat_avg"`
			LatMax    FlexInt `json:"lat_max"`
			LatMin    FlexInt `json:"lat_min"`
			Stalls    FlexInt `json:"stalls"`
		} `json:"tx_tcp_stats"`
		TxTotal          FlexInt  `json:"tx_total"`
		Up               FlexBool `json:"up"`
		Usage            string   `json:"usage"`
		WifiTxAttempts   FlexInt  `json:"wifi_tx_attempts"`
		WifiTxDropped    FlexInt  `json:"wifi_tx_dropped"`
		WifiTxLatencyMov struct {
			Avg        FlexInt `json:"avg"`
			Max        FlexInt `json:"max"`
			Min        FlexInt `json:"min"`
			Total      FlexInt `json:"total"`
			TotalCount FlexInt `json:"total_count"`
		} `json:"wifi_tx_latency_mov"`
		T          string      `json:"t"`
		WlanconfID string      `json:"wlanconf_id"`
		IsGuest    FlexBool    `json:"is_guest"`
		IsWep      FlexBool    `json:"is_wep"`
		ApMac      string      `json:"ap_mac"`
		MapID      interface{} `json:"map_id"`
		SiteID     string      `json:"site_id"`
	} `json:"vap_table"`
	DownlinkTable []interface{} `json:"downlink_table"`
	VwireVapTable []interface{} `json:"vwire_vap_table"`
	BytesD        FlexInt       `json:"bytes-d"`
	TxBytesD      FlexInt       `json:"tx_bytes-d"`
	RxBytesD      FlexInt       `json:"rx_bytes-d"`
	BytesR        FlexInt       `json:"bytes-r"`
	LastUplink    struct {
		UplinkMac        string `json:"uplink_mac"`
		UplinkRemotePort int    `json:"uplink_remote_port"`
	} `json:"last_uplink"`
	Stat          UAPStat       `json:"stat"`
	TxBytes       FlexInt       `json:"tx_bytes"`
	RxBytes       FlexInt       `json:"rx_bytes"`
	Bytes         FlexInt       `json:"bytes"`
	VwireEnabled  FlexBool      `json:"vwireEnabled"`
	UplinkTable   []interface{} `json:"uplink_table"`
	NumSta        int           `json:"num_sta"`
	UserNumSta    int           `json:"user-num_sta"`
	GuestNumSta   int           `json:"guest-num_sta"`
	TwoPhaseAdopt FlexBool      `json:"two_phase_adopt,omitempty"`
}

UAP represents all the data from the Ubiquiti Controller for a Unifi Access Point.

func (*UAP) Points

func (u *UAP) Points() ([]*influx.Point, error)

Points generates Wireless-Access-Point datapoints for InfluxDB. These points can be passed directly to influx.

func (*UAP) PointsAt

func (u *UAP) PointsAt(now time.Time) ([]*influx.Point, error)

PointsAt generates Wireless-Access-Point datapoints for InfluxDB. These points can be passed directly to influx. This is just like Points(), but specify when points were created.

type UAPStat

type UAPStat struct {
	// contains filtered or unexported fields
}

UAPStat holds the "stat" data for an access point. This is split out because of a JSON data format change from 5.10 to 5.11.

func (*UAPStat) UnmarshalJSON

func (v *UAPStat) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshalls 5.10 or 5.11 formatted Access Point Stat data.

type UDM

type UDM struct {
	SiteID                string   `json:"site_id"`
	SiteName              string   `json:"-"`
	Mac                   string   `json:"mac"`
	Adopted               FlexBool `json:"adopted"`
	Serial                string   `json:"serial"`
	IP                    string   `json:"ip"`
	Uptime                FlexInt  `json:"uptime"`
	Model                 string   `json:"model"`
	Version               string   `json:"version"`
	Name                  string   `json:"hostname"`
	Default               FlexBool `json:"default"`
	Locating              FlexBool `json:"locating"`
	Type                  string   `json:"type"`
	Unsupported           FlexBool `json:"unsupported"`
	UnsupportedReason     FlexInt  `json:"unsupported_reason"`
	DiscoveredVia         string   `json:"discovered_via"`
	AdoptIP               string   `json:"adopt_ip"`
	AdoptURL              string   `json:"adopt_url"`
	State                 FlexInt  `json:"state"`
	AdoptStatus           FlexInt  `json:"adopt_status"`
	UpgradeState          FlexInt  `json:"upgrade_state"`
	LastSeen              FlexInt  `json:"last_seen"`
	AdoptableWhenUpgraded FlexBool `json:"adoptable_when_upgraded"`
	Cfgversion            string   `json:"cfgversion"`
	ConfigNetwork         struct {
		Type string `json:"type"`
		IP   string `json:"ip"`
	} `json:"config_network"`
	VwireTable             []interface{} `json:"vwire_table"`
	Dot1XPortctrlEnabled   FlexBool      `json:"dot1x_portctrl_enabled"`
	JumboframeEnabled      FlexBool      `json:"jumboframe_enabled"`
	FlowctrlEnabled        FlexBool      `json:"flowctrl_enabled"`
	StpVersion             string        `json:"stp_version"`
	StpPriority            string        `json:"stp_priority"`
	PowerSourceCtrlEnabled FlexBool      `json:"power_source_ctrl_enabled"`
	LicenseState           string        `json:"license_state"`
	ID                     string        `json:"_id"`
	DeviceID               string        `json:"device_id"`
	AdoptState             FlexInt       `json:"adopt_state"`
	AdoptTries             FlexInt       `json:"adopt_tries"`
	AdoptManual            FlexBool      `json:"adopt_manual"`
	InformURL              string        `json:"inform_url"`
	InformIP               string        `json:"inform_ip"`
	RequiredVersion        string        `json:"required_version"`
	BoardRev               FlexInt       `json:"board_rev"`
	EthernetTable          []struct {
		Mac     string  `json:"mac"`
		NumPort FlexInt `json:"num_port"`
		Name    string  `json:"name"`
	} `json:"ethernet_table"`
	PortTable         []Port `json:"port_table"`
	EthernetOverrides []struct {
		Ifname       string `json:"ifname"`
		Networkgroup string `json:"networkgroup"`
	} `json:"ethernet_overrides"`
	UsgCaps    FlexInt  `json:"usg_caps"`
	HasSpeaker FlexBool `json:"has_speaker"`
	HasEth1    FlexBool `json:"has_eth1"`
	FwCaps     FlexInt  `json:"fw_caps"`
	HwCaps     FlexInt  `json:"hw_caps"`
	SwitchCaps struct {
		MaxMirrorSessions    FlexInt `json:"max_mirror_sessions"`
		MaxAggregateSessions FlexInt `json:"max_aggregate_sessions"`
	} `json:"switch_caps"`
	HasFan            FlexBool `json:"has_fan"`
	HasTemperature    FlexBool `json:"has_temperature"`
	RulesetInterfaces struct {
		Br0  string `json:"br0"`
		Eth8 string `json:"eth8"`
		Eth9 string `json:"eth9"`
	} `json:"ruleset_interfaces"`
	KnownCfgversion      string          `json:"known_cfgversion"`
	SysStats             SysStats        `json:"sys_stats"`
	SystemStats          SystemStats     `json:"system-stats"`
	GuestToken           string          `json:"guest_token"`
	Overheating          FlexBool        `json:"overheating"`
	SpeedtestStatus      SpeedtestStatus `json:"speedtest-status"`
	SpeedtestStatusSaved FlexBool        `json:"speedtest-status-saved"`
	Wan1                 Wan             `json:"wan1"`
	Wan2                 Wan             `json:"wan2"`
	Uplink               Uplink          `json:"uplink"`
	ConnectRequestIP     string          `json:"connect_request_ip"`
	ConnectRequestPort   string          `json:"connect_request_port"`
	DownlinkTable        []interface{}   `json:"downlink_table"`
	NetworkTable         []struct {
		ID                     string   `json:"_id"`
		AttrNoDelete           FlexBool `json:"attr_no_delete"`
		AttrHiddenID           string   `json:"attr_hidden_id"`
		Name                   string   `json:"name"`
		SiteID                 string   `json:"site_id"`
		VlanEnabled            FlexBool `json:"vlan_enabled"`
		Purpose                string   `json:"purpose"`
		IPSubnet               string   `json:"ip_subnet"`
		Ipv6InterfaceType      string   `json:"ipv6_interface_type"`
		DomainName             string   `json:"domain_name"`
		IsNat                  FlexBool `json:"is_nat"`
		DhcpdEnabled           FlexBool `json:"dhcpd_enabled"`
		DhcpdStart             string   `json:"dhcpd_start"`
		DhcpdStop              string   `json:"dhcpd_stop"`
		Dhcpdv6Enabled         FlexBool `json:"dhcpdv6_enabled"`
		Ipv6RaEnabled          FlexBool `json:"ipv6_ra_enabled"`
		LteLanEnabled          FlexBool `json:"lte_lan_enabled"`
		Networkgroup           string   `json:"networkgroup"`
		DhcpdLeasetime         FlexInt  `json:"dhcpd_leasetime"`
		DhcpdDNSEnabled        FlexBool `json:"dhcpd_dns_enabled"`
		DhcpdGatewayEnabled    FlexBool `json:"dhcpd_gateway_enabled"`
		DhcpdTimeOffsetEnabled FlexBool `json:"dhcpd_time_offset_enabled"`
		Ipv6PdStart            string   `json:"ipv6_pd_start"`
		Ipv6PdStop             string   `json:"ipv6_pd_stop"`
		DhcpdDNS1              string   `json:"dhcpd_dns_1"`
		DhcpdDNS2              string   `json:"dhcpd_dns_2"`
		DhcpdDNS3              string   `json:"dhcpd_dns_3"`
		DhcpdDNS4              string   `json:"dhcpd_dns_4"`
		Enabled                FlexBool `json:"enabled"`
		DhcpRelayEnabled       FlexBool `json:"dhcp_relay_enabled"`
		Mac                    string   `json:"mac"`
		IsGuest                FlexBool `json:"is_guest"`
		IP                     string   `json:"ip"`
		Up                     FlexBool `json:"up"`
		DpistatsTable          struct {
			LastUpdated FlexInt `json:"last_updated"`
			ByCat       []struct {
				Cat       FlexInt   `json:"cat"`
				Apps      []FlexInt `json:"apps"`
				RxBytes   FlexInt   `json:"rx_bytes"`
				TxBytes   FlexInt   `json:"tx_bytes"`
				RxPackets FlexInt   `json:"rx_packets"`
				TxPackets FlexInt   `json:"tx_packets"`
			} `json:"by_cat"`
			ByApp []struct {
				App     FlexInt `json:"app"`
				Cat     FlexInt `json:"cat"`
				Clients []struct {
					Mac       string  `json:"mac"`
					RxBytes   FlexInt `json:"rx_bytes"`
					TxBytes   FlexInt `json:"tx_bytes"`
					RxPackets FlexInt `json:"rx_packets"`
					TxPackets FlexInt `json:"tx_packets"`
				} `json:"clients"`
				KnownClients FlexInt `json:"known_clients"`
				RxBytes      FlexInt `json:"rx_bytes"`
				TxBytes      FlexInt `json:"tx_bytes"`
				RxPackets    FlexInt `json:"rx_packets"`
				TxPackets    FlexInt `json:"tx_packets"`
			} `json:"by_app"`
		} `json:"dpistats_table,omitempty"`
		NumSta    FlexInt `json:"num_sta"`
		RxBytes   FlexInt `json:"rx_bytes"`
		RxPackets FlexInt `json:"rx_packets"`
		TxBytes   FlexInt `json:"tx_bytes"`
		TxPackets FlexInt `json:"tx_packets"`
	} `json:"network_table"`
	PortOverrides []struct {
		PortIdx    FlexInt `json:"port_idx"`
		PortconfID string  `json:"portconf_id"`
	} `json:"port_overrides"`
	Stat            UDMStat `json:"stat"`
	TxBytes         FlexInt `json:"tx_bytes"`
	RxBytes         FlexInt `json:"rx_bytes"`
	Bytes           FlexInt `json:"bytes"`
	NumSta          FlexInt `json:"num_sta"`
	WlanNumSta      FlexInt `json:"wlan-num_sta"`
	LanNumSta       FlexInt `json:"lan-num_sta"`
	UserWlanNumSta  FlexInt `json:"user-wlan-num_sta"`
	UserLanNumSta   FlexInt `json:"user-lan-num_sta"`
	UserNumSta      FlexInt `json:"user-num_sta"`
	GuestWlanNumSta FlexInt `json:"guest-wlan-num_sta"`
	GuestLanNumSta  FlexInt `json:"guest-lan-num_sta"`
	GuestNumSta     FlexInt `json:"guest-num_sta"`
	NumDesktop      FlexInt `json:"num_desktop"`
	NumMobile       FlexInt `json:"num_mobile"`
	NumHandheld     FlexInt `json:"num_handheld"`
}

UDM represents all the data from the Ubiquiti Controller for a Unifi Dream Machine. The UDM shares several structs/type-data with USW and USG.

func (*UDM) Points

func (u *UDM) Points() ([]*influx.Point, error)

Points generates Unifi Gateway datapoints for InfluxDB. These points can be passed directly to influx.

func (*UDM) PointsAt

func (u *UDM) PointsAt(now time.Time) ([]*influx.Point, error)

PointsAt generates Unifi Gateway datapoints for InfluxDB. These points can be passed directly to influx. This is just like Points(), but specify when points were created.

type UDMStat

type UDMStat struct {
	// contains filtered or unexported fields
}

UDMStat holds the "stat" data for a dream machine. A dream machine is a USG + USW + Controller

type USG

type USG struct {
	ID            string   `json:"_id"`
	Adopted       FlexBool `json:"adopted"`
	Cfgversion    string   `json:"cfgversion"`
	ConfigNetwork struct {
		Type string `json:"type"`
		IP   string `json:"ip"`
	} `json:"config_network"`
	EthernetTable []struct {
		Mac     string  `json:"mac"`
		NumPort FlexInt `json:"num_port"`
		Name    string  `json:"name"`
	} `json:"ethernet_table"`
	FwCaps              FlexInt `json:"fw_caps"`
	InformIP            string  `json:"inform_ip"`
	InformURL           string  `json:"inform_url"`
	IP                  string  `json:"ip"`
	LedOverride         string  `json:"led_override"`
	LicenseState        string  `json:"license_state"`
	Mac                 string  `json:"mac"`
	Model               string  `json:"model"`
	Name                string  `json:"name"`
	OutdoorModeOverride string  `json:"outdoor_mode_override"`
	Serial              string  `json:"serial"`
	SiteID              string  `json:"site_id"`
	SiteName            string  `json:"-"`
	Type                string  `json:"type"`
	UsgCaps             FlexInt `json:"usg_caps"`
	Version             string  `json:"version"`
	RequiredVersion     string  `json:"required_version"`
	EthernetOverrides   []struct {
		Ifname       string `json:"ifname"`
		Networkgroup string `json:"networkgroup"`
	} `json:"ethernet_overrides"`
	HwCaps                FlexInt         `json:"hw_caps"`
	BoardRev              FlexInt         `json:"board_rev"`
	Unsupported           FlexBool        `json:"unsupported"`
	UnsupportedReason     FlexInt         `json:"unsupported_reason"`
	DeviceID              string          `json:"device_id"`
	State                 FlexInt         `json:"state"`
	LastSeen              FlexInt         `json:"last_seen"`
	Upgradable            FlexBool        `json:"upgradable"`
	AdoptableWhenUpgraded FlexBool        `json:"adoptable_when_upgraded"`
	Rollupgrade           FlexBool        `json:"rollupgrade"`
	KnownCfgversion       string          `json:"known_cfgversion"`
	Uptime                FlexInt         `json:"uptime"`
	Locating              FlexBool        `json:"locating"`
	ConnectRequestIP      string          `json:"connect_request_ip"`
	ConnectRequestPort    string          `json:"connect_request_port"`
	SysStats              SysStats        `json:"sys_stats"`
	SystemStats           SystemStats     `json:"system-stats"`
	GuestToken            string          `json:"guest_token"`
	SpeedtestStatus       SpeedtestStatus `json:"speedtest-status"`
	SpeedtestStatusSaved  FlexBool        `json:"speedtest-status-saved"`
	Wan1                  Wan             `json:"wan1"`
	Wan2                  Wan             `json:"wan2"`
	PortTable             []struct {
		Name        string   `json:"name"`
		Ifname      string   `json:"ifname"`
		IP          string   `json:"ip"`
		Netmask     string   `json:"netmask"`
		Mac         string   `json:"mac"`
		Up          FlexBool `json:"up"`
		Speed       FlexInt  `json:"speed"`
		FullDuplex  FlexBool `json:"full_duplex"`
		RxBytes     FlexInt  `json:"rx_bytes"`
		RxDropped   FlexInt  `json:"rx_dropped"`
		RxErrors    FlexInt  `json:"rx_errors"`
		RxPackets   FlexInt  `json:"rx_packets"`
		TxBytes     FlexInt  `json:"tx_bytes"`
		TxDropped   FlexInt  `json:"tx_dropped"`
		TxErrors    FlexInt  `json:"tx_errors"`
		TxPackets   FlexInt  `json:"tx_packets"`
		RxMulticast FlexInt  `json:"rx_multicast"`
		Enable      FlexBool `json:"enable"`
		DNS         []string `json:"dns,omitempty"`
		Gateway     string   `json:"gateway,omitempty"`
	} `json:"port_table"`
	NetworkTable []struct {
		ID                     string   `json:"_id"`
		IsNat                  FlexBool `json:"is_nat"`
		DhcpdDNSEnabled        FlexBool `json:"dhcpd_dns_enabled"`
		Purpose                string   `json:"purpose"`
		DhcpdLeasetime         FlexInt  `json:"dhcpd_leasetime"`
		IgmpSnooping           FlexBool `json:"igmp_snooping"`
		DhcpguardEnabled       FlexBool `json:"dhcpguard_enabled,omitempty"`
		DhcpdStart             string   `json:"dhcpd_start"`
		Enabled                FlexBool `json:"enabled"`
		DhcpdStop              string   `json:"dhcpd_stop"`
		DhcpdWinsEnabled       FlexBool `json:"dhcpd_wins_enabled,omitempty"`
		DomainName             string   `json:"domain_name"`
		DhcpdEnabled           FlexBool `json:"dhcpd_enabled"`
		IPSubnet               string   `json:"ip_subnet"`
		Vlan                   FlexInt  `json:"vlan,omitempty"`
		Networkgroup           string   `json:"networkgroup"`
		Name                   string   `json:"name"`
		SiteID                 string   `json:"site_id"`
		DhcpdIP1               string   `json:"dhcpd_ip_1,omitempty"`
		VlanEnabled            FlexBool `json:"vlan_enabled"`
		DhcpdGatewayEnabled    FlexBool `json:"dhcpd_gateway_enabled"`
		DhcpdTimeOffsetEnabled FlexBool `json:"dhcpd_time_offset_enabled"`
		Ipv6InterfaceType      string   `json:"ipv6_interface_type"`
		DhcpRelayEnabled       FlexBool `json:"dhcp_relay_enabled"`
		Mac                    string   `json:"mac"`
		IsGuest                FlexBool `json:"is_guest"`
		IP                     string   `json:"ip"`
		Up                     FlexBool `json:"up"`
		NumSta                 FlexInt  `json:"num_sta"`
		RxBytes                FlexInt  `json:"rx_bytes"`
		RxPackets              FlexInt  `json:"rx_packets"`
		TxBytes                FlexInt  `json:"tx_bytes"`
		TxPackets              FlexInt  `json:"tx_packets"`
		DhcpdNtp1              string   `json:"dhcpd_ntp_1,omitempty"`
		DhcpdNtpEnabled        FlexBool `json:"dhcpd_ntp_enabled,omitempty"`
		DhcpdUnifiController   string   `json:"dhcpd_unifi_controller,omitempty"`
		UpnpLanEnabled         FlexBool `json:"upnp_lan_enabled,omitempty"`
		AttrNoDelete           FlexBool `json:"attr_no_delete,omitempty"`
		AttrHiddenID           string   `json:"attr_hidden_id,omitempty"`
	} `json:"network_table"`
	Uplink      Uplink  `json:"uplink"`
	Stat        USGStat `json:"stat"`
	TxBytes     FlexInt `json:"tx_bytes"`
	RxBytes     FlexInt `json:"rx_bytes"`
	Bytes       FlexInt `json:"bytes"`
	NumSta      FlexInt `json:"num_sta"`
	UserNumSta  FlexInt `json:"user-num_sta"`
	GuestNumSta FlexInt `json:"guest-num_sta"`
	NumDesktop  FlexInt `json:"num_desktop"`
	NumMobile   FlexInt `json:"num_mobile"`
	NumHandheld FlexInt `json:"num_handheld"`
}

USG represents all the data from the Ubiquiti Controller for a Unifi Security Gateway.

func (*USG) Points

func (u *USG) Points() ([]*influx.Point, error)

Points generates Unifi Gateway datapoints for InfluxDB. These points can be passed directly to influx.

func (*USG) PointsAt

func (u *USG) PointsAt(now time.Time) ([]*influx.Point, error)

PointsAt generates Unifi Gateway datapoints for InfluxDB. These points can be passed directly to influx. This is just like Points(), but specify when points were created.

type USGStat

type USGStat struct {
	// contains filtered or unexported fields
}

USGStat holds the "stat" data for a gateway. This is split out because of a JSON data format change from 5.10 to 5.11.

func (*USGStat) UnmarshalJSON

func (v *USGStat) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshalls 5.10 or 5.11 formatted Gateway Stat data.

type USW

type USW struct {
	SiteName      string   `json:"-"`
	ID            string   `json:"_id"`
	Adopted       FlexBool `json:"adopted"`
	BoardRev      FlexInt  `json:"board_rev"`
	Cfgversion    string   `json:"cfgversion"`
	ConfigNetwork struct {
		Type string `json:"type"`
		IP   string `json:"ip"`
	} `json:"config_network"`
	Dot1XPortctrlEnabled FlexBool `json:"dot1x_portctrl_enabled"`
	EthernetTable        []struct {
		Mac     string  `json:"mac"`
		NumPort FlexInt `json:"num_port,omitempty"`
		Name    string  `json:"name"`
	} `json:"ethernet_table"`
	FlowctrlEnabled     FlexBool `json:"flowctrl_enabled"`
	FwCaps              FlexInt  `json:"fw_caps"`
	HasFan              FlexBool `json:"has_fan"`
	HasTemperature      FlexBool `json:"has_temperature"`
	InformIP            string   `json:"inform_ip"`
	InformURL           string   `json:"inform_url"`
	IP                  string   `json:"ip"`
	JumboframeEnabled   FlexBool `json:"jumboframe_enabled"`
	LedOverride         string   `json:"led_override"`
	LicenseState        string   `json:"license_state"`
	Mac                 string   `json:"mac"`
	Model               string   `json:"model"`
	Name                string   `json:"name"`
	OutdoorModeOverride string   `json:"outdoor_mode_override"`
	PortOverrides       []struct {
		Name       string  `json:"name,omitempty"`
		PoeMode    string  `json:"poe_mode,omitempty"`
		PortIdx    FlexInt `json:"port_idx"`
		PortconfID string  `json:"portconf_id"`
	} `json:"port_overrides"`
	PortTable       []Port `json:"port_table"`
	Serial          string `json:"serial"`
	SiteID          string `json:"site_id"`
	StpPriority     string `json:"stp_priority"`
	StpVersion      string `json:"stp_version"`
	Type            string `json:"type"`
	Version         string `json:"version"`
	RequiredVersion string `json:"required_version"`
	SwitchCaps      struct {
		FeatureCaps          FlexInt `json:"feature_caps"`
		MaxMirrorSessions    FlexInt `json:"max_mirror_sessions"`
		MaxAggregateSessions FlexInt `json:"max_aggregate_sessions"`
	} `json:"switch_caps"`
	HwCaps                FlexInt     `json:"hw_caps"`
	Unsupported           FlexBool    `json:"unsupported"`
	UnsupportedReason     FlexInt     `json:"unsupported_reason"`
	SysErrorCaps          FlexInt     `json:"sys_error_caps"`
	DeviceID              string      `json:"device_id"`
	State                 FlexInt     `json:"state"`
	LastSeen              FlexInt     `json:"last_seen"`
	Upgradable            FlexBool    `json:"upgradable,omitempty"`
	AdoptableWhenUpgraded FlexBool    `json:"adoptable_when_upgraded,omitempty"`
	Rollupgrade           FlexBool    `json:"rollupgrade,omitempty"`
	KnownCfgversion       string      `json:"known_cfgversion"`
	Uptime                FlexInt     `json:"uptime"`
	Locating              FlexBool    `json:"locating"`
	ConnectRequestIP      string      `json:"connect_request_ip"`
	ConnectRequestPort    string      `json:"connect_request_port"`
	SysStats              SysStats    `json:"sys_stats"`
	SystemStats           SystemStats `json:"system-stats"`
	FanLevel              FlexInt     `json:"fan_level"`
	GeneralTemperature    FlexInt     `json:"general_temperature"`
	Overheating           FlexBool    `json:"overheating"`
	TotalMaxPower         FlexInt     `json:"total_max_power"`
	DownlinkTable         []struct {
		PortIdx    FlexInt  `json:"port_idx"`
		Speed      FlexInt  `json:"speed"`
		FullDuplex FlexBool `json:"full_duplex"`
		Mac        string   `json:"mac"`
	} `json:"downlink_table"`
	Uplink     Uplink `json:"uplink"`
	LastUplink struct {
		UplinkMac string `json:"uplink_mac"`
	} `json:"last_uplink"`
	UplinkDepth FlexInt `json:"uplink_depth"`
	Stat        USWStat `json:"stat"`
	TxBytes     FlexInt `json:"tx_bytes"`
	RxBytes     FlexInt `json:"rx_bytes"`
	Bytes       FlexInt `json:"bytes"`
	NumSta      FlexInt `json:"num_sta"`
	UserNumSta  FlexInt `json:"user-num_sta"`
	GuestNumSta FlexInt `json:"guest-num_sta"`
}

USW represents all the data from the Ubiquiti Controller for a Unifi Switch.

func (*USW) Points

func (u *USW) Points() ([]*influx.Point, error)

Points generates Unifi Switch datapoints for InfluxDB. These points can be passed directly to influx.

func (*USW) PointsAt

func (u *USW) PointsAt(now time.Time) ([]*influx.Point, error)

PointsAt generates Unifi Switch datapoints for InfluxDB. These points can be passed directly to influx. This is just like Points(), but specify when points were created.

type USWStat

type USWStat struct {
	// contains filtered or unexported fields
}

USWStat holds the "stat" data for a switch. This is split out because of a JSON data format change from 5.10 to 5.11.

func (*USWStat) UnmarshalJSON

func (v *USWStat) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshalls 5.10 or 5.11 formatted Switch Stat data.

type Unifi

type Unifi struct {
	*http.Client

	ErrorLog Logger
	DebugLog Logger
	// contains filtered or unexported fields
}

Unifi is what you get in return for providing a password! Unifi represents a controller that you can make authenticated requests to. Use this to make additional requests for devices, clients or other custom data. Do not set the loggers to nil. Set them to DiscardLogs if you want no logs.

func NewUnifi

func NewUnifi(user, pass, url string, verifySSL bool) (*Unifi, error)

NewUnifi creates a http.Client with authenticated cookies. Used to make additional, authenticated requests to the APIs. Start here.

func (*Unifi) GetClients

func (u *Unifi) GetClients(sites Sites) (Clients, error)

GetClients returns a response full of clients' data from the UniFi Controller.

func (*Unifi) GetData

func (u *Unifi) GetData(methodPath string, v interface{}) error

GetData makes a unifi request and unmarshal the response into a provided pointer.

func (*Unifi) GetDevices

func (u *Unifi) GetDevices(sites Sites) (*Devices, error)

GetDevices returns a response full of devices' data from the UniFi Controller.

func (*Unifi) GetIDS

func (u *Unifi) GetIDS(sites Sites, from, to time.Time) ([]*IDS, error)

GetIDS returns Intrusion Detection Systems events. Returns all events that happened in site between from and to.

func (*Unifi) GetJSON

func (u *Unifi) GetJSON(apiPath string) ([]byte, error)

GetJSON returns the raw JSON from a path. This is useful for debugging.

func (*Unifi) GetSiteIDS

func (u *Unifi) GetSiteIDS(site *Site, from, to time.Time) ([]*IDS, error)

GetSiteIDS is a helper to offload the for-loop work. This method retreives the Intrusion Detection System Data for 1 Site.

func (*Unifi) GetSites

func (u *Unifi) GetSites() (Sites, error)

GetSites returns a list of configured sites on the UniFi controller.

func (*Unifi) UniReq

func (u *Unifi) UniReq(apiPath string, params string) (req *http.Request, err error)

UniReq is a small helper function that adds an Accept header. Use this if you're unmarshalling UniFi data into custom types. And if you're doing that... sumbut a pull request with your new struct. :) This is a helper method that is exposed for convenience.

type Uplink struct {
	BytesR           FlexInt  `json:"bytes-r"`
	Drops            FlexInt  `json:"drops"`
	Enable           FlexBool `json:"enable,omitempty"`
	FullDuplex       FlexBool `json:"full_duplex"`
	Gateways         []string `json:"gateways,omitempty"`
	IP               string   `json:"ip"`
	Latency          FlexInt  `json:"latency"`
	Mac              string   `json:"mac,omitempty"`
	MaxSpeed         FlexInt  `json:"max_speed"`
	Name             string   `json:"name"`
	Nameservers      []string `json:"nameservers"`
	Netmask          string   `json:"netmask"`
	NumPort          FlexInt  `json:"num_port"`
	RxBytes          FlexInt  `json:"rx_bytes"`
	RxBytesR         FlexInt  `json:"rx_bytes-r"`
	RxDropped        FlexInt  `json:"rx_dropped"`
	RxErrors         FlexInt  `json:"rx_errors"`
	RxMulticast      FlexInt  `json:"rx_multicast"`
	RxPackets        FlexInt  `json:"rx_packets"`
	Speed            FlexInt  `json:"speed"`
	SpeedtestLastrun FlexInt  `json:"speedtest_lastrun,omitempty"`
	SpeedtestPing    FlexInt  `json:"speedtest_ping,omitempty"`
	SpeedtestStatus  string   `json:"speedtest_status,omitempty"`
	TxBytes          FlexInt  `json:"tx_bytes"`
	TxBytesR         FlexInt  `json:"tx_bytes-r"`
	TxDropped        FlexInt  `json:"tx_dropped"`
	TxErrors         FlexInt  `json:"tx_errors"`
	TxPackets        FlexInt  `json:"tx_packets"`
	Type             string   `json:"type"`
	Up               FlexBool `json:"up"`
	Uptime           FlexInt  `json:"uptime"`
	XputDown         FlexInt  `json:"xput_down,omitempty"`
	XputUp           FlexInt  `json:"xput_up,omitempty"`
}

Uplink is the Internet connection (or uplink) on a UniFi device.

type Wan

type Wan struct {
	Autoneg     FlexBool `json:"autoneg"`
	BytesR      FlexInt  `json:"bytes-r"`
	DNS         []string `json:"dns"`
	Enable      FlexBool `json:"enable"`
	FlowctrlRx  FlexBool `json:"flowctrl_rx"`
	FlowctrlTx  FlexBool `json:"flowctrl_tx"`
	FullDuplex  FlexBool `json:"full_duplex"`
	Gateway     string   `json:"gateway"` // may be deprecated
	IP          string   `json:"ip"`
	Ifname      string   `json:"ifname"`
	IsUplink    FlexBool `json:"is_uplink"`
	Mac         string   `json:"mac"`
	MaxSpeed    FlexInt  `json:"max_speed"`
	Media       string   `json:"media"`
	Name        string   `json:"name"`
	Netmask     string   `json:"netmask"` // may be deprecated
	NumPort     int      `json:"num_port"`
	PortIdx     int      `json:"port_idx"`
	PortPoe     FlexBool `json:"port_poe"`
	RxBroadcast FlexInt  `json:"rx_broadcast"`
	RxBytes     FlexInt  `json:"rx_bytes"`
	RxBytesR    FlexInt  `json:"rx_bytes-r"`
	RxDropped   FlexInt  `json:"rx_dropped"`
	RxErrors    FlexInt  `json:"rx_errors"`
	RxMulticast FlexInt  `json:"rx_multicast"`
	RxPackets   FlexInt  `json:"rx_packets"`
	Speed       FlexInt  `json:"speed"`
	TxBroadcast FlexInt  `json:"tx_broadcast"`
	TxBytes     FlexInt  `json:"tx_bytes"`
	TxBytesR    FlexInt  `json:"tx_bytes-r"`
	TxDropped   FlexInt  `json:"tx_dropped"`
	TxErrors    FlexInt  `json:"tx_errors"`
	TxMulticast FlexInt  `json:"tx_multicast"`
	TxPackets   FlexInt  `json:"tx_packets"`
	Type        string   `json:"type"`
	Up          FlexBool `json:"up"`
}

Wan is a Wan interface on a USG or UDM.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL