Coder Social home page Coder Social logo

unpoller / unifi Goto Github PK

View Code? Open in Web Editor NEW
110.0 10.0 22.0 556 KB

Go Library (w/ structures) to grab data from a Ubitquiti UniFi Controller

Home Page: https://golift.io/discord

License: MIT License

Go 100.00%
unifi-api unifi-controller go-modules go-unifi unifi-poller

unifi's Introduction

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

unifi's People

Contributors

adregner avatar bmatheny avatar davidnewhall avatar dependabot[bot] avatar it-bluefish avatar kmpm avatar platinummonkey avatar thirdmartini avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

unifi's Issues

USG - cannot unmarshal number into Go struct field .vlan of type string

Hi there, i'm getting this error in unifi-poller, which i've tracked down to the USG client type marshalling.

My guess is that the marshalling has the vlan field as a string, when it's exposed in the JSON as an integer.

https://github.com/golift/unifi/blob/master/usg_type.go#L75

Snapshot of the offending payload:

 "network_table": [
    {
      "_id": "53b5a52de4b00cc433ccc346",
      "is_nat": true,
      "purpose": "corporate",
      "dhcpd_start": "10.0.2.1",
      "dhcpd_stop": "10.0.3.254",
      "domain_name": "lan",
      "dhcpd_enabled": true,
      "ip_subnet": "10.0.0.1/22",
      "networkgroup": "LAN",
      "name": "main",
      "site_id": "53b5a522e4b00cc433ccc340",
      "attr_no_delete": true,
      "attr_hidden_id": "LAN",
      "vlan_enabled": false,
      "dhcpd_dns_enabled": true,
      "dhcpd_leasetime": 86400,
      "dhcpd_gateway_enabled": false,
      "dhcpd_time_offset_enabled": false,
      "dhcp_relay_enabled": false,
      "enabled": true,
      "ipv6_interface_type": "none",
      "dhcpd_dns_1": "10.0.1.1",
      "dhcpd_dns_2": "1.1.1.1",
      "dhcpd_dns_3": "1.0.0.1",
      "dhcpd_dns_4": "",
      "upnp_lan_enabled": false,
      "igmp_snooping": false,
      "dhcpguard_enabled": false,
      "mac": "18:e8:29:49:af:a9",
      "is_guest": false,
      "ip": "10.0.0.1",
      "up": "true",
      "num_sta": 12,
      "rx_bytes": 449934776894,
      "rx_packets": 379649461,
      "tx_bytes": 201930232054,
      "tx_packets": 307391431
    },
    {
      "_id": "5d0d7a4fa3de99046bf3da0e",
      "purpose": "corporate",
      "networkgroup": "LAN",
      "dhcpd_enabled": true,
      "dhcpd_leasetime": 86400,
      "dhcpd_dns_enabled": false,
      "dhcpd_gateway_enabled": false,
      "dhcpd_time_offset_enabled": false,
      "ipv6_interface_type": "none",
      "name": "iot",
      "ip_subnet": "10.0.20.1/24",
      "vlan": 20,
      "dhcpd_start": "10.0.20.10",
      "dhcpd_stop": "10.0.20.254",
      "enabled": true,
      "is_nat": true,
      "dhcp_relay_enabled": false,
      "vlan_enabled": true,
      "site_id": "53b5a522e4b00cc433ccc340",
      "dhcpguard_enabled": false,
      "upnp_lan_enabled": false,
      "igmp_snooping": false,
      "mac": "18:e8:29:49:af:a9",
      "is_guest": false,
      "ip": "10.0.20.1",
      "up": "true",
      "num_sta": 3,
      "rx_bytes": 372685754,
      "rx_packets": 589147,
      "tx_bytes": 65800600,
      "tx_packets": 612741
    },
    {
      "_id": "5a6d0b72e4b04c618946806e",
      "is_nat": true,
      "dhcpd_dns_enabled": false,
      "purpose": "guest",
      "dhcpd_leasetime": 86400,
      "dhcpd_gateway_enabled": false,
      "dhcpd_time_offset_enabled": false,
      "dhcpd_start": "10.0.10.6",
      "dhcp_relay_enabled": false,
      "dhcpd_stop": "10.0.10.254",
      "enabled": true,
      "dhcpd_enabled": true,
      "vlan": 10,
      "ip_subnet": "10.0.10.1/24",
      "networkgroup": "LAN",
      "name": "guest",
      "vlan_enabled": true,
      "site_id": "53b5a522e4b00cc433ccc340",
      "dhcpd_dns_1": "10.0.1.1",
      "dhcpd_dns_2": "10.0.0.2",
      "ipv6_interface_type": "none",
      "dhcpguard_enabled": false,
      "upnp_lan_enabled": false,
      "igmp_snooping": false,
      "mac": "18:e8:29:49:af:a9",
      "is_guest": true,
      "ip": "10.0.10.1",
      "up": "true",
      "num_sta": 0,
      "rx_bytes": 0,
      "rx_packets": 0,
      "tx_bytes": 0,
      "tx_packets": 0
    }
  ],

