Skip to content
This repository has been archived by the owner on Jul 22, 2020. It is now read-only.

Allow passing query args to HTTP requests send to the Alertmanager API #222

Merged
merged 1 commit into from
Jan 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 11 additions & 0 deletions internal/alertmanager/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions internal/mapper/mapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions internal/mapper/v04/alerts.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
9 changes: 9 additions & 0 deletions internal/mapper/v04/silences.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ package v04
import (
"encoding/json"
"errors"
"fmt"
"io"
"math"
"strconv"
"time"

Expand Down Expand Up @@ -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")
Expand Down
5 changes: 5 additions & 0 deletions internal/mapper/v05/alerts.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
5 changes: 5 additions & 0 deletions internal/mapper/v05/silences.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
5 changes: 5 additions & 0 deletions internal/mapper/v061/alerts.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
5 changes: 5 additions & 0 deletions internal/mapper/v062/alerts.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down