|
29 | 29 | from .rule import TOMLRule, TOMLRuleContents, downgrade_contents_from_rule |
30 | 30 | from .rule_loader import RawRuleCollection, RuleCollection, update_metadata_from_file |
31 | 31 | from .schemas import definitions # noqa: TC001 |
32 | | -from .utils import format_command_options, rulename_to_filename |
| 32 | +from .utils import CUSTOM_RULES_KQL, format_command_options, rulename_to_filename |
33 | 33 |
|
34 | 34 | RULES_CONFIG = parse_rules_config() |
35 | 35 |
|
@@ -303,9 +303,7 @@ def kibana_export_rules( # noqa: PLR0912, PLR0913, PLR0915 |
303 | 303 | query = ( |
304 | 304 | export_query |
305 | 305 | if not custom_rules_only |
306 | | - else ( |
307 | | - f'alert.attributes.params.ruleSource.type: "internal"{f" and ({export_query})" if export_query else ""}' |
308 | | - ) |
| 306 | + else (f"({CUSTOM_RULES_KQL}){f' and ({export_query})' if export_query else ''}") |
309 | 307 | ) |
310 | 308 |
|
311 | 309 | results = ( # type: ignore[reportUnknownVariableType] |
@@ -336,8 +334,10 @@ def kibana_export_rules( # noqa: PLR0912, PLR0913, PLR0915 |
336 | 334 | rules_results = results # type: ignore[reportUnknownVariableType] |
337 | 335 | action_connector_results = [] |
338 | 336 | exception_results = [] |
| 337 | + results_len = len(results) # type: ignore[reportUnknownVariableType] |
339 | 338 | if kibana_include_details: |
340 | 339 | # Assign counts to variables |
| 340 | + results_len = results_len - 1 |
341 | 341 | rules_count = results[-1]["exported_rules_count"] # type: ignore[reportUnknownVariableType] |
342 | 342 | exception_list_count = results[-1]["exported_exception_list_count"] # type: ignore[reportUnknownVariableType] |
343 | 343 | exception_list_item_count = results[-1]["exported_exception_list_item_count"] # type: ignore[reportUnknownVariableType] |
@@ -497,7 +497,7 @@ def kibana_export_rules( # noqa: PLR0912, PLR0913, PLR0915 |
497 | 497 |
|
498 | 498 | saved_action_connectors.append(action) |
499 | 499 |
|
500 | | - click.echo(f"{len(results)} results exported") # type: ignore[reportUnknownArgumentType] |
| 500 | + click.echo(f"{results_len} results exported") # type: ignore[reportUnknownArgumentType] |
501 | 501 | click.echo(f"{len(exported)} rules converted") |
502 | 502 | click.echo(f"{len(exceptions)} exceptions exported") |
503 | 503 | click.echo(f"{len(action_connectors)} action connectors exported") |
|
0 commit comments