ElasticSearchExporter

class resilient_exporters.exporters.ElasticSearchExporter(target_ip: str = None, target_port: int = 9300, username: str = None, password: str = None, cluster_hosts: Iterable[str] = None, cloud_id: str = None, api_key: str = None, sniff_on_start: bool = True, default_index: Optional[str] = None, use_ssl: bool = False, ssl_certfile: str = None, ssl_ca_certs: str = None, **kwargs)[source]

Exporter for ElasticSearch.

Parameters
  • target_ip (str) – an IP address of a ElasticSearch server.

  • target_port (int) – the port to connect to. Default to 9300.

  • username (str) – the username for authentication.

  • password (str) – the password as plain text for authentication. Use an environement variable for security.

  • cluster_hosts (Iterable[Text]) – cluster of hosts, passed to ES’s client application.

  • cloud_id (str) – cloud id used to connect to a Elastic Cloud server. A username and password is most likely required to be able to connect.

  • api_key (str) – a base64 encoded token to authenticate to a ElasticSearch server.

  • sniff_on_start (bool) – see Elasticsearch documentation.

  • default_index (str) – a default index to use when send is called. If None, an index will have to be provided as an argument when calling send.

  • **kwargs – the keyword arguments to pass down to parent’s class Exporter

Warning

If target_ip is provided, it will supercede cluster_hosts.

property client

The Elasticsearch client. It cannot be replaced.

has_unsent_data() → bool

Assesses if there’s saved, unsent data.

Returns

True if there’s saved, unsent data. False otherwise.

Return type

bool

save_unsent_data(data: Any, kwargs: dict, exporter_name: str) → None

Saves the data in memory or disk, depending on the value of use_memory of the instance, so it can be sent later.

Parameters
  • data (Any) – the core data.

  • kwargs (dict) – the keyword arguments to pass to send for the given data.

  • exporter_name (str) – the name of the exporter.

Returns

None

send(data: dict, index: Optional[str] = None) → resilient_exporters.exporters.ExportResult[source]

Indexes the data into an ElasicSearch index.

Parameters
  • data (dict) – the data, as a dict, to index.

  • index (str) – the index name. If None, it uses the default value provided at initialisation.

Returns

(Object, True) if successful, (None, False) otherwise.

Return type

ExportResult

Raises
send_unsent_data() → List[resilient_exporters.exporters.ExportResult]

Tries to send the previously saved, unsent data.

Returns

list of the results of the export jobs.

Return type

List[ExportResult]

transform(data: Any) → Any

Applies transform to the given data.

Parameters

data (Any) – the data to pass to transform.

Returns

the output of transform

Return type

Any

Raises

Exception – if the output of transform(data) is None.

property use_memory

The value use_memory of the instance.

When set to True, it loads the data into memory if it was previously using a file (previous value was False), or vice versa.

Parameters

new_val (bool) – new value for use_memory.

Returns

its value

Return type

bool