Uncomment lines 255 to 338 in uap.go

Hey,

I currently use this library to gather telemetry from my unifi controller. I want to get aggregated wifi stats per radio but it appears that they have been commented out because they can be found in the VAP tables (uap.go lines 255 - 338). Is there anyway these can be uncommented since the aggregation of stats is useful? Also are the VAP tables the stats per radio and per ssid?

Thanks!

Misleading function names

Hi,

i am working on a terraform provider to configure the unifi controller.
I started with using your library but then realized that all functions are just reporting the stats and not the configuration endpoints.

I forked your lib and gonna do some rewrites based on the api stuff from node-unifi.

I would also like to create a PR after finishing the adding, but i struggle with if a renaming of the existing functions is better than creating wired function names on getSites() and rename the existing to getSitesStats() for example..

Question: PDU Power Pro - Outlet stats

It looks like you have the PDU per-outlet stats (power, etc) but I can't see how to pull them via the API or graph them in Grafana. Can you tell me how to access them?

[Feature Request] UDM storage utilization

As an administrator I'd like to have a report on storage utilization on my UDM/UDM Pro.
The device object contains this information, please make it available via the poller.

This could be achieved by adding the following entry to UDM struct (https://github.com/unifi-poller/unifi/blob/master/udm.go):

Storage     []struct {
    MountPoint  string  `json:"mount_point"`
    Name        string  `json:"name"`
    Type        string  `json:"type"`
    Size        FlexInt `json:"size"`
    Used        FlexInt `json:"used"`
} `json:"storage"`

Thanks and keep up the great work!

Edit Note for Client

Hi!
My suggestion is adding functional which will insert Note for Client.
In my company I develop script which handle anomalies.
And for every client would like to see and edit information in Note:

  • Number of ticket for support
  • or Exception, if user exclude from monitoring
  • or name of nout's AP
  • and other

Thanks for your Great work!

Docs link on GitHub is wrong

The website link on GitHub is to https://godoc.org/golift.io/unifi which made me import and try to use that package. It was a while before I noticed that the version was mismatched somehow and that things weren't working that should, then I noticed the readme used the GitHub import path directly and changing to that fixed my project. Please change the documentation link to point at GitHub if this other import path was an old one that's no longer used but still has cached tags that no longer exist or something. Thanks!

Feature request: configurable client data collection

Please consider making client data collection configurable: enabled or disabled. For certain PII-sensitive use cases, MD5 obfuscation may not be adequate. If a user's MAC address or name is known, for example, the obfuscated version could be calculated by an attacker and then tracked in the obfuscated data.

unpoller is a great contribution to the community ... thanks!

cannot unmarshal number into Go struct field USW.stp_priority of type string

Running UniFi Controller 5.11.39 & USW 4.0.54.10625

Sep 13 10:40:10 localhost unifi-poller[4130]: 2019/09/13 10:40:10.461631 devices.go:76: [ERROR] json.Unmarshal(usw): json: cannot unmarshal number into Go struct field USW.stp_priority of type string Sep 13 10:40:10 localhost unifi-poller[4130]: 2019/09/13 10:40:10.461673 devices.go:77: [ERROR] Enable Debug Logging to output the failed payload. Sep 13 10:40:10 localhost unifi-poller[4130]: 2019/09/13 10:40:10.461732 devices.go:79: [DEBUG] Failed Payload: {"_id":"598c2e16f62eb3ad7244b62b","inform_url":"http://unifi.foo.bar:8080/inform","port_table":[{"port_idx":1,"media":"GE","port_poe":true,"poe_caps":7,"speed_caps":1048623,"op_mode":"switch","portconf_id":"597f622ef62e74498be19d82","poe_mode":"auto","autoneg":true,"dot1x_mode":"unknown","dot1x_status":"disabled","enable":true,"flowctrl_rx":false,"flowctrl_tx":false,"full_duplex":true,"is_uplink":false,"jumbo":false,"lldp_table":[],"poe_class":"Class 4","poe_current":"74.70","poe_enable":true,"poe_good":true,"poe_power":"3.99","poe_voltage":"53.40","rx_broadcast":40941,"rx_bytes":23231572387,"rx_dropped":0,"rx_errors":0,"rx_multicast":1703530,"rx_packets":165271401,"satisfaction":100,"speed":1000,"stp_pathcost":20000,"stp_state":"forwarding","tx_broadcast":587533,"tx_bytes":906402777198,"tx_dropped":0,"tx_errors":0,"tx_multicast":2194058,"tx_packets":628804357,"up":true,"tx_bytes-r":520986,"rx_bytes-r":5198,"bytes-r":526184,"isolation":false,"name":"ge-0.wap1.site1.foo.bar","stormctrl_bcast_enabled":false,"stormctrl_mcast_enabled":false,"stormctrl_ucast_enabled":false,"masked":false,"aggregated_by":false},{"port_idx":2,"media":"GE","port_poe":true,"poe_caps":7,"speed_caps":1048623,"op_mode":"switch","portconf_id":"597f622ef62e74498be19d82","poe_mode":"auto","autoneg":true,"dot1x_mode":"unknown","dot1x_status":"disabled","enable":true,"flowctrl_rx":false,"flowctrl_tx":false,"full_duplex":true,"is_uplink":false,"jumbo":false,"lldp_table":[],"poe_class":"Class 4","poe_current":"60.18","poe_enable":true,"poe_good":true,"poe_power":"3.21","poe_voltage":"53.27","rx_broadcast":196256,"rx_bytes":2164756965,"rx_dropped":0,"rx_errors":0,"rx_multicast":87644,"rx_packets":8247525,"satisfaction":100,"speed":1000,"stp_pathcost":20000,"stp_state":"forwarding","tx_broadcast":431939,"tx_bytes":13824027908,"tx_dropped":0,"tx_errors":0,"tx_multicast":3809944,"tx_packets":15549138,"up":true,"tx_bytes-r":393,"rx_bytes-r":149,"bytes-r":542,"isolation":false,"name":"g Sep 13 10:40:10 localhost unifi-poller[4130]: e-0.wap2.site1.foo.bar","stormctrl_bcast_enabled":false,"stormctrl_mcast_enabled":false,"stormctrl_ucast_enabled":false,"masked":false,"aggregated_by":false},{"port_idx":3,"media":"GE","port_poe":true,"poe_caps":7,"speed_caps":1048623,"op_mode":"switch","portconf_id":"597f622ef62e74498be19d84","poe_mode":"auto","autoneg":true,"dot1x_mode":"unknown","dot1x_status":"disabled","enable":true,"flowctrl_rx":false,"flowctrl_tx":false,"full_duplex":true,"is_uplink":false,"jumbo":false,"lldp_table":[],"poe_class":"Class 4","poe_current":"59.44","poe_enable":true,"poe_good":true,"poe_power":"3.16","poe_voltage":"53.14","rx_broadcast":83,"rx_bytes":377675043937,"rx_dropped":0,"rx_errors":0,"rx_multicast":0,"rx_packets":277354243,"satisfaction":100,"speed":100,"stp_pathcost":200000,"stp_state":"forwarding","tx_broadcast":628326,"tx_bytes":12096103183,"tx_dropped":0,"tx_errors":0,"tx_multicast":3897647,"tx_packets":161755046,"up":true,"tx_bytes-r":3982,"rx_bytes-r":110501,"bytes-r":114484,"name":"unifi-video-cottage","masked":false,"aggregated_by":false},{"port_idx":4,"media":"GE","port_poe":true,"poe_caps":7,"speed_caps":1048623,"op_mode":"switch","portconf_id":"597f622ef62e74498be19d83","poe_mode":"auto","autoneg":true,"dot1x_mode":"unknown","dot1x_status":"disabled","enable":false,"flowctrl_rx":false,"flowctrl_tx":false,"full_duplex":false,"is_uplink":false,"jumbo":false,"lldp_table":[],"poe_class":"Unknown","poe_current":"0.00","poe_enable":false,"poe_good":false,"poe_power":"0.00","poe_voltage":"0.00","rx_broadcast":0,"rx_bytes":0,"rx_dropped":0,"rx_errors":0,"rx_multicast":0,"rx_packets":0,"satisfaction":100,"speed":0,"stp_pathcost":0,"stp_state":"disabled","tx_broadcast":0,"tx_bytes":0,"tx_dropped":0,"tx_errors":0,"tx_multicast":0,"tx_packets":0,"up":false,"tx_bytes-r":0,"rx_bytes-r":0,"bytes-r":0,"isolation":false,"name":"Port 4","stormctrl_bcast_enabled":false,"stormctrl_mcast_enabled":false,"stormctrl_ucast_enabled":false,"masked":false,"aggregated_by":false},{"port_idx":5,"media":"GE","port_poe":true,"poe_caps" Sep 13 10:40:10 localhost unifi-poller[4130]: :7,"speed_caps":1048623,"op_mode":"switch","portconf_id":"597f622ef62e74498be19d82","poe_mode":"auto","autoneg":true,"dot1x_mode":"unknown","dot1x_status":"disabled","enable":true,"flowctrl_rx":false,"flowctrl_tx":false,"full_duplex":true,"is_uplink":false,"jumbo":false,"lldp_table":[],"poe_class":"Unknown","poe_current":"0.00","poe_enable":false,"poe_good":false,"poe_power":"0.00","poe_voltage":"0.00","rx_broadcast":40,"rx_bytes":229233398,"rx_dropped":0,"rx_errors":0,"rx_multicast":388873,"rx_packets":810480,"satisfaction":100,"speed":100,"stp_pathcost":200000,"stp_state":"forwarding","tx_broadcast":628370,"tx_bytes":747328563,"tx_dropped":0,"tx_errors":0,"tx_multicast":3508775,"tx_packets":4480680,"up":true,"tx_bytes-r":319,"rx_bytes-r":84,"bytes-r":403,"name":"Port 5","masked":false,"aggregated_by":false},{"port_idx":6,"media":"GE","port_poe":true,"poe_caps":7,"speed_caps":1048623,"op_mode":"switch","portconf_id":"597f622ef62e74498be19d82","poe_mode":"off","autoneg":true,"dot1x_mode":"unknown","dot1x_status":"disabled","enable":true,"flowctrl_rx":false,"flowctrl_tx":false,"full_duplex":true,"is_uplink":false,"jumbo":false,"lldp_table":[],"poe_class":"Unknown","poe_current":"0.00","poe_enable":false,"poe_good":false,"poe_power":"0.00","poe_voltage":"0.00","rx_broadcast":112384,"rx_bytes":394476944,"rx_dropped":0,"rx_errors":0,"rx_multicast":24114,"rx_packets":3413514,"satisfaction":100,"speed":100,"stp_pathcost":200000,"stp_state":"forwarding","tx_broadcast":516019,"tx_bytes":1059874327,"tx_dropped":0,"tx_errors":0,"tx_multicast":3873531,"tx_packets":7668436,"up":true,"tx_bytes-r":441,"rx_bytes-r":151,"bytes-r":593,"name":"en-0.ups1.site1.foo.bar","masked":false,"aggregated_by":false},{"port_idx":7,"media":"GE","port_poe":true,"poe_caps":7,"speed_caps":1048623,"op_mode":"switch","portconf_id":"597f622ef62e74498be19d82","poe_mode":"off","autoneg":true,"dot1x_mode":"unknown","dot1x_status":"disabled","enable":true,"flowctrl_rx":false,"flowctrl_tx":false,"full_duplex":true,"is_uplink":false,"jumbo":false,"lld Sep 13 10:40:10 localhost unifi-poller[4130]: p_table":[],"poe_class":"Unknown","poe_current":"0.00","poe_enable":false,"poe_good":false,"poe_power":"0.00","poe_voltage":"0.00","rx_broadcast":160,"rx_bytes":2011157563,"rx_dropped":0,"rx_errors":0,"rx_multicast":118035,"rx_packets":12252923,"satisfaction":100,"speed":100,"stp_pathcost":200000,"stp_state":"forwarding","tx_broadcast":628246,"tx_bytes":9768120171,"tx_dropped":0,"tx_errors":0,"tx_multicast":3779641,"tx_packets":22863939,"up":true,"tx_bytes-r":833,"rx_bytes-r":851,"bytes-r":1684,"name":"en-0.raspberrypi.site1.foo.bar","masked":false,"aggregated_by":false},{"port_idx":8,"media":"GE","port_poe":true,"poe_caps":7,"speed_caps":1048623,"op_mode":"switch","portconf_id":"597f622ef62e74498be19d83","poe_mode":"off","autoneg":true,"dot1x_mode":"unknown","dot1x_status":"disabled","enable":false,"flowctrl_rx":false,"flowctrl_tx":false,"full_duplex":false,"is_uplink":false,"jumbo":false,"lldp_table":[],"poe_class":"Unknown","poe_current":"0.00","poe_enable":false,"poe_good":false,"poe_power":"0.00","poe_voltage":"0.00","rx_broadcast":0,"rx_bytes":0,"rx_dropped":0,"rx_errors":0,"rx_multicast":0,"rx_packets":0,"satisfaction":100,"speed":0,"stp_pathcost":0,"stp_state":"disabled","tx_broadcast":0,"tx_bytes":0,"tx_dropped":0,"tx_errors":0,"tx_multicast":0,"tx_packets":0,"up":false,"tx_bytes-r":0,"rx_bytes-r":0,"bytes-r":0,"name":"Port 8","masked":false,"aggregated_by":false},{"port_idx":9,"media":"SFP","port_poe":false,"poe_caps":0,"speed_caps":1048608,"op_mode":"switch","portconf_id":"597f622ef62e74498be19d82","autoneg":true,"dot1x_mode":"unknown","dot1x_status":"disabled","enable":true,"flowctrl_rx":false,"flowctrl_tx":false,"full_duplex":true,"is_uplink":true,"jumbo":false,"lldp_table":[{"lldp_chassis_id":"78:8A:20:FD:62:EE","lldp_port_id":"0/26","lldp_system_name":"cr-sw2"}],"rx_broadcast":212212,"rx_bytes":931434428704,"rx_dropped":0,"rx_errors":0,"rx_multicast":1575479,"rx_packets":804298097,"satisfaction":100,"sfp_compliance":"Unknown","sfp_current":"0.000","sfp_found":true,"sfp_part":"SFP-GE-BX","sfp_re Sep 13 10:40:10 localhost unifi-poller[4130]: v":"A0","sfp_rxfault":false,"sfp_rxpower":"-40.00","sfp_serial":"D87B2338304","sfp_temperature":"51.562","sfp_txfault":false,"sfp_txpower":"-40.00","sfp_vendor":"FiberStore","sfp_voltage":"3.356","speed":1000,"stp_pathcost":20000,"stp_state":"forwarding","tx_broadcast":416500,"tx_bytes":397567018879,"tx_dropped":0,"tx_errors":0,"tx_multicast":2417485,"tx_packets":453438238,"up":true,"tx_bytes-r":116758,"rx_bytes-r":524926,"bytes-r":641685,"name":"cr-sw2.site1.foo.bar","masked":false,"aggregated_by":false},{"port_idx":10,"media":"SFP","port_poe":false,"poe_caps":0,"speed_caps":1048608,"op_mode":"switch","portconf_id":"597f622ef62e74498be19d83","autoneg":true,"dot1x_mode":"unknown","dot1x_status":"disabled","enable":false,"flowctrl_rx":false,"flowctrl_tx":false,"full_duplex":false,"is_uplink":false,"jumbo":false,"lldp_table":[],"rx_broadcast":0,"rx_bytes":0,"rx_dropped":0,"rx_errors":0,"rx_multicast":0,"rx_packets":0,"satisfaction":100,"sfp_found":false,"speed":0,"stp_pathcost":0,"stp_state":"disabled","tx_broadcast":0,"tx_bytes":0,"tx_dropped":0,"tx_errors":0,"tx_multicast":0,"tx_packets":0,"up":false,"tx_bytes-r":0,"rx_bytes-r":0,"bytes-r":0,"isolation":false,"name":"SFP 2","poe_mode":"off","stormctrl_bcast_enabled":false,"stormctrl_mcast_enabled":false,"stormctrl_ucast_enabled":false,"masked":false,"aggregated_by":false}],"cfgversion":"e6b97905f1f641e6","model":"US8P150","fw_caps":4906533,"mac":"f0:9f:c2:68:1c:53","led_override":"default","ethernet_table":[{"mac":"f0:9f:c2:68:1c:53","num_port":10,"name":"eth0"},{"mac":"f0:9f:c2:68:1c:54","name":"srv0"}],"port_overrides":[{"autoneg":true,"isolation":false,"name":"ge-0.wap1.site1.foo.bar","op_mode":"switch","poe_mode":"auto","port_idx":1,"portconf_id":"597f622ef62e74498be19d82","stormctrl_bcast_enabled":false,"stormctrl_mcast_enabled":false,"stormctrl_ucast_enabled":false},{"autoneg":true,"isolation":false,"name":"ge-0.wap2.site1.foo.bar","op_mode":"switch","poe_mode":"auto","port_idx":2,"portconf_id":"597f622ef62e74498be19d82","stormctrl_bcast_enabled Sep 13 10:40:10 localhost unifi-poller[4130]: ":false,"stormctrl_mcast_enabled":false,"stormctrl_ucast_enabled":false},{"name":"unifi-video-cottage","poe_mode":"auto","port_idx":3,"portconf_id":"597f622ef62e74498be19d84"},{"autoneg":true,"isolation":false,"name":"Port 4","op_mode":"switch","poe_mode":"auto","port_idx":4,"portconf_id":"597f622ef62e74498be19d83","stormctrl_bcast_enabled":false,"stormctrl_mcast_enabled":false,"stormctrl_ucast_enabled":false},{"name":"Port 5","poe_mode":"auto","port_idx":5,"portconf_id":"597f622ef62e74498be19d82"},{"name":"en-0.ups1.site1.foo.bar","poe_mode":"off","port_idx":6,"portconf_id":"597f622ef62e74498be19d82"},{"name":"en-0.raspberrypi.site1.foo.bar","poe_mode":"off","port_idx":7,"portconf_id":"597f622ef62e74498be19d82"},{"poe_mode":"off","port_idx":8,"portconf_id":"597f622ef62e74498be19d83"},{"name":"cr-sw2.site1.foo.bar","port_idx":9,"portconf_id":"597f622ef62e74498be19d82"},{"autoneg":true,"isolation":false,"name":"SFP 2","op_mode":"switch","poe_mode":"off","port_idx":10,"portconf_id":"597f622ef62e74498be19d83","stormctrl_bcast_enabled":false,"stormctrl_mcast_enabled":false,"stormctrl_ucast_enabled":false}],"type":"usw","version":"4.0.54.10625","board_rev":12,"adopted":true,"name":"cr-sw1","stp_version":"rstp","config_network":{"type":"dhcp","ip":"192.168.1.214"},"jumboframe_enabled":false,"site_id":"597f622ef62e74498be19d79","dot1x_portctrl_enabled":false,"ip":"10.10.0.28","has_fan":false,"license_state":"registered","stp_priority":8192,"flowctrl_enabled":false,"inform_ip":"134.209.247.121","serial":"F09FC2681C53","has_temperature":true,"hw_caps":0,"mgmt_network_id":"597f622ef62e74498be19d7e","snmp_location":"cottage","switch_caps":{"feature_caps":1022,"max_mirror_sessions":1,"max_aggregate_sessions":5},"required_version":"3.3.11","unsupported":false,"unsupported_reason":0,"sys_error_caps":0,"two_phase_adopt":false,"device_id":"598c2e16f62eb3ad7244b62b","state":1,"last_seen":1568371207,"satisfaction":100,"known_cfgversion":"e6b97905f1f641e6","uptime":2893946,"_uptime":2893946,"locating":false,"connect_req Sep 13 10:40:10 localhost unifi-poller[4130]: uest_ip":"84.240.91.119","connect_request_port":"56139","sys_stats":{"loadavg_1":"2.28","loadavg_15":"1.68","loadavg_5":"1.87","mem_buffer":0,"mem_total":262397952,"mem_used":131788800},"system-stats":{"cpu":"56.1","mem":"50.2","uptime":"2891844"},"ssh_session_table":[],"general_temperature":59,"overheating":false,"total_max_power":140,"downlink_table":[{"port_idx":1,"speed":1000,"full_duplex":true,"mac":"f0:9f:c2:79:8b:0a"},{"port_idx":2,"speed":1000,"full_duplex":true,"mac":"78:8a:20:20:5f:9d"}],"uplink":{"full_duplex":true,"ip":"10.10.0.28","mac":"f0:9f:c2:68:1c:53","name":"eth0","netmask":"255.255.255.0","num_port":10,"rx_bytes":931434428704,"rx_dropped":0,"rx_errors":0,"rx_multicast":0,"rx_packets":804298097,"speed":1000,"tx_bytes":397567018879,"tx_dropped":0,"tx_errors":0,"tx_packets":453438238,"up":true,"port_idx":9,"media":"SFP","max_speed":1000,"uplink_mac":"78:8a:20:fd:62:ee","uplink_remote_port":26,"type":"wire","tx_bytes-r":116758,"rx_bytes-r":524926},"uplink_depth":2,"dhcp_server_table":[],"upgradable":false,"adoptable_when_upgraded":false,"rollupgrade":false,"last_uplink":{"uplink_mac":"78:8a:20:fd:62:ee"},"next_interval":80,"next_heartbeat_at":1568371297,"considered_lost_at":1568371477,"stat":{"sw":{"site_id":"597f622ef62e74498be19d79","o":"sw","oid":"f0:9f:c2:68:1c:53","sw":"f0:9f:c2:68:1c:53","time":1567676100000,"datetime":"2019-09-05T09:35:00Z","rx_packets":3.28377767E8,"rx_bytes":3.47723382756E11,"rx_errors":0.0,"rx_dropped":0.0,"rx_crypts":0.0,"rx_frags":0.0,"tx_packets":3.33752292E8,"tx_bytes":3.48707873436E11,"tx_errors":0.0,"tx_dropped":0.0,"tx_retries":0.0,"rx_multicast":918801.0,"rx_broadcast":126620.0,"tx_multicast":5535779.0,"tx_broadcast":872315.0,"bytes":6.96431256192E11,"duration":6.94947E8,"port_1-rx_packets":4.2225772E7,"port_1-rx_bytes":4.791957175E9,"port_1-tx_packets":1.65409036E8,"port_1-tx_bytes":2.3815386298E11,"port_1-rx_multicast":390387.0,"port_1-tx_multicast":528424.0,"port_1-tx_broadcast":133081.0,"port_2-rx_packets":1720237.0,"port_2-rx_bytes":3.01605592E8,"port_2-tx_p Sep 13 10:40:10 localhost unifi-poller[4130]: ackets":3334724.0,"port_2-tx_bytes":2.857029313E9,"port_2-rx_multicast":18983.0,"port_2-rx_broadcast":48208.0,"port_2-tx_multicast":899828.0,"port_2-tx_broadcast":94471.0,"port_3-rx_packets":7.1541662E7,"port_3-rx_bytes":9.8190437738E10,"port_3-tx_packets":4.0955965E7,"port_3-tx_bytes":3.045086966E9,"port_3-tx_multicast":918811.0,"port_3-tx_broadcast":142660.0,"port_5-tx_packets":1032805.0,"port_5-tx_bytes":1.64499058E8,"port_5-tx_multicast":825463.0,"port_5-tx_broadcast":142678.0,"port_6-rx_packets":820084.0,"port_6-rx_bytes":9.4615774E7,"port_6-tx_packets":1816504.0,"port_6-tx_bytes":2.43823307E8,"port_6-tx_multicast":913019.0,"port_6-tx_broadcast":115698.0,"port_7-rx_packets":2740205.0,"port_7-rx_bytes":4.55707009E8,"port_7-tx_packets":3409285.0,"port_7-tx_bytes":4.69288209E8,"port_7-rx_multicast":31714.0,"port_7-tx_multicast":887097.0,"port_7-tx_broadcast":142647.0,"port_9-rx_packets":2.09150305E8,"port_9-rx_bytes":2.43840711657E11,"port_9-tx_packets":1.17793973E8,"port_9-tx_bytes":1.03774283603E11,"port_9-rx_multicast":378578.0,"port_9-rx_broadcast":41690.0,"port_9-tx_multicast":563137.0,"port_9-tx_broadcast":101080.0,"port_1-rx_broadcast":9689.0,"port_5-rx_packets":179502.0,"port_5-rx_bytes":4.8347811E7,"port_5-rx_multicast":93348.0,"port_6-rx_broadcast":26981.0,"port_6-rx_multicast":5791.0,"port_3-rx_broadcast":19.0,"port_7-rx_broadcast":32.0,"port_5-rx_broadcast":1.0}},"tx_bytes":931434428704,"rx_bytes":397567018879,"bytes":1329001447583,"num_sta":4,"user-num_sta":4,"guest-num_sta":0} (marshal err: <nil>) Sep 13 10:40:10 localhost unifi-poller[4130]: 2019/09/13 10:40:10.461762 devices.go:80: [DEBUG] The above payload can prove useful during torubleshooting when you open an Issue: Sep 13 10:40:10 localhost unifi-poller[4130]: 2019/09/13 10:40:10.461785 devices.go:81: [DEBUG] ==- https://github.com/golift/unifi/issues/new -==

Power Cycle Ports

Great tool. I would like to have the ability to power cycle ports on a POE switch.
Based on https://ubntwiki.com/products/software/unifi-controller/api Something like the following:
func (api *Unifi) PowerCycle(site string, switch_mac string, portIndex int) error {
manager := "devmgr"
command := "power-cycle"

    jsonString := fmt.Sprintf(`"data":[{"cmd":"%s","mac":"%s","port_idx":%d}]`, command, switch_mac, portIndex)
    fmt.Println("JSON:  " + jsonString)
    url := fmt.Sprintf("/proxy/network/api/s/%s/cmd/%s", site, manager)
    req := struct {
            Command   string `json:"cmd"`
            Mac       string `json:"mac"`
            PortIndex int    `json:"port_idx"`
    }{
            Command:   command,
            Mac:       switch_mac,
            PortIndex: portIndex,
    }
    return api.postCommand(url, &req, &json.RawMessage{}, reqOpts{})

}

Feature [set settings] - Firewall Rule updates

You mentioned in the readme that your not against maybe a few functions that set data.

So I have a WAN firewall rule designed to let a certain list of ip addresses in on a certain port.
I'd like to be able to update the source IP addresses programically (if the API can do that)
Technically in my case I use a Firewall ipv4 Group, so I'm looking for a way to actually update the group membership

Device tags

Hi!

Can it to get "device tags"?
image

image

I tried to review all methods and structures, but found nothing, unfortunately...

Thanks!

json.Unmarshal(ugw): json: cannot unmarshal string into Go struct field SystemStats.system-stats.temps of type map[string]string

Hi i ran into this issue when running the unifi poller in docker:

json.Unmarshal(ugw): json: cannot unmarshal string into Go struct field SystemStats.system-stats.temps of type map[string]string

I enabled debug logs to check, and it looks like the temps field is an empty string. Not sure why that is, but it keeps the whole thing from working correctly.

{
"_id": "5dbadcxxxxxxxxxxxx4101c6f33",
"ip": "xxx.xxx.xxx.98",
"mac": "XX:XX:XX:XX:XX:XX",
"model": "UGW4",
"type": "ugw",
"version": "4.4.55.5377109",
"adopted": true,
"site_id": "5c653f14xxxxxxxxxxx72a9c",
"license_state": "registered",
"board_rev": 18,
"name": "USG",
"kernel_version": "3.10.107-UBNT",
"architecture": "mips64",
"model_incompatible": false,
"model_in_lts": false,
"model_in_eol": false,
"connected_at": 1616608597,
"provisioned_at": 1618489821,
"device_id": "5dbadcxxxxxxxxxxxx4101c6f33",
"state": 1,
"start_disconnected_millis": 1617836549326,
"last_seen": 1619452806,
"known_cfgversion": "6456170f42b3ed10",
"use_custom_config": false,
"start_connected_millis": 1617836549515,
"upgradable": false,
"adoptable_when_upgraded": false,
"rollupgrade": false,
"uptime": 1616358,
"_uptime": 1616358,
"locating": false,
"sys_stats": {
	"loadavg_1": "0.05",
	"loadavg_15": "0.13",
	"loadavg_5": "0.10",
	"mem_buffer": 51363840,
	"mem_total": 2089517056,
	"mem_used": 716029952
},
"system-stats": {
	"cpu": "6",
	"mem": "23",
	"temps": "",
	"uptime": "1350941"
},
"stat": {
	"gw": {
		"site_id": "5c653f1xxxxxxxxxc5772a9c",
		"o": "gw",
		"oid": "XX:XX:XX:XX:XX:XX",
		"gw": "XX:XX:XX:XX:XX:XX",
		"time": 1616608500000,
		"datetime": "2021-03-24T17:55:00Z",
		"duration": 2.8442E9,
		"lan-rx_packets": 2.5665939E8,
		"lan-rx_bytes": 1.89716820138E11,
		"lan-tx_packets": 2.68149976E8,
		"lan-tx_bytes": 2.0295825211E11,
		"wan-rx_packets": 2.86663081E8,
		"wan-rx_bytes": 2.31630196413E11,
		"wan-tx_packets": 2.68936271E8,
		"wan-tx_bytes": 2.13627880406E11,
		"lan-rx_dropped": 3958.0,
		"wan-rx_dropped": 69273.0
	}
},
"tx_bytes": 139274450613,
"rx_bytes": 169398902236,
"bytes": 308673352849,
"num_sta": 16,
"user-num_sta": 16,
"guest-num_sta": 0,
"num_desktop": 0,
"num_mobile": 0,
"num_handheld": 0
}

Would be good to know why the temps are not reported anymore. But in the meantime, is there a way you could handle this failure more gracefully?

2 usw's

unidev.go:155: [ERROR] json.Unmarshal(usw): json: cannot unmarshal number into Go struct field .aggregated_by of type bool

gave me this err

only 1 usw is logged

Update Client Device access (Block and Unblock)

I'm trying to control access to the network leveraging scheduled FW rules. I do this by MAC to IP (static dhcp reservation) and IP to vlan mapping. Then rules for a specific vlan.

One way to bypass rules is to use a "Randomized MAC" (Randomized MACs can be matched by looking at the second digit, if it is [2, 6, A, E] then it is a randomized MAC).

I'd like to block all devices with a random MAC. I can add a hook into the dnsmasq server to execute a script upon a new DHCP client lease ui.com dnsmasq execute script on dhcp lease.

I'll use that to execute a command (with the MAC address) to a golang server that can then call the Block and/ or Unblock update methds.

Thank you for considering these "update" updates to the go-unifi library.
Screenshot 2023-08-06 171018

rx_bytes-r vs rx_bytes

I'm trying to create a way to get notified when I'm nearing my ISP's monthly caps, so I'm digging around unifi-poller, trying to determine what the difference between rx_bytes-r and rx_bytes is.

By plugging the two fields into Grafana, I can see that on my setup the rx_bytes value is way higher than the rx_bytes-r (with the -r) value. Same thing for tx_bytes. Does -r denote "realtime" whereas the non-dash-rs are UniFi's value for data-since-last-couter-reset?

client.ApName output nothing

log.Println(len(clients), "Clients connected:")
for i, client := range clients {
log.Println(i+1, client.ID, client.Hostname, client.IP, client.Name, ### client.ApName)
}

client.ApName output nothing. Please, look at the screenshot:
image

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.