lib/zabbix/client/client.rb in zabbix-client-0.0.2 vs lib/zabbix/client/client.rb in zabbix-client-0.0.3
- old
+ new
@@ -4,10 +4,15 @@
JSON_RPC_REQUEST_ID = 1
LOGIN_METHOD = 'user.login'
LOGOUT_METHOD = 'user.logout'
+ UNAUTHENTICATED_METHODS = [
+ 'user.login',
+ 'apiinfo.version',
+ ]
+
DEFAULT_HEADERS = {
'Content-Type' => 'application/json-rpc'
}
def initialize(prefix, client)
@@ -52,10 +57,13 @@
:method => method,
:params => params,
:id => JSON_RPC_REQUEST_ID,
}.merge(options)
- body[:auth] = @client.auth if @client.auth
+ if @client.auth and not UNAUTHENTICATED_METHODS.include?(method)
+ body[:auth] = @client.auth
+ end
+
body = JSON.dump(body)
proxy_user = @client.options[:proxy_user]
proxy_password = @client.options[:proxy_password]
http = Net::HTTP.Proxy(nil, nil).new(@client.url.host, @client.url.port)