Skip to content

Commit

Permalink
Merge pull request #205 from jeffk/dyn_elasticsearch_version
Browse files Browse the repository at this point in the history
Dyn elasticsearch version
  • Loading branch information
jbuchbinder committed Jul 17, 2015
2 parents 2b04b99 + e23009b commit 12ff387
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions elasticsearch/python_modules/elasticsearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,12 +187,20 @@ def metric_init(params):

host = params.get('host', 'http://localhost:9200/')

version = params.get('version', '1.2')

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)

m = re.match('(?P<major>\d+)\.(?P<minor>(\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)

Expand Down

0 comments on commit 12ff387

Please sign in to comment.