From 1eba68cd37c3d8e7c4de52f0e82dc615bb6e4d0e Mon Sep 17 00:00:00 2001 From: Jeff Kramer Date: Fri, 17 Jul 2015 10:08:14 -0500 Subject: [PATCH 1/2] add dynamic-version-awareness and 1.3.2 support to elasticsearch --- elasticsearch/python_modules/elasticsearch.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/elasticsearch/python_modules/elasticsearch.py b/elasticsearch/python_modules/elasticsearch.py index 2aa9643d..e52d4362 100755 --- a/elasticsearch/python_modules/elasticsearch.py +++ b/elasticsearch/python_modules/elasticsearch.py @@ -187,12 +187,17 @@ def metric_init(params): host = params.get('host', 'http://localhost:9200/') - version = params.get('version', '1.2') - + result = json.load(urllib.urlopen(host)) + + host_version = result.get('version',{}).get('number') or "1.2" + version = params.get('version', host_version) + m = re.match('(?P\d+)\.(?P(\d+(\.\d+)*))', version) - + if m and m.group('major') == '0': url_cluster = '{0}_cluster/nodes/_local/stats?all=true'.format(host) + elif m and m.group('major') == '1' and m.group('minor') == '3.2': + url_cluster = '{0}_nodes/_local/stats'.format(host) else: url_cluster = '{0}_cluster/state/nodes'.format(host) From e23009b02f167018221b87e0bb6902377813bda9 Mon Sep 17 00:00:00 2001 From: Jeff Kramer Date: Fri, 17 Jul 2015 10:12:55 -0500 Subject: [PATCH 2/2] fails cleanly if root node is unavailable --- elasticsearch/python_modules/elasticsearch.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/elasticsearch/python_modules/elasticsearch.py b/elasticsearch/python_modules/elasticsearch.py index e52d4362..405fb652 100755 --- a/elasticsearch/python_modules/elasticsearch.py +++ b/elasticsearch/python_modules/elasticsearch.py @@ -187,7 +187,10 @@ def metric_init(params): host = params.get('host', 'http://localhost:9200/') - result = json.load(urllib.urlopen(host)) + try: + result = json.load(urllib.urlopen(host)) + except (ValueError, IOError): + result = {} host_version = result.get('version',{}).get('number') or "1.2" version = params.get('version', host_version)