From 7c54ff45036f3e3055caea5123b767fd6323e574 Mon Sep 17 00:00:00 2001 From: Martin Cozzi Date: Tue, 15 Apr 2014 13:21:34 -0700 Subject: [PATCH] Checks for ElasticSearch 0.9x and 1.x /_cluster/nodes/_local has been retired with ES 1.0, so this check does not work anymore. By identifying the cluster version before running the check, we can adjust the URL. --- .../elasticsearch/check-es-cluster-status.rb | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/plugins/elasticsearch/check-es-cluster-status.rb b/plugins/elasticsearch/check-es-cluster-status.rb index 083acdc89..881ec391f 100755 --- a/plugins/elasticsearch/check-es-cluster-status.rb +++ b/plugins/elasticsearch/check-es-cluster-status.rb @@ -5,6 +5,7 @@ # # DESCRIPTION: # This plugin checks the ElasticSearch cluster status, using its API. +# Works with ES 0.9x and ES 1.x # # OUTPUT: # plain-text @@ -45,10 +46,20 @@ def get_es_resource(resource) end end + def version + info = get_es_resource('/') + info['version']['number'] + end + def is_master - state = get_es_resource('/_cluster/state?filter_routing_table=true&filter_metadata=true&filter_indices=true') - local = get_es_resource('/_cluster/nodes/_local') - local['nodes'].keys.first == state['master_node'] + if Gem::Version.new(version) >= Gem::Version.new('1.0.0') + master = get_es_resource('_cluster/state/master_node')['master_node'] + local = get_es_resource('/_nodes/_local') + else + master = get_es_resource('/_cluster/state?filter_routing_table=true&filter_metadata=true&filter_indices=true')['master_node'] + local = get_es_resource('/_cluster/nodes/_local') + end + local['nodes'].keys.first == master end def get_status