bin/check-jenkins-health.rb in sensu-plugins-jenkins-1.6.0 vs bin/check-jenkins-health.rb in sensu-plugins-jenkins-1.6.1

- old
+ new

@@ -73,22 +73,45 @@ long: '--timeout SECS', description: 'Request timeout in seconds', proc: proc(&:to_i), default: 5 + option :verbose, + short: '-v', + long: '--verbose', + boolean: true, + description: 'Return more verbose errors', + default: false + def run https ||= config[:https] ? 'https' : 'http' testurl = "#{https}://#{config[:server]}:#{config[:port]}#{config[:uri]}" - r = if config[:https] && config[:insecure] - RestClient::Resource.new(testurl, timeout: config[:timeout], verify_ssl: false).get - elsif config[:https] - RestClient::Resource.new(testurl, timeout: config[:timeout], verify_ssl: true).get - else - RestClient::Resource.new(testurl, timeout: config[:timeout]).get - end - - if [200, 500].include? r.code + begin + r = if config[:https] && config[:insecure] + RestClient::Resource.new(testurl, timeout: config[:timeout], verify_ssl: false) + elsif config[:https] + RestClient::Resource.new(testurl, timeout: config[:timeout], verify_ssl: true) + else + RestClient::Resource.new(testurl, timeout: config[:timeout]) + end + if config[:verbose] + r.get + else + r.get { |response| response } + end + rescue RestClient::SSLCertificateNotVerified => e + critical "ssl verification failed: #{e.response}" + rescue RestClient::ServerBrokeConnection + critical "server broke the connection: #{e}" + rescue RestClient::RequestFailed => e + critical "request failed: #{e.response}" + rescue RestClient::ExceptionWithResponse => e + critical "failed to #{e.response}" + end + # if you have a 500 it will only reach here if you are not specifying `--verbose` + # as it will be caught by the rescue above + if [200, 500].include?(r.code) healthchecks = JSON.parse(r) healthchecks.each do |healthcheck, healthcheck_hash_value| if healthcheck_hash_value['healthy'] != true critical "Jenkins health check '#{healthcheck}' reported unhealthy state. Message: #{healthcheck_hash_value['message']}" end