lib/zabbixapi/base.rb in zabbixapi-0.1.6.4 vs lib/zabbixapi/base.rb in zabbixapi-0.1.7
- old
+ new
@@ -21,18 +21,19 @@
class ArgumentError < RuntimeError
end
class ZabbixApi
- attr_accessor :debug
+ attr_accessor :debug, :basic_auth
def initialize (api_url, api_user, api_password)
@api_url = api_url
@api_user = api_user
@api_password = api_password
@debug = false # Disable debug by default
+ @basic_auth = false #Disable basic_auth by default
end
def do_request(message)
id = rand 100_000
@@ -51,9 +52,13 @@
end
request = Net::HTTP::Post.new(uri.request_uri)
request.add_field('Content-Type', 'application/json-rpc')
request.body=(message_json)
+
+ if @basic_auth
+ request.basic_auth @api_user, @api_password
+ end
begin
puts "[ZBXAPI] : #{Time.now()} : INFO : Do request. Body => #{request.body}" if @debug
response = http.request(request)
rescue ::SocketError => e