Skip to content

Commit ea7de82

Browse files
[FR] Add Kibana Action Connector Error to Exception List Workaround (#4583)
* Add error catch for workaround * Switch to set for efficiency * Patch version bump --------- Co-authored-by: Mika Ayenson, PhD <[email protected]>
1 parent 108b64f commit ea7de82

File tree

2 files changed

+26
-9
lines changed

2 files changed

+26
-9
lines changed

detection_rules/kbwrap.py

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -108,27 +108,44 @@ def _parse_list_id(s: str):
108108

109109
# Re-try to address known Kibana issue: https://github.com/elastic/kibana/issues/143864
110110
workaround_errors = []
111+
workaround_error_types = set()
111112

112113
flattened_exceptions = [e for sublist in exception_dicts for e in sublist]
113114
all_exception_list_ids = {exception["list_id"] for exception in flattened_exceptions}
114115

115116
click.echo(f'{len(response["errors"])} rule(s) failed to import!')
116117

118+
action_connector_validation_error = "Error validating create data"
119+
action_connector_type_error = "expected value of type [string] but got [undefined]"
117120
for error in response['errors']:
118-
click.echo(f' - {error["rule_id"]}: ({error["error"]["status_code"]}) {error["error"]["message"]}')
121+
error_message = error["error"]["message"]
122+
click.echo(f' - {error["rule_id"]}: ({error["error"]["status_code"]}) {error_message}')
119123

120-
if "references a non existent exception list" in error["error"]["message"]:
121-
list_id = _parse_list_id(error["error"]["message"])
124+
if "references a non existent exception list" in error_message:
125+
list_id = _parse_list_id(error_message)
122126
if list_id in all_exception_list_ids:
123127
workaround_errors.append(error["rule_id"])
128+
workaround_error_types.add("non existent exception list")
129+
130+
if action_connector_validation_error in error_message and action_connector_type_error in error_message:
131+
workaround_error_types.add("connector still being built")
124132

125133
if workaround_errors:
126134
workaround_errors = list(set(workaround_errors))
127-
click.echo(f'Missing exception list errors detected for {len(workaround_errors)} rules. '
128-
'Try re-importing using the following command and rule IDs:\n')
129-
click.echo('python -m detection_rules kibana import-rules -o ', nl=False)
130-
click.echo(' '.join(f'-id {rule_id}' for rule_id in workaround_errors))
131-
click.echo()
135+
if "non existent exception list" in workaround_error_types:
136+
click.echo(
137+
f"Missing exception list errors detected for {len(workaround_errors)} rules. "
138+
"Try re-importing using the following command and rule IDs:\n"
139+
)
140+
click.echo("python -m detection_rules kibana import-rules -o ", nl=False)
141+
click.echo(" ".join(f"-id {rule_id}" for rule_id in workaround_errors))
142+
click.echo()
143+
if "connector still being built" in workaround_error_types:
144+
click.echo(
145+
f"Connector still being built errors detected for {len(workaround_errors)} rules. "
146+
"Please try re-importing the rules again."
147+
)
148+
click.echo()
132149

133150
def _process_imported_items(imported_items_list, item_type_description, item_key):
134151
"""Displays appropriately formatted success message that all items imported successfully."""

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "detection_rules"
3-
version = "1.0.6"
3+
version = "1.0.7"
44
description = "Detection Rules is the home for rules used by Elastic Security. This repository is used for the development, maintenance, testing, validation, and release of rules for Elastic Security’s Detection Engine."
55
readme = "README.md"
66
requires-python = ">=3.12"

0 commit comments

Comments
 (0)