mirror of
https://github.com/unpoller/unpoller.git
synced 2026-03-31 06:24:21 -04:00
fix: add HTTP timeout configuration to prevent indefinite hangs
The UniFi controller HTTP client was created without a timeout, causing unpoller to hang indefinitely when the controller becomes unresponsive. This resulted in random stops where polling would cease until the container was restarted. Changes: - Add Timeout field to Controller struct (cnfg.Duration) - Set default timeout of 60 seconds - Pass timeout to unifi.Config when creating the client - Log timeout value on startup for visibility The timeout can be configured via: - Config file: timeout = "60s" - Environment: UP_UNIFI_DEFAULT_TIMEOUT=60s Fixes issue where container would hang overnight: 2025/12/22 22:29:27 - Requesting https://unifi/.../stat/sta [~2 hour gap - request hung indefinitely] 2025/12/23 00:17:57 - Unmarshalling Device Type: udm...
This commit is contained in:
@@ -11,6 +11,7 @@ import (
|
||||
|
||||
"github.com/unpoller/unifi/v5"
|
||||
"github.com/unpoller/unpoller/pkg/poller"
|
||||
"golift.io/cnfg"
|
||||
)
|
||||
|
||||
// PluginName is the name of this input plugin.
|
||||
@@ -21,6 +22,7 @@ const (
|
||||
defaultUser = "unifipoller"
|
||||
defaultPass = "unifipoller"
|
||||
defaultSite = "all"
|
||||
defaultTimeout = 60 * time.Second
|
||||
)
|
||||
|
||||
// InputUnifi contains the running data.
|
||||
@@ -47,6 +49,7 @@ type Controller struct {
|
||||
HashPII *bool `json:"hash_pii" toml:"hash_pii" xml:"hash_pii" yaml:"hash_pii"`
|
||||
DropPII *bool `json:"drop_pii" toml:"drop_pii" xml:"drop_pii" yaml:"drop_pii"`
|
||||
SaveSites *bool `json:"save_sites" toml:"save_sites" xml:"save_sites" yaml:"save_sites"`
|
||||
Timeout cnfg.Duration `json:"timeout" toml:"timeout" xml:"timeout" yaml:"timeout"`
|
||||
CertPaths []string `json:"ssl_cert_paths" toml:"ssl_cert_paths" xml:"ssl_cert_path" yaml:"ssl_cert_paths"`
|
||||
User string `json:"user" toml:"user" xml:"user" yaml:"user"`
|
||||
Pass string `json:"pass" toml:"pass" xml:"pass" yaml:"pass"`
|
||||
@@ -134,6 +137,7 @@ func (u *InputUnifi) getUnifi(c *Controller) error {
|
||||
URL: c.URL,
|
||||
SSLCert: certs,
|
||||
VerifySSL: *c.VerifySSL,
|
||||
Timeout: c.Timeout.Duration,
|
||||
ErrorLog: u.LogErrorf, // Log all errors.
|
||||
DebugLog: u.LogDebugf, // Log debug messages.
|
||||
})
|
||||
@@ -296,6 +300,10 @@ func (u *InputUnifi) setDefaults(c *Controller) { //nolint:cyclop
|
||||
if len(c.Sites) == 0 {
|
||||
c.Sites = []string{defaultSite}
|
||||
}
|
||||
|
||||
if c.Timeout.Duration == 0 {
|
||||
c.Timeout.Duration = defaultTimeout
|
||||
}
|
||||
}
|
||||
|
||||
// setControllerDefaults sets defaults for the for controllers.
|
||||
@@ -393,6 +401,10 @@ func (u *InputUnifi) setControllerDefaults(c *Controller) *Controller { //nolint
|
||||
c.DefaultSiteNameOverride = u.Default.DefaultSiteNameOverride
|
||||
}
|
||||
|
||||
if c.Timeout.Duration == 0 {
|
||||
c.Timeout = u.Default.Timeout
|
||||
}
|
||||
|
||||
return c
|
||||
}
|
||||
|
||||
|
||||
@@ -114,7 +114,7 @@ func (u *InputUnifi) DebugInput() (bool, error) {
|
||||
}
|
||||
|
||||
func (u *InputUnifi) logController(c *Controller) {
|
||||
u.Logf(" => URL: %s (verify SSL: %v)", c.URL, *c.VerifySSL)
|
||||
u.Logf(" => URL: %s (verify SSL: %v, timeout: %v)", c.URL, *c.VerifySSL, c.Timeout.Duration)
|
||||
|
||||
if len(c.CertPaths) > 0 {
|
||||
u.Logf(" => Cert Files: %s", strings.Join(c.CertPaths, ", "))
|
||||
|
||||
Reference in New Issue
Block a user