Add `--id` flag to `amtool silence query` (#3241)
In the Web UI, we have a UI to get information on a given silence through its ID. This functionality is missing from amtool however, leading to the necessity to pull _all_ the silenced, and filter with `grep` or similar. This commit adds in a `--id` flag to the `silence query` command, which allows specifying an ID to match on, matching the functionality of the Web UI. Signed-off-by: sinkingpoint <colin@quirl.co.nz>
This commit is contained in:
parent
11d0b57c97
commit
a66692fa56
|
@ -31,6 +31,7 @@ type silenceQueryCmd struct {
|
||||||
expired bool
|
expired bool
|
||||||
quiet bool
|
quiet bool
|
||||||
createdBy string
|
createdBy string
|
||||||
|
ID string
|
||||||
matchers []string
|
matchers []string
|
||||||
within time.Duration
|
within time.Duration
|
||||||
}
|
}
|
||||||
|
@ -86,6 +87,7 @@ func configureSilenceQueryCmd(cc *kingpin.CmdClause) {
|
||||||
queryCmd.Flag("expired", "Show expired silences instead of active").BoolVar(&c.expired)
|
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("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.Flag("created-by", "Show silences that belong to this creator").StringVar(&c.createdBy)
|
||||||
|
queryCmd.Flag("id", "Get a single silence by its ID").StringVar(&c.ID)
|
||||||
queryCmd.Arg("matcher-groups", "Query filter").StringsVar(&c.matchers)
|
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.Flag("within", "Show silences that will expire or have expired within a duration").DurationVar(&c.within)
|
||||||
queryCmd.Action(execWithTimeout(c.query))
|
queryCmd.Action(execWithTimeout(c.query))
|
||||||
|
@ -133,6 +135,10 @@ func (c *silenceQueryCmd) query(ctx context.Context, _ *kingpin.ParseContext) er
|
||||||
if c.createdBy != "" && *silence.CreatedBy != c.createdBy {
|
if c.createdBy != "" && *silence.CreatedBy != c.createdBy {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
// Skip silences if the ID doesn't match.
|
||||||
|
if c.ID != "" && c.ID != *silence.ID {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
displaySilences = append(displaySilences, *silence)
|
displaySilences = append(displaySilences, *silence)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue