graylog2-client 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +23 -3
- data/graylog2-client.gemspec +1 -2
- data/lib/graylog2-client/parser.rb +15 -47
- data/lib/graylog2-client/version.rb +1 -1
- data/spec/graylog2-client.rb +1 -0
- data/spec/spec_helper.rb +1 -0
- metadata +15 -25
- data/Gemfile.lock +0 -28
data/README.md
CHANGED
@@ -1,8 +1,10 @@
|
|
1
|
-
|
1
|
+
Graylog2Client
|
2
|
+
==============
|
2
3
|
|
3
4
|
This gem provides a simple interface to search on a graylog server for a given pattern.
|
4
5
|
|
5
|
-
|
6
|
+
Installation
|
7
|
+
------------
|
6
8
|
|
7
9
|
Add this line to your application's Gemfile:
|
8
10
|
|
@@ -16,5 +18,23 @@ Or install it yourself as:
|
|
16
18
|
|
17
19
|
$ gem install graylog2-client
|
18
20
|
|
19
|
-
|
21
|
+
Usage
|
22
|
+
-----
|
20
23
|
|
24
|
+
You will need to set some configurations:
|
25
|
+
|
26
|
+
config = {
|
27
|
+
:user => "theuser",
|
28
|
+
:password => "p4s5w0rd",
|
29
|
+
:url => "http://graylog2.yourcompany.com",
|
30
|
+
:stream_id => "000000000000000000000000"
|
31
|
+
}
|
32
|
+
|
33
|
+
The `stream_id` is the id from the required graylog stream.
|
34
|
+
Get an instance of the Graylog parser passing the configuration:
|
35
|
+
|
36
|
+
graylog = Graylog2Client::Parser.new config
|
37
|
+
|
38
|
+
Get the messages for a given query:
|
39
|
+
|
40
|
+
graylog.messages_for("graylogquery*")
|
data/graylog2-client.gemspec
CHANGED
@@ -1,59 +1,27 @@
|
|
1
1
|
# -*- coding: UTF-8 -*-
|
2
|
+
require "json"
|
3
|
+
|
2
4
|
module Graylog2Client
|
3
5
|
class Parser
|
4
|
-
attr_accessor :
|
6
|
+
attr_accessor :url
|
5
7
|
|
6
8
|
def initialize(options)
|
7
|
-
self.client = HTTPClient.new
|
8
9
|
self.url = options[:url]
|
9
|
-
self.user = options[:user]
|
10
|
-
self.password = options[:password]
|
11
|
-
self.stream_id = options[:stream_id]
|
12
|
-
end
|
13
|
-
|
14
|
-
def login!
|
15
|
-
response = client.get("#{url}/login")
|
16
|
-
doc = Nokogiri::HTML(response.body)
|
17
|
-
token = doc.css("input[name='authenticity_token']").attribute("value").value
|
18
|
-
params = {:login => user, :password => password, :authenticity_token => token}.to_param
|
19
|
-
response = client.post("#{url}/session", :body => params)
|
20
|
-
response.code == 302
|
21
10
|
end
|
22
11
|
|
23
12
|
def messages_for(pattern)
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
}.
|
36
|
-
response = client.get("#{url}/messages", params)
|
37
|
-
doc = Nokogiri::HTML(response.body)
|
38
|
-
doc.css("table.messages tbody tr").map do |message|
|
39
|
-
date, host, severity, facility, message = message.css("td")
|
40
|
-
message.content.strip
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
private
|
45
|
-
|
46
|
-
def to_param(hash_params, namespace=nil)
|
47
|
-
hash_params.map do |key,value|
|
48
|
-
to_param(value, key) if value.is_a(Hash)
|
49
|
-
|
50
|
-
if namespace
|
51
|
-
namespaced = CGI.escape("#{namespace}[#{key.to_s}]")
|
52
|
-
"#{namespaced}=#{CGI.escape(value.to_s)}"
|
53
|
-
else
|
54
|
-
"#{CGI.escape(key.to_s)}=#{CGI.escape(value.to_s)}"
|
55
|
-
end
|
56
|
-
end.join("&")
|
13
|
+
params = JSON.dump({
|
14
|
+
:from => 0, :size => 1000,
|
15
|
+
:query => {
|
16
|
+
:query_string => {
|
17
|
+
:query => pattern,
|
18
|
+
:default_operator => "AND"
|
19
|
+
}
|
20
|
+
}
|
21
|
+
})
|
22
|
+
response = HTTParty.get(url, :body => params)
|
23
|
+
hits = response["hits"]["hits"]
|
24
|
+
hits.map {|m| m["_source"]["message"]}.sort
|
57
25
|
end
|
58
26
|
end
|
59
27
|
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "graylog2-client"
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: graylog2-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,11 +10,11 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2012-02-
|
13
|
+
date: 2012-02-29 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
|
-
name:
|
17
|
-
requirement: &
|
16
|
+
name: httparty
|
17
|
+
requirement: &2151903780 !ruby/object:Gem::Requirement
|
18
18
|
none: false
|
19
19
|
requirements:
|
20
20
|
- - ! '>='
|
@@ -22,21 +22,10 @@ dependencies:
|
|
22
22
|
version: '0'
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
|
-
version_requirements: *
|
26
|
-
- !ruby/object:Gem::Dependency
|
27
|
-
name: nokogiri
|
28
|
-
requirement: &14031320 !ruby/object:Gem::Requirement
|
29
|
-
none: false
|
30
|
-
requirements:
|
31
|
-
- - ! '>='
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '0'
|
34
|
-
type: :runtime
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: *14031320
|
25
|
+
version_requirements: *2151903780
|
37
26
|
- !ruby/object:Gem::Dependency
|
38
27
|
name: rspec
|
39
|
-
requirement: &
|
28
|
+
requirement: &2151902900 !ruby/object:Gem::Requirement
|
40
29
|
none: false
|
41
30
|
requirements:
|
42
31
|
- - ! '>='
|
@@ -44,7 +33,7 @@ dependencies:
|
|
44
33
|
version: '0'
|
45
34
|
type: :development
|
46
35
|
prerelease: false
|
47
|
-
version_requirements: *
|
36
|
+
version_requirements: *2151902900
|
48
37
|
description: A simple gem to search on a graylog2 server
|
49
38
|
email:
|
50
39
|
- pothix@pothix.com
|
@@ -53,15 +42,16 @@ executables: []
|
|
53
42
|
extensions: []
|
54
43
|
extra_rdoc_files: []
|
55
44
|
files:
|
45
|
+
- ./Gemfile
|
56
46
|
- ./graylog2-client.gemspec
|
57
|
-
- ./
|
47
|
+
- ./lib/graylog2-client/parser.rb
|
48
|
+
- ./lib/graylog2-client/version.rb
|
49
|
+
- ./lib/graylog2-client.rb
|
58
50
|
- ./LICENSE
|
59
|
-
- ./README.md
|
60
|
-
- ./Gemfile
|
61
51
|
- ./Rakefile
|
62
|
-
- ./
|
63
|
-
- ./
|
64
|
-
- ./
|
52
|
+
- ./README.md
|
53
|
+
- ./spec/graylog2-client.rb
|
54
|
+
- ./spec/spec_helper.rb
|
65
55
|
homepage: http://github.com/locaweb/graylog2-client
|
66
56
|
licenses: []
|
67
57
|
post_install_message:
|
@@ -82,7 +72,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
82
72
|
version: '0'
|
83
73
|
requirements: []
|
84
74
|
rubyforge_project:
|
85
|
-
rubygems_version: 1.8.
|
75
|
+
rubygems_version: 1.8.10
|
86
76
|
signing_key:
|
87
77
|
specification_version: 3
|
88
78
|
summary: This gem provides a simple interface to search on a graylog server for a
|
data/Gemfile.lock
DELETED
@@ -1,28 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
graylog2-client (0.0.1)
|
5
|
-
httpclient
|
6
|
-
nokogiri
|
7
|
-
|
8
|
-
GEM
|
9
|
-
remote: https://rubygems.org/
|
10
|
-
specs:
|
11
|
-
diff-lcs (1.1.3)
|
12
|
-
httpclient (2.2.4)
|
13
|
-
nokogiri (1.5.0)
|
14
|
-
rspec (2.8.0)
|
15
|
-
rspec-core (~> 2.8.0)
|
16
|
-
rspec-expectations (~> 2.8.0)
|
17
|
-
rspec-mocks (~> 2.8.0)
|
18
|
-
rspec-core (2.8.0)
|
19
|
-
rspec-expectations (2.8.0)
|
20
|
-
diff-lcs (~> 1.1.2)
|
21
|
-
rspec-mocks (2.8.0)
|
22
|
-
|
23
|
-
PLATFORMS
|
24
|
-
ruby
|
25
|
-
|
26
|
-
DEPENDENCIES
|
27
|
-
graylog2-client!
|
28
|
-
rspec
|