bin/check-http.rb in sensu-plugins-http-2.8.0 vs bin/check-http.rb in sensu-plugins-http-2.8.1

- old
+ new

@@ -1,6 +1,8 @@ #!/usr/bin/env ruby +# frozen_string_literal: true + # # check-http # # DESCRIPTION: # Takes either a URL or a combination of host/path/port/ssl, and checks for @@ -88,11 +90,11 @@ option :method, short: '-m GET|POST', long: '--method GET|POST|PUT', description: 'Specify a GET, POST, or PUT operation; defaults to GET', - in: %w(GET POST PUT), + in: %w[GET POST PUT], default: 'GET' option :header, short: '-H HEADER', long: '--header HEADER', @@ -243,11 +245,11 @@ Timeout.timeout(config[:timeout]) do acquire_resource end rescue Timeout::Error critical 'Request timed out' - rescue => e + rescue StandardError => e critical "Request error: #{e.message}" end end def acquire_resource @@ -391,14 +393,13 @@ critical(res.code + body) unless config[:response_code] else warning(res.code + body) unless config[:response_code] end - if config[:response_code] - if config[:response_code] == res.code - ok "#{res.code}, #{size} bytes" + body - else - critical res.code + body - end + if config[:response_code] && config[:response_code] == res.code + ok "#{res.code}, #{size} bytes" + body + + else + critical res.code + body end end end