logstash-input-irc 1.0.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 40fc37ec1f7ce6a5c7ca80b9c9c6ba2d6eb0ce3a
4
- data.tar.gz: dcfd76081bb32869f2fa56fa4d00d43d2f7c8633
3
+ metadata.gz: cace7a5e1b01c9e4fa461ea71fed7fd49d8c86ae
4
+ data.tar.gz: 0c6ba7cf5fc467a41c8a1cf241e070e1ced10588
5
5
  SHA512:
6
- metadata.gz: 8fda29ba672bc0caa64e481ebbd54e69420047e308e07c4cb8d2c80e87a0bb0b3647e9005e6ee9a4f7ad8b3e9411f3263cef83cf78450796c321ed63c580d848
7
- data.tar.gz: b0bece388946e04d39c5d3d2fd9802df2423f93b508cc1e59d761451bc022d3c5860a3ec6353eb070947ca3ccd36277fe299c4e03e09352654aaaad6d89f3d34
6
+ metadata.gz: 0d674f160aff5a3ffa81075d5f2be4df25beb51c3f6a4ff98ebe9038a90f85347bf431c073dce673f9f32c93ac87a018e3852aa11ea1ff2cc1a764c75f6e09fa
7
+ data.tar.gz: c840297ce74132b6af4b48cb7fd43fca6b0f6cba136c12b784c186f348e933ecba0d859266de9ea8f42d61a3a482aa0d6911ae44cdc36dc2601e6a16276f4b40
data/CHANGELOG.md CHANGED
@@ -0,0 +1,6 @@
1
+ # 1.1.0
2
+ - Add basic tests for the project
3
+ - Refactor the plugin to include the option to add an option to inject
4
+ a dummy bot.
5
+ - Refactor the plugin to have a cleaner shutdown methodology, so the
6
+ thread is not stuck waiting in the queue if there is no reason.
data/README.md CHANGED
@@ -1,15 +1,15 @@
1
1
  # Logstash Plugin
2
2
 
