bin/check-jenkins-health.rb in sensu-plugins-jenkins-1.1.0 vs bin/check-jenkins-health.rb in sensu-plugins-jenkins-1.2.0

- old
+ new

@@ -59,25 +59,32 @@ long: '--https', boolean: true, description: 'Enabling https connections', default: false + option :timeout, + short: '-t SECS', + long: '--timeout SECS', + description: 'Request timeout in seconds', + proc: proc(&:to_i), + default: 5 + def run https ||= config[:https] ? 'https' : 'http' - r = RestClient::Resource.new("#{https}://#{config[:server]}:#{config[:port]}#{config[:uri]}", timeout: 5).get - if r.code == 200 + r = RestClient::Resource.new("#{https}://#{config[:server]}:#{config[:port]}#{config[:uri]}", timeout: config[:timeout]).get + if [200, 500].include? r.code healthchecks = JSON.parse(r) - healthchecks.each do |_, healthcheck_hash_value| + healthchecks.each do |healthcheck, healthcheck_hash_value| if healthcheck_hash_value['healthy'] != true - critical 'Jenkins Health Parameters not OK' + critical "Jenkins health check '#{healthcheck}' reported unhealthy state. Message: #{healthcheck_hash_value['message']}" end end ok 'Jenkins Health Parameters are OK' else - critical 'Jenkins Service is not responding' + critical "Jenkins Service is replying with status code #{r.code}. Body: #{r.body}" end - rescue Errno::ECONNREFUSED - critical 'Jenkins Service is not responding' - rescue RestClient::RequestTimeout - critical 'Jenkins Service Connection timed out' + rescue Errno::ECONNREFUSED => e + critical "Jenkins Service is not responding: #{e}" + rescue RestClient::RequestTimeout => e + critical "Jenkins Service Connection timed out after #{config[:timeout]} seconds: #{e}" end end