express42 / zabbixapi

Ruby wrapper to Zabbix API
MIT License
132 stars 128 forks source link

options[:no_proxy] has no value #79

Closed Valiron closed 3 years ago

Valiron commented 7 years ago

When I tried to use the no_proxy option to bypass the proxy, it didn't delivered it correctly. It doesn't appear in the initialize function in the client.rb

# Initializes a new Client object
    #
    # @param options [Hash]
    # @return [ZabbixApi::Client]
def initialize(options = {})

      @options = options
      if !ENV['http_proxy'].nil? && options[:no_proxy] != true
        @proxy_uri = URI.parse(ENV['http_proxy'])
        @proxy_host = @proxy_uri.host
        @proxy_port = @proxy_uri.port
        @proxy_user, @proxy_pass = @proxy_uri.userinfo.split(/:/) if @proxy_uri.userinfo
      end
      unless api_version =~ /(2\.4|3\.[02])\.\d+/
        raise ApiError.new("Zabbix API version: #{api_version} is not support by this version of zabbixapi")
      end
      @auth_hash = auth
    end
jrbeilke commented 7 years ago

Have an example of the code you're using and the response?

no_proxy is the default so you shouldn't need to pass that param unless you're needing to deal with a proxy in front of Zabbix

pu239ppy commented 7 years ago

I am also having this isssue

Per Net::Http documentation

Net::HTTP will automatically create a proxy from the http_proxy environment variable if it is present. To disable use of http_proxy, pass nil for the proxy address.

so it seem that if condition

!ENV['http_proxy'].nil? && options[:no_proxy] != true

evaluates to false you still need to tell Net::HTTP not to use a proxy, so what you really want is

      if @proxy_uri
        http = Net::HTTP.Proxy(@proxy_host, @proxy_port, @proxy_user, @proxy_pass).new(uri.host, uri.port)
      else
        http = Net::HTTP.new(uri.host, uri.port, nil)
      end

Also as @proxy_uri is a derived value perhaps you still want :no_proxy to drive this behavior