unpoller / unifi

Go Library (w/ structures) to grab data from a Ubitquiti UniFi Controller
https://golift.io/discord
MIT License
114 stars 22 forks source link

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

Closed adampetrovic closed 5 years ago

adampetrovic commented 5 years ago

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
    }
  ],
adampetrovic commented 5 years ago

Just confirmed switching from string to int fixes the issue. Is this perhaps something that changed as part of a firmware upgrade?

adampetrovic commented 5 years ago

FWIW I have a Unifi Gateway Pro 4 Port (the rack mount kind)

davidnewhall commented 5 years ago

What controller version are you running? 5.10.x?

adampetrovic commented 5 years ago

5.10.25-11682-1

davidnewhall commented 5 years ago

kk thanks! The fix will be out in the next release! Thank you very much for the report!