Fix issue with status not returning controller version on 6.0.43

This commit is contained in:
Paul Tyng
2021-03-07 11:00:18 -05:00
parent 23f4659d36
commit 3eb04af6a7
2 changed files with 103 additions and 2 deletions

85
unifi/sysinfo.go Normal file
View File

@@ -0,0 +1,85 @@
package unifi
import (
"context"
"fmt"
)
type sysInfo struct {
Timezone string `json:"timezone"`
Version string `json:"version"`
PreviousVersion string `json:"previous_version"`
UBNTDeviceType string `json:"ubnt_device_type"`
UDMVersion string `json:"udm_version"`
/*
{
"meta": {
"rc": "ok"
},
"data": [
{
"timezone": "America/New_York",
"autobackup": false,
"build": "atag_6.0.43_14348",
"version": "6.0.43",
"previous_version": "5.12.60",
"debug_mgmt": "warn",
"debug_system": "warn",
"debug_device": "warn",
"debug_sdn": "warn",
"data_retention_days": 90,
"data_retention_time_in_hours_for_5minutes_scale": 24,
"data_retention_time_in_hours_for_hourly_scale": 720,
"data_retention_time_in_hours_for_daily_scale": 2160,
"data_retention_time_in_hours_for_monthly_scale": 8760,
"data_retention_time_in_hours_for_others": 2160,
"update_available": false,
"update_downloaded": false,
"live_chat": "super-only",
"store_enabled": "super-only",
"hostname": "example-domain.ui.com",
"name": "Dream Machine",
"ip_addrs": [
"1.2.3.4"
],
"inform_port": 8080,
"https_port": 8443,
"override_inform_host": false,
"image_maps_use_google_engine": false,
"radius_disconnect_running": false,
"facebook_wifi_registered": false,
"sso_app_id": "",
"sso_app_sec": "",
"uptime": 2541796,
"anonymous_controller_id": "",
"ubnt_device_type": "UDMB",
"udm_version": "1.8.6.2969",
"unsupported_device_count": 0,
"unsupported_device_list": [],
"unifi_go_enabled": false
}
]
}
*/
}
func (c *Client) sysinfo(ctx context.Context, id string) (*sysInfo, error) {
var respBody struct {
Meta meta `json:"meta"`
Data []sysInfo `json:"data"`
}
err := c.do(ctx, "GET", fmt.Sprintf("s/%s/stat/sysinfo", id), nil, &respBody)
if err != nil {
return nil, err
}
if len(respBody.Data) != 1 {
return nil, &NotFoundError{}
}
return &respBody.Data[0], nil
}

View File

@@ -168,7 +168,24 @@ func (c *Client) Login(ctx context.Context, user, pass string) error {
if err != nil {
return err
}
c.version = status.Meta.ServerVersion
if version := status.Meta.ServerVersion; version != "" {
c.version = status.Meta.ServerVersion
return nil
}
// newer version of 6.0 controller, use sysinfo to determine version
// using default site since it must exist
si, err := c.sysinfo(ctx, "default")
if err != nil {
return err
}
c.version = si.Version
if c.version == "" {
return fmt.Errorf("unable to determine controller version")
}
return nil
}
@@ -227,7 +244,6 @@ func (c *Client) do(ctx context.Context, method, relativeURL string, reqBody int
}
if resp.StatusCode != 200 {
fmt.Printf("Request Body:\n%s\n", string(reqBytes))
errBody := struct {
Meta meta `json:"meta"`
}{}