Skip to content

Commit 028ba6b

Browse files
authored
Merge pull request #1876 from elementary-data/ele-4239-not-contains-filter-in-alert-routing-rules
Add NOT_CONTAINS filter type and update apply_filter function
2 parents b5cd157 + 716bf14 commit 028ba6b

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

elementary/monitor/data_monitoring/schema.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ class FilterType(str, Enum):
3232
IS = "is"
3333
IS_NOT = "is_not"
3434
CONTAINS = "contains"
35+
NOT_CONTAINS = "not_contains"
3536

3637

3738
class FilterFields(BaseModel):
@@ -55,14 +56,16 @@ def apply_filter(filter_type: FilterType, value: Any, filter_value: Any) -> bool
5556
return value != filter_value
5657
elif filter_type == FilterType.CONTAINS:
5758
return str(filter_value).lower() in str(value).lower()
59+
elif filter_type == FilterType.NOT_CONTAINS:
60+
return str(filter_value).lower() not in str(value).lower()
5861
raise ValueError(f"Unsupported filter type: {filter_type}")
5962

6063

6164
ValueT = TypeVar("ValueT")
6265

6366

6467
ANY_OPERATORS = [FilterType.IS, FilterType.CONTAINS]
65-
ALL_OPERATORS = [FilterType.IS_NOT]
68+
ALL_OPERATORS = [FilterType.IS_NOT, FilterType.NOT_CONTAINS]
6669

6770

6871
class FilterSchema(BaseModel, Generic[ValueT]):

0 commit comments

Comments
 (0)