Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit7a3889f

Browse files
committed
chore: update format of errors
1 parent0f861b6 commit7a3889f

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

‎mitreattack/attackToExcel/stixToDf.py‎

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ def analyticsToDf(src):
376376
analytic_rows= []
377377
logsource_rows= []
378378
analytic_to_ds_rows= []
379-
failed_analytics=set()
379+
failed_by_data_component={}
380380

381381
# analytics to detection strategies
382382
analytic_to_ds_map= {}
@@ -392,19 +392,29 @@ def analyticsToDf(src):
392392

393393
# Prints out errors where data components are not in the same domain as analytics
394394
foranalyticintqdm(analytics,desc="parsing analytics"):
395+
analytic_id=analytic.get("id")
395396
forlogsrcinanalytic.get("x_mitre_log_source_references", []):
396397
data_comp_id=logsrc.get("x_mitre_data_component_ref","")
397398
data_comp=src.get(data_comp_id)
398399
try:
399400
data_comp_attack_id=data_comp["external_references"][0]["external_id"]
400401
except (KeyError,TypeError,IndexError,AttributeError):
401-
failed_analytics.add((analytic["id"],data_comp_id))
402-
403-
iffailed_analytics:
404-
raiseRuntimeError(
405-
f"{len(failed_analytics)} failures:\n"+
406-
"\n".join(f"analytic={a}, data_component={d}"fora,dinsorted(failed_analytics))
407-
)
402+
ifdata_comp_idnotinfailed_by_data_component:
403+
failed_by_data_component[data_comp_id]= []
404+
failed_by_data_component[data_comp_id].append(analytic_id)
405+
406+
iffailed_by_data_component:
407+
lines= ["Failures grouped by data component:\n"]
408+
fordc_idinsorted(failed_by_data_component):
409+
analytic_ids=sorted(set(failed_by_data_component[dc_id]))
410+
dc_obj=src.get(dc_id)or {}
411+
dc_name=dc_obj.get("name","")
412+
413+
lines.append(f"data_component={dc_id}"+ (f" ({dc_name})"ifdc_nameelse""))
414+
lines.extend([f" - analytic={a}"forainanalytic_ids])
415+
lines.append("")
416+
417+
raiseRuntimeError("\n".join(lines))
408418

409419
foranalyticintqdm(analytics,desc="parsing analytics"):
410420
analytic_rows.append(parseBaseStix(analytic))

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2026 Movatter.jp