class Object

Constants

CERT_PASS
CERT_PATH

Your client certififcate that grants access to the reverse proxy.

DEFAULT_RESTART_TIMEOUT
INDEX_NAME

Data written to Splunk with the Ruby SDK must be written to a particular index, so we first create an index to write to if it doesn't already exist.

INPUT_NAME

Create an input of kind test1.

JOB_ARGS
QUERY
TEST_PATH

Public Instance Methods

../collection() click to toggle source

Provides a class representing a configuration file.

# File lib/splunk-sdk-ruby/collection/apps.rb, line 21
require_relative '../collection'
../entity() click to toggle source

Provides a class Index to represent indexes on the Splunk server.

# File lib/splunk-sdk-ruby/entity/index.rb, line 21
require_relative '../entity'
ambiguous_entity_reference() click to toggle source

Provides the Collection class, which represents a collection in Splunk.

# File lib/splunk-sdk-ruby/collection.rb, line 21
require_relative 'ambiguous_entity_reference'
main(argv) click to toggle source
# File examples/run_examples.rb, line 30
def main(argv)
  credentials = {
    :host => "localhost",
    :port => 8089,
    :username => "admin",
    :password => "changeme",
  }
  
  parser = OptionParser.new do |op|
    op.on("--host HOSTNAME", String, "Set Splunk host (default: localhost)") do |s|
      credentials[:host] = s
    end

    op.on("--port PORT", Integer, "Set Splunk port (default: 8089)") do |p|
      credentials[:port] = p
    end

    op.on("--username USERNAME", String, "Set username for login (default: admin)") do |s|
      credentials[:username] = s
    end

    op.on("--password PASSWORD", String, "Set password for login (default: changeme)") do |s|
      credentials[:password] = s
    end
  end

  parser.parse!(argv)

  # The examples are all named as 1_something.rb, 2_something.rb in the same
  # directory as this script.
  example_path = File.dirname(File.expand_path(__FILE__))
  example_files = Dir.entries(example_path).
    select() {|s| s.match('^\d_.+\.rb')}.
    map() {|s| File.join(example_path, s)}

  # Add the path to the Splunk SDK for Ruby.
  $LOAD_PATH.push(File.join(File.dirname(example_path), "lib"))

  # Run 
  example_files.each do |p|
    run_example(p, credentials)
  end
end
nokogiri_available?() click to toggle source
# File test/test_helper.rb, line 48
def nokogiri_available?
  begin
    require 'nokogiri'
    return true
  rescue LoadError
    return false
  end
end
read_splunkrc() click to toggle source
# File test/test_helper.rb, line 18
def read_splunkrc
  file = File.new(File.expand_path("~/.splunkrc"))
  options = {
      :host => 'localhost',
      :port => 8089,
      :username => 'admin',
      :password => 'changeme',
      :scheme => 'https',
      :version => '5.0'
  }
  file.readlines.each do |raw_line|
    line = raw_line.strip()
    if line.start_with?("\#") or line.length == 0
      next
    else
      raw_key, raw_value = line.split('=', limit=2)
      key = raw_key.strip().intern
      value = raw_value.strip()

      if key == 'port'
        value = Integer(value)
      end

      options[key] = value
    end
  end

  options
end
run_example(abspath, credentials) click to toggle source
# File examples/run_examples.rb, line 91
def run_example(abspath, credentials)
    handle = File.open(abspath)
    contents = handle.read()
    handle.close()

    credentials.each_pair do |key, value|
      contents.gsub!(Regexp.new(key.inspect + "\s*=>\s*[^,\\n]+"),
                     key.inspect + " => " + value.inspect)
    end
 
    begin
      output = eval_stdout do
        eval(contents)
      end
      puts "SUCCESS: " + abspath
      puts "  stdout was:"
      puts output[0].lines.map() {|s| "    " + s}.join("")
      if output[1] != ""
        puts "  stderr was:"
        puts output[1].lines.map() {|s| "    " + s}.join("")
      end
      puts
    rescue Exception => e
      puts "FAILURE: " + abspath
      puts "  using credentials " + credentials.to_s
      puts "  Error was:"
      puts e.to_s.lines.map() {|s| "    " + s}.join("")
      puts
    end
end
temporary_name() click to toggle source
# File test/test_helper.rb, line 58
def temporary_name
  return "delete-me-" + SecureRandom.uuid()
end
xml_shim() click to toggle source

atomfeed.rb provides an AtomFeed class to parse the Atom XML feeds returned by most of Splunk's endpoints.

# File lib/splunk-sdk-ruby/atomfeed.rb, line 22
require_relative 'xml_shim'