bin/check-http-json.rb in sensu-plugins-http-0.2.1 vs bin/check-http-json.rb in sensu-plugins-http-0.3.0
- old
+ new
@@ -71,11 +71,11 @@
end
config[:port] ||= config[:ssl] ? 443 : 80
end
begin
- timeout(config[:timeout]) do
+ Timeout.timeout(config[:timeout]) do
acquire_resource
end
rescue Timeout::Error
critical 'Connection timed out'
rescue => e
@@ -102,15 +102,15 @@
end
http.ca_file = config[:cacert] if config[:cacert]
http.verify_mode = OpenSSL::SSL::VERIFY_NONE if config[:insecure]
end
- if config[:method] == 'POST'
- req = Net::HTTP::Post.new([config[:path], config[:query]].compact.join('?'))
- else
- req = Net::HTTP::Get.new([config[:path], config[:query]].compact.join('?'))
- end
+ req = if config[:method] == 'POST'
+ Net::HTTP::Post.new([config[:path], config[:query]].compact.join('?'))
+ else
+ Net::HTTP::Get.new([config[:path], config[:query]].compact.join('?'))
+ end
if config[:postbody]
post_body = IO.readlines(config[:postbody])
req.body = post_body.join
end
if !config[:user].nil? && !config[:password].nil?
@@ -132,14 +132,14 @@
begin
keys = config[:key].scan(/(?:\\\.|[^.])+/).map { |key| key.gsub(/\\./, '.') }
leaf = keys.reduce(json) do |tree, key|
- fail "could not find key: #{config[:key]}" unless tree.key?(key)
+ raise "could not find key: #{config[:key]}" unless tree.key?(key)
tree[key]
end
- fail "unexpected value for key: '#{config[:value]}' != '#{leaf}'" unless leaf.to_s == config[:value].to_s
+ raise "unexpected value for key: '#{config[:value]}' != '#{leaf}'" unless leaf.to_s == config[:value].to_s
ok "key has expected value: '#{config[:key]}' = '#{config[:value]}'"
rescue => e
critical "key check failed: #{e}"
end