Skip to content

Commit 4243e6c

Browse files
Update elk.py - ES7 support
1 parent 706f743 commit 4243e6c

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

analyzers/Elasticsearch/elk.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
#!/usr/bin/env python3
22

3-
from elasticsearch import Elasticsearch
3+
from elasticsearch import Elasticsearch, VERSION as ES_VERSION
44
from cortexutils.analyzer import Analyzer
55
import dateutil.parser
66
from datetime import datetime
77
import pytz
8+
from packaging.version import Version
89

910
# utils
1011
import operator
@@ -142,21 +143,29 @@ def run(self):
142143
client_timeout = 30 # seconds
143144

144145
for endpoint,key,user,password in zip(self.endpoints,self.keys,self.users,self.passwords):
146+
hosts = [endpoint] if isinstance(endpoint, str) else endpoint
145147
es_dict = dict(
146-
hosts=endpoint,
148+
hosts=hosts,
147149
ca_certs=self.cert,
148150
verify_certs=self.verify,
149151
request_timeout=client_timeout,
150-
connections_per_node=20, # prevent FullPoolError
151152
max_retries=3,
152153
retry_on_timeout=True,
153154
http_compress=True,
154155
)
155-
156+
157+
if Version(".".join(map(str, ES_VERSION))) < Version("8.0.0"):
158+
es_dict["maxsize"] = 20
159+
else:
160+
es_dict["connections_per_node"] = 20
161+
156162
if key:
157163
es_dict["api_key"] = key
158164
elif user:
159-
es_dict["basic_auth"] = (user, password)
165+
if Version(".".join(map(str, ES_VERSION))) < Version("8.0.0"):
166+
es_dict["http_auth"] = (user, password)
167+
else:
168+
es_dict["basic_auth"] = (user, password)
160169

161170
# ES client (ensure connections get closed)
162171
with Elasticsearch(**es_dict) as es:

0 commit comments

Comments
 (0)