Skip to content

Commit fafd0a9

Browse files
authored
Merge pull request #11644 from Azure/v-sabiraj-crowdstrikev2-jsondecoder
Updated code to handle JSON decode error
2 parents 387b404 + 80097c6 commit fafd0a9

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

Solutions/CrowdStrike Falcon Endpoint Protection/Data Connectors/CrowdstrikeReplicatorCLv2/CrowdstrikeFalconAPISentinelConn/QueueTriggerCS/__init__.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,12 @@ async def main(msg: func.QueueMessage) -> None:
106106
# requireRaw : bool
107107
def customize_event(line, eventsSchemaMappingDict, requiredFieldsMappingDict, requireRaw):
108108

109-
element = json.loads(line)
109+
try:
110+
element = json.loads(line) # Attempt to parse the line as JSON
111+
except json.JSONDecodeError as e:
112+
# Log the error and skip this line
113+
logging.error(f"JSON decoding error for line: {line}. Error: {str(e)}")
114+
return None, None
110115
if "event_simpleName" in element and element["event_simpleName"] in eventsSchemaMappingDict:
111116
schema = eventsSchemaMappingDict[element["event_simpleName"]]
112117
else:
@@ -201,13 +206,14 @@ async def process_file_primary_CLv2(bucket, s3_path, client, session, eventsSche
201206
if line:
202207
try:
203208
normalizedEvent, customizedEvent = customize_event(line, eventsSchemaMappingDict, requiredFieldsMappingDict, REQUIRE_RAW)
204-
except ValueError as e:
205-
logging.error('Error while loading json Event at s value {}. Error: {}'.format(line, str(e)))
206-
raise e
209+
if normalizedEvent is None: # Skip this line if it's invalid
210+
continue
207211
except Exception as e:
208-
logging.error(e)
209-
await normalizedSentinelHelperCollection.sendData(normalizedEvent)
210-
if REQUIRE_RAW:
212+
logging.error(f"Error while processing line: {line}. Error: {str(e)}")
213+
continue
214+
if normalizedEvent:
215+
await normalizedSentinelHelperCollection.sendData(normalizedEvent)
216+
if REQUIRE_RAW and customizedEvent:
211217
await customizedSentinelHelperCollection.sendData(customizedEvent)
212218
s = line
213219
if s:

0 commit comments

Comments
 (0)