Skip to content

Commit

Permalink
Allow filtering silences by createdBy author
Browse files Browse the repository at this point in the history
This commit adds a `--created-by` argument to the `amtool silence
query` command so that silences can be filtered by the author they
were created with in `amtool silence add --author=<name>`.

Signed-off-by: nre <nre@ableton.com>
  • Loading branch information
nre-ableton committed Sep 24, 2021
1 parent e35efbd commit 878084f
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions cli/silence_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,11 @@ import (
)

type silenceQueryCmd struct {
expired bool
quiet bool
matchers []string
within time.Duration
expired bool
quiet bool
createdBy string
matchers []string
within time.Duration
}

const querySilenceHelp = `Query Alertmanager silences.
Expand Down Expand Up @@ -84,6 +85,7 @@ func configureSilenceQueryCmd(cc *kingpin.CmdClause) {

queryCmd.Flag("expired", "Show expired silences instead of active").BoolVar(&c.expired)
queryCmd.Flag("quiet", "Only show silence ids").Short('q').BoolVar(&c.quiet)
queryCmd.Flag("created-by", "Only show silences created by this author").StringVar(&c.createdBy)
queryCmd.Arg("matcher-groups", "Query filter").StringsVar(&c.matchers)
queryCmd.Flag("within", "Show silences that will expire or have expired within a duration").DurationVar(&c.within)
queryCmd.Action(execWithTimeout(c.query))
Expand Down Expand Up @@ -127,6 +129,10 @@ func (c *silenceQueryCmd) query(ctx context.Context, _ *kingpin.ParseContext) er
if c.expired && int64(c.within) > 0 && time.Time(*silence.EndsAt).Before(time.Now().UTC().Add(-c.within)) {
continue
}
// skip silences if the author doesn't match
if c.createdBy != "" && *silence.CreatedBy != c.createdBy {
continue
}

displaySilences = append(displaySilences, *silence)
}
Expand Down

0 comments on commit 878084f

Please sign in to comment.