Switch to OpenSearch

This commit is contained in:
Mark Veidemanis 2022-05-13 16:23:23 +01:00
parent 3973413f51
commit c516bb9ca9
Signed by: m
GPG Key ID: 5ACFCEED46C0904F
1 changed files with 22 additions and 8 deletions

View File

@ -7,7 +7,7 @@ from pycoingecko import CoinGeckoAPI
from forex_python.converter import CurrencyRates
import urllib3
import logging
from elasticsearch import Elasticsearch
from opensearchpy import OpenSearch
from datetime import datetime
# Project imports
@ -17,7 +17,7 @@ import util
# TODO: secure ES traffic properly
urllib3.disable_warnings()
tracer = logging.getLogger("elasticsearch")
tracer = logging.getLogger("opensearch")
tracer.setLevel(logging.CRITICAL)
tracer = logging.getLogger("elastic_transport.transport")
tracer.setLevel(logging.CRITICAL)
@ -38,12 +38,26 @@ class Money(util.Base):
self.cr = CurrencyRates()
self.cg = CoinGeckoAPI()
if settings.ES.Enabled == "1":
self.es = Elasticsearch(
f"https://{settings.ES.Host}:9200",
# self.es = Elasticsearch(
# f"https://{settings.ES.Host}:9200",
# verify_certs=False,
# basic_auth=(settings.ES.Username, settings.ES.Pass),
# # ssl_assert_fingerprint=("6b264fd2fd107d45652d8add1750a8a78f424542e13b056d0548173006260710"),
# ca_certs="certs/ca.crt",
# )
# TODO: implement ca certs https://opensearch.org/docs/latest/clients/python/
auth = (settings.ES.Username, settings.ES.Pass)
self.es = OpenSearch(
hosts=[{"host": settings.ES.Host, "port": 9200}],
http_compress=False, # enables gzip compression for request bodies
http_auth=auth,
# client_cert = client_cert_path,
# client_key = client_key_path,
use_ssl=True,
verify_certs=False,
basic_auth=(settings.ES.Username, settings.ES.Pass),
# ssl_assert_fingerprint=("6b264fd2fd107d45652d8add1750a8a78f424542e13b056d0548173006260710"),
ca_certs="certs/ca.crt",
ssl_assert_hostname=False,
ssl_show_warn=False,
# a_certs=ca_certs_path,
)
def run_checks_in_thread(self):
@ -73,7 +87,7 @@ class Money(util.Base):
cast["type"] = msgtype
cast["ts"] = str(datetime.now().isoformat())
cast["xtype"] = "tx"
self.es.index(index=settings.ES.Index, document=cast)
self.es.index(index=settings.ES.Index, body=cast)
def lookup_rates(self, platform, ads, rates=None):
"""