Created
January 5, 2012 17:00
-
-
Save octplane/1566130 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'rubygems' | |
require 'json' | |
require 'open-uri' | |
require 'yaml' | |
critical = false | |
warn= false | |
critical_msg = [] | |
warn_msg = [] | |
additional_info =[] | |
ok_msg = [] | |
config_file = '/ftn/apps/elasticsearch/master/current/config/elasticsearch.yml' | |
# Read node list from es configuration | |
if File.exists?(config_file) | |
conf = YAML.load_file(config_file) | |
nodes = conf['discovery']['zen']['ping']['unicast.hosts'] | |
expected_count = nodes.length | |
else | |
nodes = ['a02.prod.fotonauts.net'] | |
expected_count = nil | |
end | |
clusters = {} | |
nodes.each do |hostname| | |
begin | |
nodes = JSON.parse(open("http://#{hostname}:9200/_cluster/state").read)['nodes'] | |
rescue Exception => e | |
critical = true | |
critical_msg << "Unable to get cluster state on #{hostname}" | |
additional_info << e.inspect | |
next | |
end | |
if expected_count && nodes.length != expected_count | |
critical = true | |
critical_msg << "Number of node visible on #{hostname} is #{nodes.length} (should be #{expected_count})" | |
additional_info << "Visible node for #{hostname}:"+nodes.join(", ") | |
else | |
nodes = nodes.values.map { |n| n['name'] }.sort.join(", ") | |
clusters[nodes] ||= [] | |
clusters[nodes] << hostname | |
end | |
end | |
if clusters.keys.length > 1 | |
critical = true | |
critical_msg << "More than one active cluster" | |
additional_info << clusters.inspect | |
end | |
if critical | |
puts "CRITICAL "+critical_msg.join(", ") | |
puts additional_info.join("\n") | |
Process.exit 2 | |
end | |
if warn | |
puts "WARNING "+warn_msg.join(", ") | |
puts additional_info.join("\n") | |
Process.exit 1 | |
end | |
ok_msg << "OK 1 cluster with nodes #{clusters.keys[0]}." | |
puts ok_msg.join(", ") | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment