Class: SplunkDataReader

Inherits:
Object show all
Defined in:
lib/data_services/splunk_data_reader.rb

Instance Method Summary collapse

Constructor Details

#initializeSplunkDataReader

Returns a new instance of SplunkDataReader.



35
36
37
38
39
40
41
42
43
44
# File 'lib/data_services/splunk_data_reader.rb', line 35

def initialize
  config = {:scheme => :https,
            :host => "chrcnc-hnav-splunksearchhead-01.os.vap.rr.com",
            :port => 8089,
            :username => "figaro",
            :password => "figaro"
  }

  @service = Splunk::connect(config)
end

Instance Method Details

#read_from_splunkObject



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/data_services/splunk_data_reader.rb', line 46

def read_from_splunk
  job = @service.create_search("search index=figaro",
                               :earliest_time => "-30d",
                               :latest_time => "now")

  while !job.is_ready?()
    sleep(0.1)
  end

  while !job.is_done?()
    sleep(0.1)
  end

  stream = job.results(:count => 1, :offset => 0)
# Or: stream = job.events(:count => 3, :offset => 0)
  results = Splunk::ResultsReader.new(stream)
  results.each do |result|
    puts result["_raw"]
  end
end