@@ -78,8 +78,8 @@ def example_udm_search(chronicle):
7878
7979
8080def example_udm_search_view (chronicle ):
81- """Example 14 : UDM Search View."""
82- print ("\n === Example 14 : UDM Search View ===" )
81+ """Example 15 : UDM Search View."""
82+ print ("\n === Example 15 : UDM Search View ===" )
8383 start_time , end_time = get_time_range ()
8484
8585 try :
@@ -1413,9 +1413,48 @@ def example_parser_workflow(chronicle):
14131413 print (f"\n Unexpected error: { e } " )
14141414
14151415
1416+ def example_fetch_parser_candidates (chronicle ):
1417+ """Example 13: Fetch Parser Candidates for a log type."""
1418+ print ("\n === Example 13: Fetch Parser Candidates ===" )
1419+
1420+ log_type = "OKTA"
1421+ parser_action = "PARSER_ACTION_OPT_IN_TO_PREVIEW"
1422+
1423+ try :
1424+ print (
1425+ f"\n Fetching parser candidates for log type '{ log_type } ' "
1426+ f"with action '{ parser_action } '..."
1427+ )
1428+ candidates = chronicle .fetch_parser_candidates (
1429+ log_type = log_type ,
1430+ parser_action = parser_action ,
1431+ )
1432+
1433+ if not candidates :
1434+ print (f"No parser candidates found for log type '{ log_type } '." )
1435+ return
1436+
1437+ print (f"Found { len (candidates )} parser candidate(s):" )
1438+ for candidate in candidates :
1439+ name = candidate .get ("name" , "N/A" )
1440+ state = candidate .get ("state" , "N/A" )
1441+ parser_id = name .split ("/" )[- 1 ]
1442+ print (f" - ID: { parser_id } , State: { state } " )
1443+
1444+ except APIError as e :
1445+ print (f"\n API Error: { e } " )
1446+ print ("\n Troubleshooting tips:" )
1447+ print (
1448+ "- Ensure the log type supports prebuilt parser candidates"
1449+ )
1450+ print ("- Check if you have the required permissions" )
1451+ except ValueError as e :
1452+ print (f"\n Invalid input: { e } " )
1453+
1454+
14161455def example_rule_test (chronicle ):
1417- """Example 13 : Test a detection rule against historical data."""
1418- print ("\n === Example 13 : Test a Detection Rule Against Historical Data ===" )
1456+ """Example 14 : Test a detection rule against historical data."""
1457+ print ("\n === Example 14 : Test a Detection Rule Against Historical Data ===" )
14191458
14201459 # Define time range for testing - use a recent time period (last 7 days)
14211460 end_time = datetime .now (timezone .utc ) - timedelta (minutes = 15 )
@@ -1491,8 +1530,9 @@ def example_rule_test(chronicle):
14911530 "10" : example_udm_ingestion ,
14921531 "11" : example_gemini ,
14931532 "12" : example_parser_workflow ,
1494- "13" : example_rule_test ,
1495- "14" : example_udm_search_view ,
1533+ "13" : example_fetch_parser_candidates ,
1534+ "14" : example_rule_test ,
1535+ "15" : example_udm_search_view ,
14961536}
14971537
14981538
@@ -1507,7 +1547,7 @@ def main():
15071547 parser .add_argument (
15081548 "--example" ,
15091549 "-e" ,
1510- help = "Example number to run (1-14 ). If not specified, runs all examples." ,
1550+ help = "Example number to run (1-15 ). If not specified, runs all examples." ,
15111551 )
15121552
15131553 args = parser .parse_args ()
0 commit comments