diff --git a/internal/alertmanager/models.go b/internal/alertmanager/models.go index 7f3582cf..5cec9914 100644 --- a/internal/alertmanager/models.go +++ b/internal/alertmanager/models.go @@ -115,6 +115,11 @@ func (am *Alertmanager) pullSilences(version string) error { log.Errorf("[%s] Failed to generate silences endpoint URL: %s", am.Name, err) return err } + // append query args if mapper needs those + queryArgs := mapper.QueryArgs() + if queryArgs != "" { + url = fmt.Sprintf("%s?%s", url, queryArgs) + } start := time.Now() // read raw body from the source @@ -175,6 +180,12 @@ func (am *Alertmanager) pullAlerts(version string) error { return err } + // append query args if mapper needs those + queryArgs := mapper.QueryArgs() + if queryArgs != "" { + url = fmt.Sprintf("%s?%s", url, queryArgs) + } + start := time.Now() // read raw body from the source source, err := am.reader.Read(url) diff --git a/internal/mapper/mapper.go b/internal/mapper/mapper.go index 8315e97d..09d4a587 100644 --- a/internal/mapper/mapper.go +++ b/internal/mapper/mapper.go @@ -16,6 +16,7 @@ var ( type Mapper interface { IsSupported(version string) bool AbsoluteURL(baseURI string) (string, error) + QueryArgs() string } // AlertMapper handles mapping of Alertmanager alert information to unsee AlertGroup models diff --git a/internal/mapper/v04/alerts.go b/internal/mapper/v04/alerts.go index efb09d62..5e8658da 100644 --- a/internal/mapper/v04/alerts.go +++ b/internal/mapper/v04/alerts.go @@ -59,6 +59,11 @@ func (m AlertMapper) AbsoluteURL(baseURI string) (string, error) { return uri.JoinURL(baseURI, "api/v1/alerts/groups") } +// QueryArgs for HTTP requests send to the Alertmanager API endpoint +func (m AlertMapper) QueryArgs() string { + return "" +} + // IsSupported returns true if given version string is supported func (m AlertMapper) IsSupported(version string) bool { versionRange := semver.MustParseRange(">=0.4.0 <0.5.0") diff --git a/internal/mapper/v04/silences.go b/internal/mapper/v04/silences.go index 1f8489e7..5ca14a1b 100644 --- a/internal/mapper/v04/silences.go +++ b/internal/mapper/v04/silences.go @@ -7,7 +7,9 @@ package v04 import ( "encoding/json" "errors" + "fmt" "io" + "math" "strconv" "time" @@ -52,6 +54,13 @@ func (m SilenceMapper) AbsoluteURL(baseURI string) (string, error) { return uri.JoinURL(baseURI, "api/v1/silences") } +// QueryArgs for HTTP requests send to the Alertmanager API endpoint +func (m SilenceMapper) QueryArgs() string { + // Alertmanager 0.4 uses pagination for silences, pass a huge value so that + // we get all possible silences + return fmt.Sprintf("api/v1/silences?limit=%d", math.MaxInt32) +} + // IsSupported returns true if given version string is supported func (m SilenceMapper) IsSupported(version string) bool { versionRange := semver.MustParseRange(">=0.4.0 <0.5.0") diff --git a/internal/mapper/v05/alerts.go b/internal/mapper/v05/alerts.go index 20283cff..8c0f3bad 100644 --- a/internal/mapper/v05/alerts.go +++ b/internal/mapper/v05/alerts.go @@ -58,6 +58,11 @@ func (m AlertMapper) AbsoluteURL(baseURI string) (string, error) { return uri.JoinURL(baseURI, "api/v1/alerts/groups") } +// QueryArgs for HTTP requests send to the Alertmanager API endpoint +func (m AlertMapper) QueryArgs() string { + return "" +} + // IsSupported returns true if given version string is supported func (m AlertMapper) IsSupported(version string) bool { versionRange := semver.MustParseRange(">=0.5.0 <=0.6.0") diff --git a/internal/mapper/v05/silences.go b/internal/mapper/v05/silences.go index 0740df41..6ba80543 100644 --- a/internal/mapper/v05/silences.go +++ b/internal/mapper/v05/silences.go @@ -46,6 +46,11 @@ func (m SilenceMapper) AbsoluteURL(baseURI string) (string, error) { return uri.JoinURL(baseURI, "api/v1/silences") } +// QueryArgs for HTTP requests send to the Alertmanager API endpoint +func (m SilenceMapper) QueryArgs() string { + return "" +} + // IsSupported returns true if given version string is supported func (m SilenceMapper) IsSupported(version string) bool { versionRange := semver.MustParseRange(">=0.5.0") diff --git a/internal/mapper/v061/alerts.go b/internal/mapper/v061/alerts.go index c2ff0fa1..0cdcb3b0 100644 --- a/internal/mapper/v061/alerts.go +++ b/internal/mapper/v061/alerts.go @@ -60,6 +60,11 @@ func (m AlertMapper) AbsoluteURL(baseURI string) (string, error) { return uri.JoinURL(baseURI, "api/v1/alerts/groups") } +// QueryArgs for HTTP requests send to the Alertmanager API endpoint +func (m AlertMapper) QueryArgs() string { + return "" +} + // IsSupported returns true if given version string is supported func (m AlertMapper) IsSupported(version string) bool { versionRange := semver.MustParseRange("=0.6.1") diff --git a/internal/mapper/v062/alerts.go b/internal/mapper/v062/alerts.go index b72f2f5a..61528be6 100644 --- a/internal/mapper/v062/alerts.go +++ b/internal/mapper/v062/alerts.go @@ -64,6 +64,11 @@ func (m AlertMapper) AbsoluteURL(baseURI string) (string, error) { return uri.JoinURL(baseURI, "api/v1/alerts/groups") } +// QueryArgs for HTTP requests send to the Alertmanager API endpoint +func (m AlertMapper) QueryArgs() string { + return "" +} + // IsSupported returns true if given version string is supported func (m AlertMapper) IsSupported(version string) bool { versionRange := semver.MustParseRange(">=0.6.2")