mirror of
https://github.com/prometheus/alertmanager
synced 2025-02-02 11:42:09 +00:00
cli: Unify matcher formatting
Signed-off-by: Kiril Vladimirov <kiril@vladimiroff.org>
This commit is contained in:
parent
2b6315f399
commit
133b5bab42
@ -132,14 +132,7 @@ func extendedFormatAnnotations(labels models.LabelSet) string {
|
||||
func extendedFormatMatchers(matchers models.Matchers) string {
|
||||
output := []string{}
|
||||
for _, matcher := range matchers {
|
||||
output = append(output, extendedFormatMatcher(*matcher))
|
||||
output = append(output, simpleFormatMatcher(*matcher))
|
||||
}
|
||||
return strings.Join(output, " ")
|
||||
}
|
||||
|
||||
func extendedFormatMatcher(matcher models.Matcher) string {
|
||||
if *matcher.IsRegex {
|
||||
return fmt.Sprintf("%s=~%s", *matcher.Name, *matcher.Value)
|
||||
}
|
||||
return fmt.Sprintf("%s=%s", *matcher.Name, *matcher.Value)
|
||||
}
|
||||
|
@ -94,9 +94,17 @@ func simpleFormatMatchers(matchers models.Matchers) string {
|
||||
return strings.Join(output, " ")
|
||||
}
|
||||
|
||||
func simpleFormatMatcher(matcher models.Matcher) string {
|
||||
if *matcher.IsRegex {
|
||||
return fmt.Sprintf("%s=~%s", *matcher.Name, *matcher.Value)
|
||||
func simpleFormatMatcher(m models.Matcher) string {
|
||||
var op string
|
||||
switch {
|
||||
case !*m.IsRegex && *m.IsEqual:
|
||||
op = "="
|
||||
case !*m.IsRegex && !*m.IsEqual:
|
||||
op = "!="
|
||||
case *m.IsRegex && *m.IsEqual:
|
||||
op = "=~"
|
||||
case *m.IsRegex && !*m.IsEqual:
|
||||
op = "!~"
|
||||
}
|
||||
return fmt.Sprintf("%s=%s", *matcher.Name, *matcher.Value)
|
||||
return fmt.Sprintf("%s%s%q", *m.Name, op, *m.Value)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user