Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow filtering silences by createdBy author #2718

Merged
merged 1 commit into from
Nov 9, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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", "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))
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