Skip to content

Instantly share code, notes, and snippets.

@crazed
Created September 28, 2012 14:47
Show Gist options
  • Save crazed/3800322 to your computer and use it in GitHub Desktop.
Save crazed/3800322 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'rubygems'
require 'mcollective'
class MCollectiveCheck
NAGIOS_CRITICAL = 2
NAGIOS_WARNING = 1
NAGIOS_OK = 0
include MCollective::RPC
attr_accessor :hosts
def initialize(hosts=[])
@hosts = hosts
end
def run
raise 'invalid host definition, must be an Array' unless @hosts.kind_of?(Array)
options = rpcoptions
options[:timeout] = 1
client = rpcclient('rpcutil', :options => options)
# By specifying the nodes directly, we use direct addressing
# this will cause an error if one of the hosts do not respond
client.discover :nodes => @hosts
client.progress = false
client.ping
if client.stats.noresponsefrom.empty?
puts "OK: #{@hosts.join(', ')} responded properly"
return NAGIOS_OK
else
puts "CRITICAL: No response from hosts: #{client.stats.noresponsefrom.join(', ')}"
return NAGIOS_CRITICAL
end
end
end
def usage
puts "usage: #{$0} host1 [host2 .. hostN]"
exit 1
end
usage if ARGV.size == 0
check = MCollectiveCheck.new(ARGV)
exit check.run
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment