graylog2-client 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in graylog2-client.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,28 @@
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
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 PotHix
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,20 @@
1
+ # Graylog2::Client
2
+
3
+ This gem provides a simple interface to search on a graylog server for a given pattern.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'graylog2-client'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install graylog2-client
18
+
19
+ ## Usage
20
+
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,20 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/graylog2-client/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.name = "graylog2-client"
6
+ gem.authors = ["Willian Molinari (a.k.a PotHix)", "Thiago Morello"]
7
+ gem.email = ["pothix@pothix.com", "morellon@gmail.com"]
8
+ gem.description = %q{A simple gem to search on a graylog2 server}
9
+ gem.summary = %q{This gem provides a simple interface to search on a graylog server for a given pattern}
10
+ gem.homepage = "http://github.com/locaweb/graylog2-client"
11
+
12
+ gem.files = Dir["./**/*"].reject {|file| file =~ /\.git|pkg/}
13
+ gem.require_paths = ["lib"]
14
+
15
+ gem.version = Graylog2Client::VERSION
16
+
17
+ gem.add_dependency "httpclient"
18
+ gem.add_dependency "nokogiri"
19
+ gem.add_development_dependency "rspec"
20
+ end
@@ -0,0 +1,3 @@
1
+ # -*- coding: UTF-8 -*-
2
+ require "graylog2-client/version"
3
+ require "graylog2-client/parser"
@@ -0,0 +1,59 @@
1
+ # -*- coding: UTF-8 -*-
2
+ module Graylog2Client
3
+ class Parser
4
+ attr_accessor :client, :url, :user, :password, :stream_id
5
+
6
+ def initialize(options)
7
+ self.client = HTTPClient.new
8
+ 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
+ end
22
+
23
+ def messages_for(pattern)
24
+ login!
25
+
26
+ params = {
27
+ :filters => {
28
+ :message => pattern,
29
+ :date => "",
30
+ :facility => "",
31
+ :severity => "",
32
+ :host => ""
33
+ },
34
+ :stream_id => stream_id
35
+ }.to_param
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("&")
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,4 @@
1
+ # -*- coding: UTF-8 -*-
2
+ module Graylog2Client
3
+ VERSION = "0.0.1"
4
+ end
metadata ADDED
@@ -0,0 +1,90 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: graylog2-client
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Willian Molinari (a.k.a PotHix)
9
+ - Thiago Morello
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2012-02-16 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: httpclient
17
+ requirement: &14032680 !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
22
+ version: '0'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: *14032680
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
37
+ - !ruby/object:Gem::Dependency
38
+ name: rspec
39
+ requirement: &14030220 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ! '>='
43
+ - !ruby/object:Gem::Version
44
+ version: '0'
45
+ type: :development
46
+ prerelease: false
47
+ version_requirements: *14030220
48
+ description: A simple gem to search on a graylog2 server
49
+ email:
50
+ - pothix@pothix.com
51
+ - morellon@gmail.com
52
+ executables: []
53
+ extensions: []
54
+ extra_rdoc_files: []
55
+ files:
56
+ - ./graylog2-client.gemspec
57
+ - ./Gemfile.lock
58
+ - ./LICENSE
59
+ - ./README.md
60
+ - ./Gemfile
61
+ - ./Rakefile
62
+ - ./lib/graylog2-client.rb
63
+ - ./lib/graylog2-client/version.rb
64
+ - ./lib/graylog2-client/parser.rb
65
+ homepage: http://github.com/locaweb/graylog2-client
66
+ licenses: []
67
+ post_install_message:
68
+ rdoc_options: []
69
+ require_paths:
70
+ - lib
71
+ required_ruby_version: !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ required_rubygems_version: !ruby/object:Gem::Requirement
78
+ none: false
79
+ requirements:
80
+ - - ! '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ requirements: []
84
+ rubyforge_project:
85
+ rubygems_version: 1.8.16
86
+ signing_key:
87
+ specification_version: 3
88
+ summary: This gem provides a simple interface to search on a graylog server for a
89
+ given pattern
90
+ test_files: []