Class: Splunk::Splunk
- Inherits:
-
Object
- Object
- Splunk::Splunk
- Defined in:
- lib/splunk.rb
Instance Method Summary collapse
-
#initialize(splunk_uri, user, password) ⇒ Splunk
constructor
A new instance of Splunk.
- #search(search, *data) ⇒ Object
Constructor Details
#initialize(splunk_uri, user, password) ⇒ Splunk
Returns a new instance of Splunk.
12 13 14 15 16 |
# File 'lib/splunk.rb', line 12 def initialize(splunk_uri,user,password) @uri = splunk_uri res = Nokogiri::XML(api_request("#{@uri}/auth/login", 'username' => user, 'password' => password).body) @session_key = res.xpath('/response/sessionKey')[0].content end |
Instance Method Details
#search(search, *data) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/splunk.rb', line 18 def search(search, *data) search = "search #{search}" data[0]["search"] = search xml = Nori.parse api_request("#{@uri}/search/jobs/export", *data).body raise "Search failed: #{xml["response"]["messages"]["msg"]}" if xml.has_key? "response" ret = Array.new if xml["results"]["result"] xml["results"]["result"].each do |result| rres = Hash.new result["field"].each do |field| if field.has_key? "@k" case field["@k"] when '_raw' rres[:"#{field["@k"]}"] = field["v"].to_s.gsub /<sgh="1">([^<]*)<\/sg>/, '\1' when '_si' # FIXME do nothing - we don't handle this yet else case field["@k"] when '_time' rres[:"#{field["@k"]}"] = Time.parse field["value"]["text"].to_s else if field["value"].instance_of? Array rres[:"#{field["@k"]}"] = Array.new unless rres[:"#{field["@k"]}"] field["value"].each { |value| rres[:"#{field["@k"]}"] << value["text"].to_s } else rres[:"#{field["@k"]}"] = field["value"]["text"].to_s end end end end end ret << rres end end ret end |