3
- This is a plugin for [Logstash](https://github.com/elasticsearch/logstash).
3
+ This is a plugin for [Logstash](https://github.com/elastic/logstash).
4
4
 
5
5
  It is fully free and fully open source. The license is Apache 2.0, meaning you are pretty much free to use it however you want in whatever way.
6
6
 
7
7
  ## Documentation
8
8
 
9
- Logstash provides infrastructure to automatically generate documentation for this plugin. We use the asciidoc format to write documentation so any comments in the source code will be first converted into asciidoc and then into html. All plugin documentation are placed under one [central location](http://www.elasticsearch.org/guide/en/logstash/current/).
9
+ Logstash provides infrastructure to automatically generate documentation for this plugin. We use the asciidoc format to write documentation so any comments in the source code will be first converted into asciidoc and then into html. All plugin documentation are placed under one [central location](http://www.elastic.co/guide/en/logstash/current/).
10
10
 
11
11
  - For formatting code or config example, you can use the asciidoc `[source,ruby]` directive
12
- - For more asciidoc formatting tips, see the excellent reference here https://github.com/elasticsearch/docs#asciidoc-guide
12
+ - For more asciidoc formatting tips, see the excellent reference here https://github.com/elastic/docs#asciidoc-guide
13
13
 
14
14
  ## Need Help?
15
15
 
@@ -83,4 +83,4 @@ Programming is not a required skill. Whatever you've seen about open source and
83
83
 
84
84
  It is more important to the community that you are able to contribute.
85
85
 
86
- For more information about contributing, see the [CONTRIBUTING](https://github.com/elasticsearch/logstash/blob/master/CONTRIBUTING.md) file.
86
+ For more information about contributing, see the [CONTRIBUTING](https://github.com/elastic/logstash/blob/master/CONTRIBUTING.md) file.
@@ -2,7 +2,8 @@
2
2
  require "logstash/inputs/base"
3
3
  require "logstash/namespace"
4
4
  require "thread"
5
-
5
+ require "stud/task"
6
+ require "stud/interval"
6
7
  # Read events from an IRC Server.
7
8
  #
8
9
  class LogStash::Inputs::Irc < LogStash::Inputs::Base
@@ -52,6 +53,16 @@ class LogStash::Inputs::Irc < LogStash::Inputs::Base
52
53
  config :channels, :validate => :array, :required => true
53
54
 
54
55
  public
56
+
57
+ def inject_bot(bot)
58
+ @bot = bot
59
+ self
60
+ end
61
+
62
+ def bot
63
+ @bot
64
+ end
65
+
55
66
  def register
56
67
  require "cinch"
57
68
  @user_stats = Hash.new
@@ -59,7 +70,7 @@ class LogStash::Inputs::Irc < LogStash::Inputs::Base
59
70
  @catch_all = true if @get_stats
60
71
  @logger.info("Connecting to irc server", :host => @host, :port => @port, :nick => @nick, :channels => @channels)
61
72
 
62
- @bot = Cinch::Bot.new
73
+ @bot ||= Cinch::Bot.new
63
74
  @bot.loggers.clear
64
75
  @bot.configure do |c|
65
76
  c.server = @host
@@ -77,29 +88,34 @@ class LogStash::Inputs::Irc < LogStash::Inputs::Base
77
88
  queue << m
78
89
  end
79
90
  else
80
- @bot.on :channel do |m|
81
- queue << m
82
- end
91
+ @bot.on :channel do |m|
92
+ queue << m
93
+ end
83
94
  end
84
-
85
95
  end # def register
86
96
 
87
97
  public
88
98
  def run(output_queue)
89
99
  @bot_thread = Stud::Task.new(@bot) do |bot|
90
- bot.start
100
+ bot.start
91
101
  end
92
102
  if @get_stats
93
103
  @request_names_thread = Stud::Task.new do
94
- loop do
95
- sleep (@stats_interval * 60)
104
+ while !stop?
105
+ Stud.stoppable_sleep (@stats_interval * 60) do
106
+ stop?
107
+ end
96
108
  request_names
97
109
  end
98
110
  end
99
111
  end
100
- loop do
101
- msg = @irc_queue.pop
102
- handle_response(msg, output_queue)
112
+ while !stop?
113
+ begin
114
+ msg = @irc_queue.pop(true)
115
+ handle_response(msg, output_queue)
116
+ rescue ThreadError
117
+ # Empty queue
118
+ end
103
119
  end
104
120
  end # def run
105
121
 
@@ -150,8 +166,8 @@ class LogStash::Inputs::Irc < LogStash::Inputs::Base
150
166
  end
151
167
  end
152
168
 
153
- def teardown
154
- @request_names_thread#stop!
155
- @bot_thread#stop!
169
+ def stop
170
+ @request_names_thread.stop! if @request_names_thread
171
+ @bot_thread.stop!
156
172
  end
157
173
  end # class LogStash::Inputs::Irc
@@ -1,7 +1,7 @@
1
1
  Gem::Specification.new do |s|
2
2
 
3
3
  s.name = 'logstash-input-irc'
4
- s.version = '1.0.0'
4
+ s.version = '2.0.0'
5
5
  s.licenses = ['Apache License (2.0)']
6
6
  s.summary = "Read events from an IRC Server."
7
7
  s.description = "This gem is a logstash plugin required to be installed on top of the Logstash core pipeline using $LS_HOME/bin/plugin install gemname. This gem is not a stand-alone program"
@@ -11,7 +11,7 @@ Gem::Specification.new do |s|
11
11
  s.require_paths = ["lib"]
12
12
 
13
13
  # Files
14
- s.files = `git ls-files`.split($\)+::Dir.glob('vendor/*')
14
+ s.files = Dir['lib/**/*','spec/**/*','vendor/**/*','*.gemspec','*.md','CONTRIBUTORS','Gemfile','LICENSE','NOTICE.TXT']
15
15
 
16
16
  # Tests
17
17
  s.test_files = s.files.grep(%r{^(test|spec|features)/})
@@ -20,8 +20,8 @@ Gem::Specification.new do |s|
20
20
  s.metadata = { "logstash_plugin" => "true", "logstash_group" => "input" }
21
21
 
22
22
  # Gem dependencies
23
- s.add_runtime_dependency "logstash-core", '>= 1.4.0', '< 2.0.0'
24
-
23
+ s.add_runtime_dependency "logstash-core", "~> 2.0.0.snapshot"
24
+ s.add_runtime_dependency 'stud', '~> 0.0.22'
25
25
  s.add_runtime_dependency 'logstash-codec-plain'
26
26
  s.add_runtime_dependency 'cinch'
27
27
 
@@ -1,3 +1,78 @@
1
1
  # encoding: utf-8
2
- require "logstash/devutils/rspec/spec_helper"
3
- require 'logstash/inputs/irc'
2
+ require_relative "../spec_helper"
3
+ require "logstash/plugin"
4
+ require "logstash/event"
5
+ require "cinch"
6
+
7
+ describe LogStash::Inputs::Irc do
8
+
9
+ let(:properties) { {:name => "foo" } }
10
+ let(:event) { LogStash::Event.new(properties) }
11
+
12
+ let(:host) { "irc.freenode.org" }
13
+ let(:channels) { ["foo", "bar"] }
14
+
15
+ it "should register without errors" do
16
+ plugin = LogStash::Plugin.lookup("input", "irc").new({ "host" => host, "channels" => channels })
17
+ expect { plugin.register }.to_not raise_error
18
+ end
19
+
20
+ context "when stopping the plugin" do
21
+ it_behaves_like "an interruptible input plugin" do
22
+ let(:host) { "irc.freenode.org" }
23
+ let(:channels) { ["foo", "bar"] }
24
+ let(:config) { { "host" => host, "channels" => channels, "get_stats" => true } }
25
+ end
26
+ end
27
+
28
+ describe "receive" do
29
+
30
+ let(:config) { { "host" => host, "channels" => channels } }
31
+ subject { LogStash::Inputs::Irc.new(config) }
32
+
33
+ let(:msg) { double("message") }
34
+ let(:user) { double("user") }
35
+
36
+ before(:each) do
37
+ allow(msg).to receive(:message).and_return("message")
38
+ allow(msg).to receive(:command).and_return("command")
39
+ allow(user).to receive(:host).and_return("host")
40
+ allow(user).to receive(:nick).and_return("nick")
41
+ allow(msg).to receive(:user).and_return(user)
42
+ allow(msg).to receive(:prefix).and_return("prefix")
43
+ allow(msg).to receive(:channel).and_return("channel")
44
+
45
+ subject.inject_bot(bot).register
46
+ end
47
+
48
+ let(:bot) { Cinch::Bot.new }
49
+ let(:channel) { bot.handlers.find(:channel).first }
50
+ let(:nevents) { 1 }
51
+
52
+ let(:events) do
53
+ input(subject) do |queue|
54
+ nevents.times do
55
+ channel.call(msg, [], [])
56
+ end
57
+ result = nevents.times.inject([]) do |acc|
58
+ acc << queue.pop
59
+ end
60
+ result
61
+ end
62
+ end
63
+
64
+ let(:event) { events.first }
65
+
66
+ it "receive events from a channel" do
67
+ expect(event["channel"]).to eq("channel")
68
+ end
69
+
70
+ it "receive events with a command" do
71
+ expect(event["command"]).to eq("command")
72
+ end
73
+
74
+ it "receive events with nick information" do
75
+ expect(event["nick"]).to eq("nick")
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,24 @@
1
+ # encoding: utf-8
2
+ require "logstash/devutils/rspec/spec_helper"
3
+ require 'logstash/inputs/irc'
4
+
5
+ module IrcHelpers
6
+
7
+ def input(plugin, &block)
8
+ queue = Queue.new
9
+
10
+ input_thread = Thread.new do
11
+ plugin.run(queue)
12
+ end
13
+ result = block.call(queue)
14
+
15
+ plugin.do_stop
16
+ input_thread.join
17
+ result
18
+ end
19
+
20
+ end
21
+
22
+ RSpec.configure do |c|
23
+ c.include IrcHelpers
24
+ end
metadata CHANGED
@@ -1,94 +1,101 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logstash-input-irc
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Elastic
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-06-24 00:00:00.000000000 Z
11
+ date: 2015-09-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - ~>
17
+ - !ruby/object:Gem::Version
18
+ version: 2.0.0.snapshot
14
19
  name: logstash-core
20
+ prerelease: false
21
+ type: :runtime
15
22
  version_requirements: !ruby/object:Gem::Requirement
16
23
  requirements:
17
- - - '>='
24
+ - - ~>
18
25
  - !ruby/object:Gem::Version
19
- version: 1.4.0
20
- - - <
21
- - !ruby/object:Gem::Version
22
- version: 2.0.0
26
+ version: 2.0.0.snapshot
27
+ - !ruby/object:Gem::Dependency
23
28
  requirement: !ruby/object:Gem::Requirement
24
29
  requirements:
25
- - - '>='
26
- - !ruby/object:Gem::Version
27
- version: 1.4.0
28
- - - <
30
+ - - ~>
29
31
  - !ruby/object:Gem::Version
30
- version: 2.0.0
32
+ version: 0.0.22
33
+ name: stud
31
34
  prerelease: false
32
35
  type: :runtime
33
- - !ruby/object:Gem::Dependency
34
- name: logstash-codec-plain
35
36
  version_requirements: !ruby/object:Gem::Requirement
36
37
  requirements:
37
- - - '>='
38
+ - - ~>
38
39
  - !ruby/object:Gem::Version
39
- version: '0'
40
+ version: 0.0.22
41
+ - !ruby/object:Gem::Dependency
40
42
  requirement: !ruby/object:Gem::Requirement
41
43
  requirements:
42
44
  - - '>='
43
45
  - !ruby/object:Gem::Version
44
46
  version: '0'
47
+ name: logstash-codec-plain
45
48
  prerelease: false
46
49
  type: :runtime
47
- - !ruby/object:Gem::Dependency
48
- name: cinch
49
50
  version_requirements: !ruby/object:Gem::Requirement
50
51
  requirements:
51
52
  - - '>='
52
53
  - !ruby/object:Gem::Version
53
54
  version: '0'
55
+ - !ruby/object:Gem::Dependency
54
56
  requirement: !ruby/object:Gem::Requirement
55
57
  requirements:
56
58
  - - '>='
57
59
  - !ruby/object:Gem::Version
58
60
  version: '0'
61
+ name: cinch
59
62
  prerelease: false
60
63
  type: :runtime
61
- - !ruby/object:Gem::Dependency
62
- name: logstash-devutils
63
64
  version_requirements: !ruby/object:Gem::Requirement
64
65
  requirements:
65
66
  - - '>='
66
67
  - !ruby/object:Gem::Version
67
68
  version: '0'
69
+ - !ruby/object:Gem::Dependency
68
70
  requirement: !ruby/object:Gem::Requirement
69
71
  requirements:
70
72
  - - '>='
71
73
  - !ruby/object:Gem::Version
72
74
  version: '0'
75
+ name: logstash-devutils
73
76
  prerelease: false
74
77
  type: :development
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
75
83
  description: This gem is a logstash plugin required to be installed on top of the Logstash core pipeline using $LS_HOME/bin/plugin install gemname. This gem is not a stand-alone program
76
84
  email: info@elastic.co
77
85
  executables: []
78
86
  extensions: []
79
87
  extra_rdoc_files: []
80
88
  files:
81
- - .gitignore
82
89
  - CHANGELOG.md
83
90
  - CONTRIBUTORS
84
91
  - Gemfile
85
92
  - LICENSE
86
93
  - NOTICE.TXT
87
94
  - README.md
88
- - Rakefile
89
95
  - lib/logstash/inputs/irc.rb
90
96
  - logstash-input-irc.gemspec
91
97
  - spec/inputs/irc_spec.rb
98
+ - spec/spec_helper.rb
92
99
  homepage: http://www.elastic.co/guide/en/logstash/current/index.html
93
100
  licenses:
94
101
  - Apache License (2.0)
@@ -111,9 +118,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
111
118
  version: '0'
112
119
  requirements: []
113
120
  rubyforge_project:
114
- rubygems_version: 2.2.2
121
+ rubygems_version: 2.4.8
115
122
  signing_key:
116
123
  specification_version: 4
117
124
  summary: Read events from an IRC Server.
118
125
  test_files:
119
126
  - spec/inputs/irc_spec.rb
127
+ - spec/spec_helper.rb
data/.gitignore DELETED
@@ -1,4 +0,0 @@
1
- *.gem
2
- Gemfile.lock
3
- .bundle
4
- vendor
data/Rakefile DELETED
@@ -1,7 +0,0 @@
1
- @files=[]
2
-
3
- task :default do
4
- system("rake -T")
5
- end
6
-
7
- require "logstash/devutils/rake"