From 10298ced8f00d9e7f2879a0824f9e964a5635e0e Mon Sep 17 00:00:00 2001 From: lza_menace Date: Sun, 27 Sep 2020 05:54:38 -0700 Subject: [PATCH] add elasticsearch bypass --- wowstash/config.example.py | 1 + wowstash/library/elasticsearch.py | 31 ++++++++++++++++--------------- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/wowstash/config.example.py b/wowstash/config.example.py index 99ccb23..07131c7 100644 --- a/wowstash/config.example.py +++ b/wowstash/config.example.py @@ -37,6 +37,7 @@ DB_PASS = 'zzzzzzzzz' # Development TEMPLATES_AUTO_RELOAD = True +ELASTICSEARCH_ENABLED = False # Social SOCIAL = { diff --git a/wowstash/library/elasticsearch.py b/wowstash/library/elasticsearch.py index d3ce5a6..5e62e39 100644 --- a/wowstash/library/elasticsearch.py +++ b/wowstash/library/elasticsearch.py @@ -4,18 +4,19 @@ from wowstash import config def send_es(data): - try: - es = Elasticsearch( - [getattr(config, 'ELASTICSEARCH_HOST', 'localhost')] - ) - now = datetime.utcnow() - index_ts = now.strftime('%Y%m%d') - data['datetime'] = now - es.index( - index="{}-{}".format( - getattr(config, 'ELASTICSEARCH_INDEX_NAME', 'wowstash'), - index_ts - ), body=data) - except Exception as e: - print('Could not capture event in Elasticsearch: ', e) - pass # I don't really care if this logs... + if getattr(config, 'ELASTICSEARCH_ENABLED', False): + try: + es = Elasticsearch( + [getattr(config, 'ELASTICSEARCH_HOST', 'localhost')] + ) + now = datetime.utcnow() + index_ts = now.strftime('%Y%m%d') + data['datetime'] = now + es.index( + index="{}-{}".format( + getattr(config, 'ELASTICSEARCH_INDEX_NAME', 'wowstash'), + index_ts + ), body=data) + except Exception as e: + print('Could not capture event in Elasticsearch: ', e) + pass # I don't really care if this logs...