Skip to content

Commit 46f2b67

Browse files
committed
feat: Allow using contentctl to send data trough EP with hec (ADDON-82127)
1 parent 6df8352 commit 46f2b67

File tree

2 files changed

+35
-7
lines changed

2 files changed

+35
-7
lines changed

contentctl/actions/detection_testing/infrastructures/DetectionTestingInfrastructure.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1481,16 +1481,19 @@ def hec_raw_replay(
14811481
"host": attack_data_file.host or self.sync_obj.replay_host,
14821482
}
14831483

1484-
if self.infrastructure.instance_address.strip().lower().startswith("https://"):
1485-
address_with_scheme = self.infrastructure.instance_address.strip().lower()
1486-
elif self.infrastructure.instance_address.strip().lower().startswith("http://"):
1484+
hec_instance_address = (
1485+
self.infrastructure.hec_instance_address
1486+
if self.infrastructure.hec_instance_address
1487+
else self.infrastructure.instance_address
1488+
)
1489+
if hec_instance_address.strip().lower().startswith("https://"):
1490+
address_with_scheme = hec_instance_address.strip().lower()
1491+
elif hec_instance_address.strip().lower().startswith("http://"):
14871492
address_with_scheme = (
1488-
self.infrastructure.instance_address.strip()
1489-
.lower()
1490-
.replace("http://", "https://")
1493+
hec_instance_address.strip().lower().replace("http://", "https://")
14911494
)
14921495
else:
1493-
address_with_scheme = f"https://{self.infrastructure.instance_address}"
1496+
address_with_scheme = f"https://{hec_instance_address}"
14941497

14951498
# Generate the full URL, including the host, the path, and the params.
14961499
# We can be a lot smarter about this (and pulling the port from the url, checking

contentctl/objects/config.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -713,6 +713,10 @@ class Infrastructure(BaseModel):
713713
web_ui_port: int = Field(default=8000, gt=1, lt=65536, title="Web UI Port")
714714
api_port: int = Field(default=8089, gt=1, lt=65536, title="REST API Port")
715715
instance_name: str = Field(...)
716+
hec_instance_address: Optional[str] = Field(
717+
default=instance_address,
718+
description="HTTP Event Collector Address. Equal to instance_address or Edge Processor Address.",
719+
)
716720

717721

718722
class Container(Infrastructure):
@@ -1260,6 +1264,16 @@ class test_servers(test_common):
12601264
"Note that these test_instances may be hosted on the same system, such as localhost/127.0.0.1 or a docker server, or different hosts.\n"
12611265
f"This value may also be passed by setting the environment variable [{TEST_ARGS_ENV}] with the value above.",
12621266
)
1267+
hec_server_overrides: Optional[str] = Field(
1268+
None,
1269+
validate_default=True,
1270+
description="String override servers to use for testing. The list MUST be in the format:\n"
1271+
"hec_address_override;hec_address_override_2"
1272+
"\nFor example, the following string will use 2 preconfigured hec instances:\n"
1273+
"127.0.0.1;1.2.3.4\n"
1274+
"Note that these hec_server_overrides may be hosted on the same system, such as localhost/127.0.0.1 or a docker server or different hosts.\n"
1275+
"Note that this assumes that Splunk hec token is valid for that server and that the hec port is the same as the hec_port for respective server.\n",
1276+
)
12631277

12641278
@model_validator(mode="before")
12651279
@classmethod
@@ -1279,11 +1293,21 @@ def parse_config(cls, data: Any, info: ValidationInfo) -> Any:
12791293

12801294
infrastructures: List[Infrastructure] = []
12811295

1296+
split_hec_server_overrides = []
1297+
hec_server_overrides = data.get("hec_server_overrides")
1298+
if hec_server_overrides:
1299+
split_hec_server_overrides = hec_server_overrides.split(";")
1300+
12821301
index = 0
12831302
for server in server_info.split(";"):
12841303
address, username, password, web_ui_port, hec_port, api_port = server.split(
12851304
","
12861305
)
1306+
hec_address = (
1307+
split_hec_server_overrides[index]
1308+
if len(split_hec_server_overrides) > index
1309+
else address
1310+
)
12871311
infrastructures.append(
12881312
Infrastructure(
12891313
splunk_app_username=username,
@@ -1293,6 +1317,7 @@ def parse_config(cls, data: Any, info: ValidationInfo) -> Any:
12931317
web_ui_port=int(web_ui_port),
12941318
api_port=int(api_port),
12951319
instance_name=f"test_server_{index}",
1320+
hec_instance_address=hec_address,
12961321
)
12971322
)
12981323
index += 1

0 commit comments

Comments
 (0)