Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update alert_suppression in rule schema #3207

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion detection_rules/rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,8 @@ class AlertSuppressionDuration:

group_by: List[definitions.NonEmptyStr]
duration: Optional[AlertSuppressionDuration] = field(metadata=dict(metadata=dict(min_compat="8.7")))
missing_fields_strategy: Optional[definitions.AlertSuppressionMissing] = field(
metadata=dict(metadata=dict(min_compat="8.8")))


@dataclass(frozen=True)
Expand All @@ -247,7 +249,6 @@ class RelatedIntegrations:
integration: Optional[definitions.NonEmptyStr]

actions: Optional[list]
alert_suppression: Optional[AlertSuppressionMapping] = field(metadata=dict(metadata=dict(min_compat="8.6")))
author: List[str]
building_block_type: Optional[definitions.BuildingBlockType]
description: str
Expand Down Expand Up @@ -561,6 +562,14 @@ class QueryRuleData(BaseRuleData):
index: Optional[List[str]]
query: str
language: definitions.FilterLanguages
alert_suppression: Optional[AlertSuppressionMapping] = field(metadata=dict(metadata=dict(min_compat="8.6")))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we leaving min_compat=8.6 or bumping to 8.7?


@validates_schema
def validates(self, data, **kwargs):
"""Custom validation for query rule type and subclasses."""
# alert suppression is only valid for query rule type and not any of its subclasses
if data.get('alert_suppression') is not None and data['type'] != 'query':
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if data.get('alert_suppression') is not None and data['type'] != 'query':
if data.get('alert_suppression') and data['type'] != 'query':

raise ValidationError("Alert suppression is only valid for query rule type.")

@cached_property
def validator(self) -> Optional[QueryValidator]:
Expand Down
3 changes: 2 additions & 1 deletion detection_rules/schemas/definitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,8 @@
]

MACHINE_LEARNING_PACKAGES = ['LMD', 'DGA', 'DED', 'ProblemChild', 'Beaconing']

AlertSuppressionMissing = NewType('AlertSuppressionMissing', str,
validate=validate.OneOf(['suppress', 'doNotSuppress']))
NonEmptyStr = NewType('NonEmptyStr', str, validate=validate.Length(min=1))
TimeUnits = Literal['s', 'm', 'h']
BranchVer = NewType('BranchVer', str, validate=validate.Regexp(BRANCH_PATTERN))
Expand Down
Loading