bin/check-http.rb in sensu-plugins-http-2.6.0 vs bin/check-http.rb in sensu-plugins-http-2.7.0

- old
+ new

@@ -26,10 +26,14 @@ # check-http.rb -u https://my.site.com/redirect --response-code 301 -r # # Use a proxy to check a URL # check-http.rb -u https://www.google.com --proxy-url http://my.proxy.com:3128 # +# Use a proxy with username and password to check a URL +# NOTE: Use 'check token substition' to avoid credentials leakage! +# check-http.rb -u https://www.google.com --proxy-url http://a_user:a_pass@my.proxy.com:3128 +# # Check something with needing to set multiple headers # check-http.rb -u https://www.google.com --header 'Origin: ma.local.box, SomeRandomHeader: foo' # # Check something that requires a POST with json data # check-http.rb -u https://httpbin.org/post --method POST --header 'Content-type: application/json' --body '{"foo": "bar"}' @@ -38,10 +42,11 @@ # LICENSE: # Copyright 2011 Sonian, Inc <chefs@sonian.net> # Updated by Lewis Preson 2012 to accept basic auth credentials # Updated by SweetSpot 2012 to require specified redirect # Updated by Chris Armstrong 2013 to accept multiple headers +# Updated by Mark Clarkson 2018 to accept proxy auth credentials # Released under the same terms as Sensu (the MIT license); see LICENSE # for details. # require 'sensu-plugins-http' @@ -253,10 +258,14 @@ elsif config[:proxy_url] proxy_uri = URI.parse(config[:proxy_url]) if proxy_uri.host.nil? unknown 'Invalid proxy url specified' end - http = Net::HTTP.new(config[:host], config[:port], proxy_uri.host, proxy_uri.port) + http = if proxy_uri.user && proxy_uri.password + Net::HTTP.new(config[:host], config[:port], proxy_uri.host, proxy_uri.port, proxy_uri.user, proxy_uri.password) + else + Net::HTTP.new(config[:host], config[:port], proxy_uri.host, proxy_uri.port) + end else http = Net::HTTP.new(config[:host], config[:port]) end http.read_timeout = config[:timeout] http.open_timeout = config[:timeout]