logstash-input-irc 0.1.4 → 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/logstash/inputs/irc.rb +79 -9
- data/logstash-input-irc.gemspec +1 -1
- metadata +17 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bff489f521755ff86ab1a651e99a0f9fc5b6d237
|
4
|
+
data.tar.gz: 48b7b53e0afa268840c7be0fca06b59d702d4530
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c3c7f8fe563344601340753d69c8f61e06026c6e8563c65ce4b4ac42a6da659ef3db99804743a58acad34eb71cc3623ae2ac9a6314ad94a9bc1eb1d2337babbc
|
7
|
+
data.tar.gz: 6c9aa83d937645850b044fd06261beaf7a3e28b4e41b78fadcd03421f20fa30f547a6b77216c4493e7da37238f57a93db744efd44b2cd8ed70f7c683b7549cfe
|
data/lib/logstash/inputs/irc.rb
CHANGED
@@ -32,20 +32,31 @@ class LogStash::Inputs::Irc < LogStash::Inputs::Base
|
|
32
32
|
# IRC Server password
|
33
33
|
config :password, :validate => :password
|
34
34
|
|
35
|
+
# Catch all IRC channel/user events not just channel messages
|
36
|
+
config :catch_all, :validate => :boolean, :default => false
|
37
|
+
|
38
|
+
# Gather and send user counts for channels - this requires catch_all and will force it
|
39
|
+
config :get_stats, :validate => :boolean, :default => false
|
40
|
+
|
41
|
+
# How often in minutes to get the user count stats
|
42
|
+
config :stats_interval, :validate => :number, :default => 5
|
43
|
+
|
35
44
|
# Channels to join and read messages from.
|
36
45
|
#
|
37
|
-
# These should be full channel names including the
|
38
|
-
#
|
46
|
+
# These should be full channel names including the '#' symbol, such as
|
47
|
+
# "#logstash".
|
39
48
|
#
|
40
49
|
# For passworded channels, add a space and the channel password, such as
|
41
|
-
#
|
50
|
+
# "#logstash password".
|
42
51
|
#
|
43
52
|
config :channels, :validate => :array, :required => true
|
44
53
|
|
45
54
|
public
|
46
55
|
def register
|
47
56
|
require "cinch"
|
57
|
+
@user_stats = Hash.new
|
48
58
|
@irc_queue = Queue.new
|
59
|
+
@catch_all = true if @get_stats
|
49
60
|
@logger.info("Connecting to irc server", :host => @host, :port => @port, :nick => @nick, :channels => @channels)
|
50
61
|
|
51
62
|
@bot = Cinch::Bot.new
|
@@ -61,27 +72,86 @@ class LogStash::Inputs::Irc < LogStash::Inputs::Base
|
|
61
72
|
c.ssl.use = @secure
|
62
73
|
end
|
63
74
|
queue = @irc_queue
|
64
|
-
@
|
65
|
-
|
75
|
+
if @catch_all
|
76
|
+
@bot.on :catchall do |m|
|
77
|
+
queue << m
|
78
|
+
end
|
79
|
+
else
|
80
|
+
@bot.on :channel do |m|
|
81
|
+
queue << m
|
82
|
+
end
|
66
83
|
end
|
84
|
+
|
67
85
|
end # def register
|
68
86
|
|
69
87
|
public
|
70
88
|
def run(output_queue)
|
71
|
-
|
72
|
-
|
89
|
+
@bot_thread = Stud::Task.new(@bot) do |bot|
|
90
|
+
bot.start
|
91
|
+
end
|
92
|
+
if @get_stats
|
93
|
+
@request_names_thread = Stud::Task.new do
|
94
|
+
loop do
|
95
|
+
sleep (@stats_interval * 60)
|
96
|
+
request_names
|
97
|
+
end
|
98
|
+
end
|
73
99
|
end
|
74
100
|
loop do
|
75
101
|
msg = @irc_queue.pop
|
76
|
-
|
102
|
+
handle_response(msg, output_queue)
|
103
|
+
end
|
104
|
+
end # def run
|
105
|
+
|
106
|
+
RPL_NAMREPLY = "353"
|
107
|
+
RPL_ENDOFNAMES = "366"
|
108
|
+
|
109
|
+
def handle_response (msg, output_queue)
|
110
|
+
# Set some constant variables based on https://www.alien.net.au/irc/irc2numerics.html
|
111
|
+
|
112
|
+
if @get_stats and msg.command.to_s == RPL_NAMREPLY
|
113
|
+
# Got a names list event
|
114
|
+
# Count the users returned in msg.params[3] split by " "
|
115
|
+
users = msg.params[3].split(" ")
|
116
|
+
@user_stats[msg.channel.to_s] = (@user_stats[msg.channel.to_s] || 0) + users.length
|
117
|
+
end
|
118
|
+
if @get_stats and msg.command.to_s == RPL_ENDOFNAMES
|
119
|
+
# Got an end of names event, now we can send the info down the pipe.
|
120
|
+
event = LogStash::Event.new()
|
121
|
+
decorate(event)
|
122
|
+
event["channel"] = msg.channel.to_s
|
123
|
+
event["users"] = @user_stats[msg.channel.to_s]
|
124
|
+
event["server"] = "#{@host}:#{@port}"
|
125
|
+
output_queue << event
|
126
|
+
end
|
127
|
+
if msg.command and msg.user
|
128
|
+
@logger.debug("IRC Message", :data => msg)
|
77
129
|
@codec.decode(msg.message) do |event|
|
78
130
|
decorate(event)
|
131
|
+
event["user"] = msg.prefix.to_s
|
132
|
+
event["command"] = msg.command.to_s
|
79
133
|
event["channel"] = msg.channel.to_s
|
80
134
|
event["nick"] = msg.user.nick
|
81
135
|
event["server"] = "#{@host}:#{@port}"
|
136
|
+
event["host"] = msg.user.host
|
82
137
|
output_queue << event
|
83
138
|
end
|
84
139
|
end
|
140
|
+
end
|
141
|
+
|
142
|
+
def request_names
|
143
|
+
# Go though list of channels, and request a NAMES for them
|
144
|
+
# Note : Logstash channel list can have passwords ie : "channel password"
|
145
|
+
# Need to account for that
|
146
|
+
@channels.each do |channel|
|
147
|
+
channel = channel.split(' ').first if channel.include?(' ')
|
148
|
+
@user_stats[channel] = 0
|
149
|
+
@bot.irc.send("NAMES #{channel}")
|
85
150
|
end
|
86
|
-
end
|
151
|
+
end
|
152
|
+
|
153
|
+
def teardown
|
154
|
+
@request_names_thread#stop!
|
155
|
+
@bot_thread#stop!
|
156
|
+
end
|
87
157
|
end # class LogStash::Inputs::Irc
|
data/logstash-input-irc.gemspec
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
|
3
3
|
s.name = 'logstash-input-irc'
|
4
|
-
s.version = '0.1.
|
4
|
+
s.version = '0.1.5'
|
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"
|
metadata
CHANGED
@@ -1,17 +1,18 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: logstash-input-irc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Elastic
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-04-
|
11
|
+
date: 2015-04-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
|
14
|
+
name: logstash-core
|
15
|
+
version_requirements: !ruby/object:Gem::Requirement
|
15
16
|
requirements:
|
16
17
|
- - '>='
|
17
18
|
- !ruby/object:Gem::Version
|
@@ -19,10 +20,7 @@ dependencies:
|
|
19
20
|
- - <
|
20
21
|
- !ruby/object:Gem::Version
|
21
22
|
version: 2.0.0
|
22
|
-
|
23
|
-
prerelease: false
|
24
|
-
type: :runtime
|
25
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirement: !ruby/object:Gem::Requirement
|
26
24
|
requirements:
|
27
25
|
- - '>='
|
28
26
|
- !ruby/object:Gem::Version
|
@@ -30,48 +28,50 @@ dependencies:
|
|
30
28
|
- - <
|
31
29
|
- !ruby/object:Gem::Version
|
32
30
|
version: 2.0.0
|
31
|
+
prerelease: false
|
32
|
+
type: :runtime
|
33
33
|
- !ruby/object:Gem::Dependency
|
34
|
+
name: logstash-codec-plain
|
35
|
+
version_requirements: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - '>='
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
34
40
|
requirement: !ruby/object:Gem::Requirement
|
35
41
|
requirements:
|
36
42
|
- - '>='
|
37
43
|
- !ruby/object:Gem::Version
|
38
44
|
version: '0'
|
39
|
-
name: logstash-codec-plain
|
40
45
|
prerelease: false
|
41
46
|
type: :runtime
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: cinch
|
42
49
|
version_requirements: !ruby/object:Gem::Requirement
|
43
50
|
requirements:
|
44
51
|
- - '>='
|
45
52
|
- !ruby/object:Gem::Version
|
46
53
|
version: '0'
|
47
|
-
- !ruby/object:Gem::Dependency
|
48
54
|
requirement: !ruby/object:Gem::Requirement
|
49
55
|
requirements:
|
50
56
|
- - '>='
|
51
57
|
- !ruby/object:Gem::Version
|
52
58
|
version: '0'
|
53
|
-
name: cinch
|
54
59
|
prerelease: false
|
55
60
|
type: :runtime
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: logstash-devutils
|
56
63
|
version_requirements: !ruby/object:Gem::Requirement
|
57
64
|
requirements:
|
58
65
|
- - '>='
|
59
66
|
- !ruby/object:Gem::Version
|
60
67
|
version: '0'
|
61
|
-
- !ruby/object:Gem::Dependency
|
62
68
|
requirement: !ruby/object:Gem::Requirement
|
63
69
|
requirements:
|
64
70
|
- - '>='
|
65
71
|
- !ruby/object:Gem::Version
|
66
72
|
version: '0'
|
67
|
-
name: logstash-devutils
|
68
73
|
prerelease: false
|
69
74
|
type: :development
|
70
|
-
version_requirements: !ruby/object:Gem::Requirement
|
71
|
-
requirements:
|
72
|
-
- - '>='
|
73
|
-
- !ruby/object:Gem::Version
|
74
|
-
version: '0'
|
75
75
|
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
76
|
email: info@elastic.co
|
77
77
|
executables: []
|