1class MCollective::Application::Nrpe<MCollective::Application 2 description "Client to the Nagios Remote Plugin Execution system" 3 usage "Usage: nrpe <check_name>" 4 5 def post_option_parser(configuration) 6 configuration[:command] = ARGV.shift if ARGV.size > 0 7 end 8 9 def validate_configuration(configuration) 10 raise "Please specify a check name" unless configuration.include?(:command) 11 end 12 13 def main 14 nrpe = rpcclient("nrpe") 15 16 nrpe_results = nrpe.runcommand(:command => configuration[:command]) 17 18 nrpe_results.each do |result| 19 if result[:statuscode] == 0 20 exitcode = Integer(result[:data][:exitcode]) rescue 3 21 else 22 exitcode = 1 23 end 24 25 if nrpe.verbose 26 printf("%-40s status=%s\n", result[:sender], result[:statusmsg]) 27 printf(" %-40s\n\n", result[:data][:output]) 28 else 29 if [1,2,3].include?(exitcode) 30 printf("%-40s status=%s\n", result[:sender], result[:statusmsg]) 31 printf(" %-40s\n\n", result[:data][:output]) if result[:data][:output] 32 end 33 end 34 end 35 36 printrpcstats :summarize => true, :caption => "%s NRPE results" % configuration[:command] 37 end 38end 39