support for assuming first label is alertname in silence add and query (#1693)
* simplified setting first assumed alertname in cli/silence_query.go * added assumed first label to alertname when adding silences Signed-off-by: Hrishikesh Barman <hrishikeshbman@gmail.com>
This commit is contained in:
parent
6787dd1bde
commit
1f66a7e18e
|
@ -89,6 +89,16 @@ func configureSilenceAddCmd(cc *kingpin.CmdClause) {
|
|||
func (c *silenceAddCmd) add(ctx context.Context, _ *kingpin.ParseContext) error {
|
||||
var err error
|
||||
|
||||
if len(c.matchers) > 0 {
|
||||
// If the parser fails then we likely don't have a (=|=~|!=|!~) so lets
|
||||
// assume that the user wants alertname=<arg> and prepend `alertname=`
|
||||
// to the front.
|
||||
_, err := parseMatchers([]string{c.matchers[0]})
|
||||
if err != nil {
|
||||
c.matchers[0] = fmt.Sprintf("alertname=%s", c.matchers[0])
|
||||
}
|
||||
}
|
||||
|
||||
matchers, err := parseMatchers(c.matchers)
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
|
@ -93,17 +93,14 @@ func configureSilenceQueryCmd(cc *kingpin.CmdClause) {
|
|||
|
||||
func (c *silenceQueryCmd) query(ctx context.Context, _ *kingpin.ParseContext) error {
|
||||
var filterString = ""
|
||||
if len(c.matchers) == 1 {
|
||||
if len(c.matchers) > 0 {
|
||||
// If the parser fails then we likely don't have a (=|=~|!=|!~) so lets
|
||||
// assume that the user wants alertname=<arg> and prepend `alertname=`
|
||||
// to the front.
|
||||
_, err := parse.Matcher(c.matchers[0])
|
||||
if err != nil {
|
||||
filterString = fmt.Sprintf("{alertname=%s}", c.matchers[0])
|
||||
} else {
|
||||
filterString = fmt.Sprintf("{%s}", strings.Join(c.matchers, ","))
|
||||
c.matchers[0] = fmt.Sprintf("alertname=%s", c.matchers[0])
|
||||
}
|
||||
} else if len(c.matchers) > 1 {
|
||||
filterString = fmt.Sprintf("{%s}", strings.Join(c.matchers, ","))
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue