mirror of
https://github.com/unpoller/unpoller.git
synced 2026-10-10 00:05:44 +02:00
inputunifi: skip alarms endpoint on 400 api.err.InvalidObject
Some Network 10.x+ controllers (UniFi OS, Network 10.5.67 confirmed) return HTTP 400 api.err.InvalidObject from list/alarm instead of a 404 when the endpoint is gone, so collectAlarms fell through the existing ErrEndpointNotFound skip and logged a real ERROR on every poll. Fixes #1050
This commit is contained in:
@@ -135,6 +135,16 @@ func (u *InputUnifi) collectAlarms(logs []any, sites []*unifi.Site, c *Controlle
|
||||
return logs, nil
|
||||
}
|
||||
|
||||
if isAlarmsInvalidObject(err) {
|
||||
// Some Network 10.x+ controllers (see unpoller/unpoller#1050) return
|
||||
// HTTP 400 api.err.InvalidObject for list/alarm instead of a 404 when
|
||||
// the endpoint is gone. unifi.ErrInvalidStatusCode doesn't carry a
|
||||
// parsed status code, so we match on the formatted resp.Status text.
|
||||
u.Logf("[%s] Alarms endpoint returned 400 (likely removed on this controller version): %v", c.URL, err)
|
||||
|
||||
return logs, nil
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return logs, fmt.Errorf("unifi.GetAlarms(): %w", err)
|
||||
}
|
||||
@@ -158,6 +168,12 @@ func (u *InputUnifi) collectAlarms(logs []any, sites []*unifi.Site, c *Controlle
|
||||
return logs, nil
|
||||
}
|
||||
|
||||
// isAlarmsInvalidObject reports whether err is a 400 api.err.InvalidObject response,
|
||||
// which some Network 10.x+ controllers return from list/alarm in place of a 404.
|
||||
func isAlarmsInvalidObject(err error) bool {
|
||||
return errors.Is(err, unifi.ErrInvalidStatusCode) && strings.Contains(err.Error(), ": 400 ")
|
||||
}
|
||||
|
||||
func (u *InputUnifi) collectAnomalies(logs []any, sites []*unifi.Site, c *Controller) ([]any, error) {
|
||||
if *c.SaveAnomal {
|
||||
u.LogDebugf("Collecting controller anomalies: %s (%s)", c.URL, c.ID)
|
||||
|
||||
Reference in New Issue
Block a user