Skip to content

Commit 277abb6

Browse files
authored
Merge pull request #11225 from Azure/ingestionscriptasimupdate
Update ingestASimSampleData.py
2 parents a3da44d + 8b8ff2c commit 277abb6

File tree

1 file changed

+28
-9
lines changed

1 file changed

+28
-9
lines changed

.script/tests/asimParsersTest/ingestASimSampleData.py

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -68,19 +68,36 @@ def convert_schema_csv_to_json(csv_file):
6868
return data
6969

7070
def convert_data_csv_to_json(csv_file):
71+
def convert_value(value):
72+
# Try to convert the value to an integer, then to a float, and keep it as a string if those fail
73+
try:
74+
# Try integer conversion
75+
return int(value)
76+
except ValueError:
77+
try:
78+
# Try float conversion
79+
return float(value)
80+
except ValueError:
81+
# Return the value as-is (string) if it's not numeric
82+
return value
83+
7184
data = []
72-
with open(csv_file, 'r',encoding='utf-8-sig') as file:
85+
with open(csv_file, 'r', encoding='utf-8-sig') as file:
7386
reader = csv.DictReader(file)
7487
for row in reader:
75-
table_name=row['Type']
76-
data.append(row)
88+
table_name = row['Type']
89+
# Convert each value in the row to its appropriate type
90+
processed_row = {key: convert_value(value) for key, value in row.items()}
91+
data.append(processed_row)
92+
7793
for item in data:
7894
for key in list(item.keys()):
79-
# If the key matches 'TimeGenerated [UTC]', rename it
80-
if key.endswith('[UTC]'):
81-
substring = key.split(" [")[0]
82-
item[substring] = item.pop(key)
83-
return data , table_name
95+
# If the key matches '[UTC]' or '[Local Time]', rename it
96+
if key.endswith(('[UTC]', '[Local Time]')):
97+
substring = key.split(" [")[0]
98+
item[substring] = item.pop(key)
99+
100+
return data, table_name
84101

85102
def check_for_custom_table(table_name):
86103
if table_name in lia_supported_builtin_table:
@@ -288,9 +305,11 @@ def extract_event_vendor_product(parser_query,parser_file):
288305
asim_parser_url = f'{SENTINEL_REPO_RAW_URL}/{commit_number}/{file}'
289306
asim_parser = read_github_yaml(asim_parser_url)
290307
parser_query = asim_parser.get('ParserQuery', '')
308+
normalization = asim_parser.get('Normalization', {})
309+
schema = normalization.get('Schema')
291310
event_vendor, event_product, schema_name = extract_event_vendor_product(parser_query, file)
292311

293-
SampleDataFile = f'{event_vendor}_{event_product}_{schema_name}_IngestedLogs.csv'
312+
SampleDataFile = f'{event_vendor}_{event_product}_{schema}_IngestedLogs.csv'
294313
sample_data_url = f'{SENTINEL_REPO_RAW_URL}/{commit_number}/{SAMPLE_DATA_PATH}'
295314
SampleDataUrl = sample_data_url+SampleDataFile
296315
response = requests.get(SampleDataUrl)

0 commit comments

Comments
 (0)