lib/zabbixapi/client.rb in zabbixapi-0.5.0 vs lib/zabbixapi/client.rb in zabbixapi-0.5.1a
- old
+ new
@@ -3,11 +3,11 @@
class ZabbixApi
class Client
def id
- Random.rand(100000)
+ @id = @id + 1
end
def api_version
@version ||= api_request(:method => "apiinfo.version", :params => {})
end
@@ -22,17 +22,18 @@
)
end
def initialize(options = {})
@options = options
- @auth_hash = auth
+ @id = 1
unless ENV['http_proxy'].nil?
@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
+ @auth_hash = auth
end
def message_json(body)
message = {
:method => body[:method],
@@ -50,9 +51,10 @@
http = Net::HTTP.new(uri.host, uri.port)
else
http = Net::HTTP.Proxy(@proxy_host, @proxy_port, @proxy_user, @proxy_pass).new(uri.host, uri.port)
end
request = Net::HTTP::Post.new(uri.request_uri)
+ request.basic_auth @options[:http_user], @options[:http_password] if @options[:http_user]
request.add_field('Content-Type', 'application/json-rpc')
request.body = body
response = http.request(request)
raise "HTTP Error: #{response.code} on #{@options[:url]}" unless response.code == "200"
puts "[DEBUG] Get answer: #{response.body}" if @options[:debug]