Class: Graylog2Client::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/graylog2-client/parser.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Parser

Returns a new instance of Parser.



9
10
11
# File 'lib/graylog2-client/parser.rb', line 9

def initialize(options)
  self.url = options[:url]
end

Instance Attribute Details

#urlObject

Returns the value of attribute url.



7
8
9
# File 'lib/graylog2-client/parser.rb', line 7

def url
  @url
end

Instance Method Details

#messages_for(pattern) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/graylog2-client/parser.rb', line 13

def messages_for(pattern)
  params = JSON.dump({
    :from => 0, :size => 1000,
    :query => {
      :query_string => {
        :query => pattern,
        :default_operator => "AND"
      }
    }
  })
  response = HTTParty.get(url, :body => params)
  hits = response["hits"]["hits"]

  hits.sort_by! {|m| m["_source"]["created_at"]}
  hits.map {|m| m["_source"]["message"]}
end