Skip to content

Commit

Permalink
Merge pull request #11273 from Azure/updatesentinelingestionscript01
Browse files Browse the repository at this point in the history
Update ingestASimSampleData.py
  • Loading branch information
v-atulyadav authored Oct 15, 2024
2 parents 56d6352 + 5203697 commit fe3e60f
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion .script/tests/asimParsersTest/ingestASimSampleData.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,28 @@ def extract_event_vendor_product(parser_query,parser_file):
print(f'Event Product field not mapped in parser. Please map it in parser query.{parser_file}')
return event_vendor, event_product ,schema_name

def convert_data_type(schema_result, data_result):
for data in data_result:
for schema in schema_result:
field_name = schema["name"]
field_type = schema["type"]

if field_name in data:
value = data[field_name]

# Handle conversion based on schema type

if field_type == "string":
# Convert to string
data[field_name] = str(value)
elif field_type == "boolean":
# Convert to boolean
if isinstance(value, str) and value.lower() in ["true", "false"]:
data[field_name] = value.lower() == "true"

return data_result


#main starting point of script

workspace_id = "e9beceee-7d61-429f-a177-ee5e2b7f481a"
Expand Down Expand Up @@ -336,7 +358,11 @@ def extract_event_vendor_product(parser_query,parser_file):
else:
print(f"::error::An error occurred while trying to get content of Schema file located at {schemaUrl}: {response.text}")
continue
schema_result = convert_schema_csv_to_json('tempfile.csv')
schema_result = convert_schema_csv_to_json('tempfile.csv')
data_result = convert_data_type(schema_result, data_result)
# conversion of datatype is needed for boolean and string values because during testing it has been observed that
# boolean values are consider as string and numerical value of type string are consider
# as integer which leds to non ingestion of those value in sentinel
# create table
request_body, url_to_call , method_to_use = create_table(json.dumps(schema_result, indent=4),table_name)
response_body=hit_api(url_to_call,request_body,method_to_use)
Expand Down

0 comments on commit fe3e60f

Please sign in to comment.