2022-12-13 07:20:49 +00:00
|
|
|
from datetime import datetime
|
|
|
|
|
|
|
|
from django.conf import settings
|
2023-08-26 11:05:28 +00:00
|
|
|
from elastic_transport import ConnectionError
|
2022-12-13 07:20:49 +00:00
|
|
|
from elasticsearch import Elasticsearch
|
|
|
|
|
|
|
|
from core.util import logs
|
|
|
|
|
|
|
|
log = logs.get_logger(__name__)
|
|
|
|
|
|
|
|
client = None
|
|
|
|
|
|
|
|
|
|
|
|
def initialise_elasticsearch():
|
|
|
|
"""
|
|
|
|
Initialise the Elasticsearch client.
|
|
|
|
"""
|
|
|
|
auth = (settings.ELASTICSEARCH_USERNAME, settings.ELASTICSEARCH_PASSWORD)
|
|
|
|
client = Elasticsearch(
|
|
|
|
settings.ELASTICSEARCH_HOST, http_auth=auth, verify_certs=False
|
|
|
|
)
|
|
|
|
return client
|
|
|
|
|
|
|
|
|
|
|
|
def store_msg(index, msg):
|
2024-11-16 17:31:43 +00:00
|
|
|
return
|
|
|
|
# global client
|
|
|
|
# if not client:
|
|
|
|
# client = initialise_elasticsearch()
|
|
|
|
# if "ts" not in msg:
|
|
|
|
# msg["ts"] = datetime.utcnow().isoformat()
|
|
|
|
# try:
|
|
|
|
# result = client.index(index=index, body=msg)
|
|
|
|
# except ConnectionError as e:
|
|
|
|
# log.error(f"Error indexing '{msg}': {e}")
|
|
|
|
# return
|
|
|
|
# if not result["result"] == "created":
|
|
|
|
# log.error(f"Indexing of '{msg}' failed: {result}")
|