diff --git a/docs/migrating.md b/docs/migrating.md index bff88fe..657f037 100644 --- a/docs/migrating.md +++ b/docs/migrating.md @@ -186,7 +186,7 @@ Use a `.elasticsearch:Elasticsearch` Sink. - `timeout`: moved to `client.timeout`. - `cert_path`: moved to `client.cert_path`. - `index_suffix`: no changes. -- `index_prefix`: not supported - [GitHub Issue #12](https://github.com/nhairs/parsedmarc-fork/issues/12). +- `index_prefix`: no changes. - `monthly_indexes`: no changes. - `number_of_shards`: no changes. - `number_of_replicas`: no changes. diff --git a/src/parsedmarc/elastic.py b/src/parsedmarc/elastic.py index 542f4fd..7baf6b4 100644 --- a/src/parsedmarc/elastic.py +++ b/src/parsedmarc/elastic.py @@ -194,6 +194,7 @@ def __init__( # pylint: disable=too-many-positional-arguments api_key: str | None = None, timeout: float = 60.0, index_suffix: str | None = None, + index_prefix: str = "", monthly_indexes: bool = True, number_of_shards: int = 1, number_of_replicas: int = 0, @@ -230,8 +231,8 @@ def __init__( # pylint: disable=too-many-positional-arguments self.client = Elasticsearch(**conn_params) # type: ignore[arg-type] ## Other settings - self.aggregate_index_base = "dmarc_aggregate" - self.forensic_index_base = "dmarc_forensic" + self.aggregate_index_base = f"{index_prefix}dmarc_aggregate" + self.forensic_index_base = f"{index_prefix}dmarc_forensic" if index_suffix: self.aggregate_index_base += f"_{index_suffix}" diff --git a/src/parsedmarc/sink/elasticsearch.py b/src/parsedmarc/sink/elasticsearch.py index 77f8d4a..5bfb8ab 100644 --- a/src/parsedmarc/sink/elasticsearch.py +++ b/src/parsedmarc/sink/elasticsearch.py @@ -41,6 +41,7 @@ def setup(self) -> None: api_key=self.config.client.api_key, timeout=self.config.client.timeout, index_suffix=self.config.index_suffix, + index_prefix=self.config.index_prefix, monthly_indexes=self.config.monthly_indexes, number_of_shards=self.config.number_of_shards, number_of_replicas=self.config.number_of_replicas, @@ -85,6 +86,7 @@ class ElasticsearchConfig(BaseConfig): client: ElasticsearchClientConfig index_suffix: Union[str, None] = None + index_prefix: str = "" monthly_indexes: bool = True number_of_shards: int = 1 number_of_replicas: int = 0