diff --git a/api/v2/api.go b/api/v2/api.go index 3394206e..b8bde463 100644 --- a/api/v2/api.go +++ b/api/v2/api.go @@ -723,12 +723,20 @@ func gettableSilenceFromProto(s *silencepb.Silence) (open_api_models.GettableSil Name: &m.Name, Value: &m.Pattern, } + f := false + t := true switch m.Type { case silencepb.Matcher_EQUAL: - f := false + matcher.IsEqual = &t + matcher.IsRegex = &f + case silencepb.Matcher_NOT_EQUAL: + matcher.IsEqual = &f matcher.IsRegex = &f case silencepb.Matcher_REGEXP: - t := true + matcher.IsEqual = &t + matcher.IsRegex = &t + case silencepb.Matcher_NOT_REGEXP: + matcher.IsEqual = &f matcher.IsRegex = &t default: return sil, fmt.Errorf( @@ -792,10 +800,25 @@ func postableSilenceToProto(s *open_api_models.PostableSilence) (*silencepb.Sile matcher := &silencepb.Matcher{ Name: *m.Name, Pattern: *m.Value, - Type: silencepb.Matcher_EQUAL, } - if *m.IsRegex { + isEqual := true + if m.IsEqual != nil { + isEqual = *m.IsEqual + } + isRegex := false + if m.IsRegex != nil { + isRegex = *m.IsRegex + } + + switch { + case isEqual && !isRegex: + matcher.Type = silencepb.Matcher_EQUAL + case !isEqual && !isRegex: + matcher.Type = silencepb.Matcher_NOT_EQUAL + case isEqual && isRegex: matcher.Type = silencepb.Matcher_REGEXP + case !isEqual && isRegex: + matcher.Type = silencepb.Matcher_NOT_REGEXP } sil.Matchers = append(sil.Matchers, matcher) } diff --git a/api/v2/models/matcher.go b/api/v2/models/matcher.go index eae3605a..5d228bb5 100644 --- a/api/v2/models/matcher.go +++ b/api/v2/models/matcher.go @@ -31,6 +31,9 @@ import ( // swagger:model matcher type Matcher struct { + // is equal + IsEqual *bool `json:"isEqual,omitempty"` + // is regex // Required: true IsRegex *bool `json:"isRegex"` diff --git a/api/v2/openapi.yaml b/api/v2/openapi.yaml index 84e8297a..c5d81d89 100644 --- a/api/v2/openapi.yaml +++ b/api/v2/openapi.yaml @@ -392,6 +392,9 @@ definitions: type: string isRegex: type: boolean + isEqual: + type: boolean + default: true required: - name - value diff --git a/api/v2/restapi/embedded_spec.go b/api/v2/restapi/embedded_spec.go index 77168bf6..cca7e806 100644 --- a/api/v2/restapi/embedded_spec.go +++ b/api/v2/restapi/embedded_spec.go @@ -612,6 +612,10 @@ func init() { "isRegex" ], "properties": { + "isEqual": { + "type": "boolean", + "default": true + }, "isRegex": { "type": "boolean" }, @@ -1421,6 +1425,10 @@ func init() { "isRegex" ], "properties": { + "isEqual": { + "type": "boolean", + "default": true + }, "isRegex": { "type": "boolean" },