From 5b825e22a4645840f7074a8f97e9ff809ea1f076 Mon Sep 17 00:00:00 2001 From: Nik Reiman Date: Tue, 9 Nov 2021 13:10:19 +0100 Subject: [PATCH] Allow filtering silences by createdBy author (#2718) 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=`. Signed-off-by: nre --- cli/silence_query.go | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/cli/silence_query.go b/cli/silence_query.go index 3c7daabf..c1e20be8 100644 --- a/cli/silence_query.go +++ b/cli/silence_query.go @@ -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. @@ -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", "Show silences that belong to this creator").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)) @@ -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) }