Amtool: Implement filter by receiver fixes:#937 (#1402)
* Amtool: Implement filter by receiver * Adds receiver flag to amtool alert query * Adds receiver argument to alert http client * Updates http client tests for added argument Also works: scpecifying `receiver: "receiver-123"` in config file automaticly filters all alerts shown * Include receiver in amtool config docs Now that I've implemented the receiver in amtool I should add the new feature to the documentation. * #937 Add mention of supporting regex syntax to receiver flag
This commit is contained in:
parent
db4af95ea0
commit
b949f0dc19
|
@ -281,6 +281,9 @@ comment_required: true
|
|||
|
||||
# Set a default output format. (unset defaults to simple)
|
||||
output: extended
|
||||
|
||||
# Set a default receiver
|
||||
receiver: team-X-pager
|
||||
```
|
||||
|
||||
## High Availability
|
||||
|
|
|
@ -29,8 +29,8 @@ import (
|
|||
|
||||
type alertQueryCmd struct {
|
||||
inhibited, silenced, active, unprocessed bool
|
||||
|
||||
matcherGroups []string
|
||||
receiver string
|
||||
matcherGroups []string
|
||||
}
|
||||
|
||||
const alertHelp = `View and search through current alerts.
|
||||
|
@ -71,6 +71,7 @@ func configureAlertCmd(app *kingpin.Application) {
|
|||
queryCmd.Flag("silenced", "Show silenced alerts").Short('s').BoolVar(&a.silenced)
|
||||
queryCmd.Flag("active", "Show active alerts").Short('a').BoolVar(&a.active)
|
||||
queryCmd.Flag("unprocessed", "Show unprocessed alerts").Short('u').BoolVar(&a.unprocessed)
|
||||
queryCmd.Flag("receiver", "Show alerts matching receiver (Supports regex syntax)").Short('r').StringVar(&a.receiver)
|
||||
queryCmd.Arg("matcher-groups", "Query filter").StringsVar(&a.matcherGroups)
|
||||
queryCmd.Action(a.queryAlerts)
|
||||
}
|
||||
|
@ -100,7 +101,7 @@ func (a *alertQueryCmd) queryAlerts(ctx *kingpin.ParseContext) error {
|
|||
if !a.silenced && !a.inhibited && !a.active && !a.unprocessed {
|
||||
a.active = true
|
||||
}
|
||||
fetchedAlerts, err := alertAPI.List(context.Background(), filterString, a.silenced, a.inhibited, a.active, a.unprocessed)
|
||||
fetchedAlerts, err := alertAPI.List(context.Background(), filterString, a.receiver, a.silenced, a.inhibited, a.active, a.unprocessed)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -154,7 +154,7 @@ func (h *httpStatusAPI) Get(ctx context.Context) (*ServerStatus, error) {
|
|||
// AlertAPI provides bindings for the Alertmanager's alert API.
|
||||
type AlertAPI interface {
|
||||
// List returns all the active alerts.
|
||||
List(ctx context.Context, filter string, silenced, inhibited, active, unprocessed bool) ([]*ExtendedAlert, error)
|
||||
List(ctx context.Context, filter, receiver string, silenced, inhibited, active, unprocessed bool) ([]*ExtendedAlert, error)
|
||||
// Push sends a list of alerts to the Alertmanager.
|
||||
Push(ctx context.Context, alerts ...Alert) error
|
||||
}
|
||||
|
@ -194,7 +194,7 @@ type httpAlertAPI struct {
|
|||
client api.Client
|
||||
}
|
||||
|
||||
func (h *httpAlertAPI) List(ctx context.Context, filter string, silenced, inhibited, active, unprocessed bool) ([]*ExtendedAlert, error) {
|
||||
func (h *httpAlertAPI) List(ctx context.Context, filter, receiver string, silenced, inhibited, active, unprocessed bool) ([]*ExtendedAlert, error) {
|
||||
u := h.client.URL(epAlerts, nil)
|
||||
params := url.Values{}
|
||||
if filter != "" {
|
||||
|
@ -204,6 +204,7 @@ func (h *httpAlertAPI) List(ctx context.Context, filter string, silenced, inhibi
|
|||
params.Add("inhibited", fmt.Sprintf("%t", inhibited))
|
||||
params.Add("active", fmt.Sprintf("%t", active))
|
||||
params.Add("unprocessed", fmt.Sprintf("%t", unprocessed))
|
||||
params.Add("receiver", receiver)
|
||||
u.RawQuery = params.Encode()
|
||||
|
||||
req, _ := http.NewRequest(http.MethodGet, u.String(), nil)
|
||||
|
|
|
@ -118,7 +118,7 @@ func TestAPI(t *testing.T) {
|
|||
}
|
||||
doAlertList := func() (interface{}, error) {
|
||||
api := httpAlertAPI{client: client}
|
||||
return api.List(context.Background(), "", false, false, false, false)
|
||||
return api.List(context.Background(), "", "", false, false, false, false)
|
||||
}
|
||||
doAlertPush := func() (interface{}, error) {
|
||||
api := httpAlertAPI{client: client}
|
||||
|
|
Loading…
Reference in New Issue