Class: Rsplunk::Client

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Search
Defined in:
lib/rsplunk/client.rb

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Methods included from Search

#create_job, #delete_job, #job_results, #list_jobs

Constructor Details

- (Client) initialize(options = {})

Create a Splunk session using basic_auth parameters.

Example: client = Rsplunk::Client.new(:username => 'your_username', :password => 'your_password')



16
17
18
19
# File 'lib/rsplunk/client.rb', line 16

def initialize(options={})
  @user  = options[:username]
  @pass  = options[:password]
end

Instance Attribute Details

- (Object) pass

Returns the value of attribute pass



10
11
12
# File 'lib/rsplunk/client.rb', line 10

def pass
  @pass
end

- (Object) user

Returns the value of attribute user



10
11
12
# File 'lib/rsplunk/client.rb', line 10

def user
  @user
end

Instance Method Details

- (Object) connection

Sets up the initial connection to your Splunk server



22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/rsplunk/client.rb', line 22

def connection
  params = {}
  params[:username] = @user if @user
  params[:password] = @pass if @pass
  @connection ||= Faraday::Connection.new(:url => api_url, :ssl => { :verify => false },
                                          :params => params, :headers => default_headers) do |builder|
    builder.request  :url_encoded
    builder.response :xml
    builder.adapter  :net_http
    builder.basic_auth(@user, @pass)
  end
end