lib/splunk_client/splunk_client.rb in splunk-client-0.8.1 vs lib/splunk_client/splunk_client.rb in splunk-client-0.9.0
- old
+ new
@@ -3,21 +3,23 @@
require 'net/https'
require 'cgi'
require 'rubygems'
require 'nokogiri'
+require 'uri'
require File.expand_path File.join(File.dirname(__FILE__), 'splunk_job')
require File.expand_path File.join(File.dirname(__FILE__), 'splunk_alert')
require File.expand_path File.join(File.dirname(__FILE__), 'splunk_alert_feed')
class SplunkClient
- def initialize(username, password, host, port=8089)
+ def initialize(username, password, host, port=8089, proxy_url = '')
@USER=username; @PASS=password; @HOST=host; @PORT=port
-
+ @PROXY_URI = URI(proxy_url) if proxy_url && !proxy_url.empty?
+
sessionKey = get_session_key
-
+
if (sessionKey == "")
raise SplunkSessionError, 'Session key is invalid. Please check your username, password and host'
else
@SESSION_KEY = { 'authorization' => "Splunk #{sessionKey}" }
end
@@ -68,10 +70,14 @@
end
private ###############################################################################
def splunk_http_request
- http = Net::HTTP.new(@HOST, @PORT)
+ if @PROXY_URI
+ http = Net::HTTP.new(@HOST, @PORT, @PROXY_URI.host, @PROXY_URI.port)
+ else
+ http = Net::HTTP.new(@HOST, @PORT)
+ end
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
return http
end