Class: Nagios::Splunk::RestClient

Inherits:
Object
  • Object
show all
Defined in:
lib/nagios/splunk/rest_client.rb

Overview

Rest client which communicates with Splunk via REST API

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(server_url) ⇒ RestClient

parse server url string and set up intance variables example: user:pass@localhost:8089/

Parameters:

  • server_url (String)

    full server url with username and password (RFC 3986)



21
22
23
24
25
26
27
# File 'lib/nagios/splunk/rest_client.rb', line 21

def initialize(server_url)
  uri = URI.parse(server_url)
  @host = uri.host
  @port = uri.port
  @username = uri.user
  @password = uri.password
end

Instance Attribute Details

#tokenObject (readonly)

Returns the value of attribute token.



9
10
11
# File 'lib/nagios/splunk/rest_client.rb', line 9

def token
  @token
end

Class Method Details

.debug(value = nil) ⇒ Object

turn on/off debugging

Parameters:

  • (<True, False>)


13
14
15
16
# File 'lib/nagios/splunk/rest_client.rb', line 13

def self.debug(value = nil)
  @debug = value if value
  @debug
end

Instance Method Details

#get(url) ⇒ Net::HTTPRespose

send HTTP request to the server

Parameters:

  • url (String)

Returns:

  • (Net::HTTPRespose)


32
33
34
35
# File 'lib/nagios/splunk/rest_client.rb', line 32

def get(url)
   unless token
  response = client.request(request(url, token))
end