Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'net/https'
- require 'rubygems'
- require 'hpricot'
- class SplunkClient
- HOST = 'localhost'
- PORT = 8089
- USER = 'admin'
- PASSWORD = 'trekbiker'
- def splunk_ssl_get_request(path, headers = nil)
- http = Net::HTTP.new(HOST, PORT)
- http.use_ssl = true
- http.verify_mode = OpenSSL::SSL::VERIFY_NONE
- http.get(path, headers).body
- end
- def splunk_ssl_post_request(path, data = nil, headers = nil)
- http = Net::HTTP.new(HOST, PORT)
- http.use_ssl = true
- http.verify_mode = OpenSSL::SSL::VERIFY_NONE
- http.post(path, data, headers).body
- end
- def session_key
- @session_key ||= load_session_key
- end
- def load_session_key
- doc = Hpricot(splunk_ssl_post_request("/services/auth/login", "username=#{USER}&password=#{PASSWORD}"))
- (doc/"//sessionkey").inner_html
- end
- def list_users_logged_in
- xml = splunk_ssl_get_request("/services/authentication/httpauth-tokens", {'authorization' => "Splunk #{session_key}"})
- puts xml
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment