Add default_site_name_override to support customizable default site names
This commit is contained in:
parent
08e3668ba3
commit
5a89a4634a
|
|
@ -152,6 +152,9 @@
|
||||||
# A setting of ["all"] will poll all sites; this works if you only have 1 site too.
|
# A setting of ["all"] will poll all sites; this works if you only have 1 site too.
|
||||||
sites = ["all"]
|
sites = ["all"]
|
||||||
|
|
||||||
|
# Added an example for overriding the default site name.
|
||||||
|
# default_site_name_override = "My Custom Default Site"
|
||||||
|
|
||||||
# Specify a timeout, leave missing to declare infinite wait. This determines the maximum
|
# Specify a timeout, leave missing to declare infinite wait. This determines the maximum
|
||||||
# time to wait for a response from the unifi controller on any API request.
|
# time to wait for a response from the unifi controller on any API request.
|
||||||
# timeout = 60s
|
# timeout = 60s
|
||||||
|
|
|
||||||
|
|
@ -42,7 +42,7 @@
|
||||||
"tags": [
|
"tags": [
|
||||||
"customer:abcde"
|
"customer:abcde"
|
||||||
]
|
]
|
||||||
}
|
},
|
||||||
|
|
||||||
"unifi": {
|
"unifi": {
|
||||||
"dynamic": false,
|
"dynamic": false,
|
||||||
|
|
@ -59,7 +59,8 @@
|
||||||
"save_dpi": false,
|
"save_dpi": false,
|
||||||
"save_sites": true,
|
"save_sites": true,
|
||||||
"hash_pii": false,
|
"hash_pii": false,
|
||||||
"verify_ssl": false
|
"verify_ssl": false,
|
||||||
|
"default_site_name_override": "My Custom Default Site"
|
||||||
},
|
},
|
||||||
"controllers": [
|
"controllers": [
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -60,7 +60,8 @@ unifi:
|
||||||
save_sites: true
|
save_sites: true
|
||||||
hash_pii: false
|
hash_pii: false
|
||||||
verify_ssl: false
|
verify_ssl: false
|
||||||
|
# Added an example for overriding the default site name.
|
||||||
|
# default_site_name_override: "My Custom Default Site"
|
||||||
|
|
||||||
controllers:
|
controllers:
|
||||||
# Repeat the following stanza to poll multiple controllers.
|
# Repeat the following stanza to poll multiple controllers.
|
||||||
|
|
|
||||||
|
|
@ -278,7 +278,16 @@ func (u *InputUnifi) getFilteredSites(c *Controller) ([]*unifi.Site, error) {
|
||||||
sites, err := c.Unifi.GetSites()
|
sites, err := c.Unifi.GetSites()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("controller: %w", err)
|
return nil, fmt.Errorf("controller: %w", err)
|
||||||
} else if len(c.Sites) == 0 || StringInSlice("all", c.Sites) {
|
}
|
||||||
|
|
||||||
|
// Apply the default_site_name_override if the site is marked as default.
|
||||||
|
for _, site := range sites {
|
||||||
|
if site.IsDefaultSite && c.DefaultSiteNameOverride != "" {
|
||||||
|
site.Name = c.DefaultSiteNameOverride
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(c.Sites) == 0 || StringInSlice("all", c.Sites) {
|
||||||
return sites, nil
|
return sites, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -50,6 +50,7 @@ type Controller struct {
|
||||||
APIKey string `json:"api_key" toml:"api_key" xml:"api_key" yaml:"api_key"`
|
APIKey string `json:"api_key" toml:"api_key" xml:"api_key" yaml:"api_key"`
|
||||||
URL string `json:"url" toml:"url" xml:"url" yaml:"url"`
|
URL string `json:"url" toml:"url" xml:"url" yaml:"url"`
|
||||||
Sites []string `json:"sites" toml:"sites" xml:"site" yaml:"sites"`
|
Sites []string `json:"sites" toml:"sites" xml:"site" yaml:"sites"`
|
||||||
|
DefaultSiteNameOverride string `json:"default_site_name_override" toml:"default_site_name_override" xml:"default_site_name_override" yaml:"default_site_name_override"`
|
||||||
Unifi *unifi.Unifi `json:"-" toml:"-" xml:"-" yaml:"-"`
|
Unifi *unifi.Unifi `json:"-" toml:"-" xml:"-" yaml:"-"`
|
||||||
ID string `json:"id,omitempty"` // this is an output, not an input.
|
ID string `json:"id,omitempty"` // this is an output, not an input.
|
||||||
}
|
}
|
||||||
|
|
@ -358,6 +359,11 @@ func (u *InputUnifi) setControllerDefaults(c *Controller) *Controller { //nolint
|
||||||
c.Sites = u.Default.Sites
|
c.Sites = u.Default.Sites
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Added handling for the new default_site_name_override parameter.
|
||||||
|
if c.DefaultSiteNameOverride == "" {
|
||||||
|
c.DefaultSiteNameOverride = u.Default.DefaultSiteNameOverride
|
||||||
|
}
|
||||||
|
|
||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue