Skip to content

Commit

Permalink
Checks for ElasticSearch 0.9x and 1.x
Browse files Browse the repository at this point in the history
/_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.
  • Loading branch information
Martin Cozzi committed Apr 15, 2014
1 parent 83d6d9f commit 7c54ff4
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions plugins/elasticsearch/check-es-cluster-status.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 7c54ff4

Please sign in to comment.