Skip to content

Commit

Permalink
fix matching multiline regex in s3 handler
Browse files Browse the repository at this point in the history
  • Loading branch information
ge0Aja committed Sep 17, 2024
1 parent 549f749 commit 97e1162
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions aws/logs_monitoring/steps/handlers/s3_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ def __init__(self, context, metadata, cache_layer):
if DD_MULTILINE_LOG_REGEX_PATTERN
else None
)
self.multiline_regex_pattern = (
re.compile("[\n\r\f]+(?={})".format(DD_MULTILINE_LOG_REGEX_PATTERN))
if DD_MULTILINE_LOG_REGEX_PATTERN
else None
)
# a private data store for event attributes
self.data_store = S3EventDataStore()

Expand Down Expand Up @@ -283,12 +288,12 @@ def _extract_cloudtrail_logs(self):
def _extract_other_logs(self):
# Check if using multiline log regex pattern
# and determine whether line or pattern separated logs
if self.multiline_regex_start_pattern:
if self.multiline_regex_start_pattern and self.multiline_regex_pattern:
# We'll do string manipulation, so decode bytes into utf-8 first
self.data_store.data = self.data_store.data.decode("utf-8", errors="ignore")

if self.multiline_regex_start_pattern.match(self.data_store.data):
self.data_store.data = self.multiline_regex_start_pattern.split(
self.data_store.data = self.multiline_regex_pattern.split(
self.data_store.data
)
else:
Expand Down

0 comments on commit 97e1162

Please sign in to comment.