logstash-input-log4j 0.1.3-java
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +4 -0
- data/CONTRIBUTORS +21 -0
- data/Gemfile +2 -0
- data/LICENSE +13 -0
- data/README.md +86 -0
- data/Rakefile +7 -0
- data/lib/logstash/inputs/log4j.rb +141 -0
- data/logstash-input-log4j.gemspec +41 -0
- data/spec/inputs/log4j_spec.rb +13 -0
- metadata +132 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 624a0877940222d6f8d74ae0b163e25651f6bfec
|
4
|
+
data.tar.gz: 929be24428d26871d002e3ce4ed7226bce4f1c8a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d0560de34d867f06f91d5c567d92932996faa549e031775ee44e4918a029cd7de650e3a06e77d7b04b39aed24a594c0c7f58895615eacd96c0d15b174e2423cc
|
7
|
+
data.tar.gz: 0c642953f85f1a326794b3e9bc5211caca352270dff34629f2e8c67b4c47547d013facfb0a1efeeb0bcfa0d9604236811c82622a3bc8e5c7136c823c10e0aa4f
|
data/.gitignore
ADDED
data/CONTRIBUTORS
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The following is a list of people who have contributed ideas, code, bug
|
2
|
+
reports, or in general have helped logstash along its way.
|
3
|
+
|
4
|
+
Contributors:
|
5
|
+
* Avishai Ish-Shalom (avishai-ish-shalom)
|
6
|
+
* Bernd Ahlers (bernd)
|
7
|
+
* Colin Surprenant (colinsurprenant)
|
8
|
+
* Gang Chen (goncha)
|
9
|
+
* Jordan Sissel (jordansissel)
|
10
|
+
* Jurjan Woltman (jwoltman)
|
11
|
+
* Kurt Hurtado (kurtado)
|
12
|
+
* Matt Dainty (bodgit)
|
13
|
+
* Pete Fritchman (fetep)
|
14
|
+
* Pier-Hugues Pellerin (ph)
|
15
|
+
* Richard Pijnenburg (electrical)
|
16
|
+
* davux (davux)
|
17
|
+
|
18
|
+
Note: If you've sent us patches, bug reports, or otherwise contributed to
|
19
|
+
Logstash, and you aren't on the list above and want to be, please let us know
|
20
|
+
and we'll make sure you're here. Contributions from folks like you are what make
|
21
|
+
open source awesome.
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
Copyright (c) 2012-2015 Elasticsearch <http://www.elasticsearch.org>
|
2
|
+
|
3
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
you may not use this file except in compliance with the License.
|
5
|
+
You may obtain a copy of the License at
|
6
|
+
|
7
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
|
9
|
+
Unless required by applicable law or agreed to in writing, software
|
10
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
See the License for the specific language governing permissions and
|
13
|
+
limitations under the License.
|
data/README.md
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
# Logstash Plugin
|
2
|
+
|
3
|
+
This is a plugin for [Logstash](https://github.com/elasticsearch/logstash).
|
4
|
+
|
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
|
+
|
7
|
+
## Documentation
|
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/).
|
10
|
+
|
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
|
13
|
+
|
14
|
+
## Need Help?
|
15
|
+
|
16
|
+
Need help? Try #logstash on freenode IRC or the logstash-users@googlegroups.com mailing list.
|
17
|
+
|
18
|
+
## Developing
|
19
|
+
|
20
|
+
### 1. Plugin Developement and Testing
|
21
|
+
|
22
|
+
#### Code
|
23
|
+
- To get started, you'll need JRuby with the Bundler gem installed.
|
24
|
+
|
25
|
+
- Create a new plugin or clone and existing from the GitHub [logstash-plugins](https://github.com/logstash-plugins) organization. We also provide [example plugins](https://github.com/logstash-plugins?query=example).
|
26
|
+
|
27
|
+
- Install dependencies
|
28
|
+
```sh
|
29
|
+
bundle install
|
30
|
+
```
|
31
|
+
|
32
|
+
#### Test
|
33
|
+
|
34
|
+
- Update your dependencies
|
35
|
+
|
36
|
+
```sh
|
37
|
+
bundle install
|
38
|
+
```
|
39
|
+
|
40
|
+
- Run tests
|
41
|
+
|
42
|
+
```sh
|
43
|
+
bundle exec rspec
|
44
|
+
```
|
45
|
+
|
46
|
+
### 2. Running your unpublished Plugin in Logstash
|
47
|
+
|
48
|
+
#### 2.1 Run in a local Logstash clone
|
49
|
+
|
50
|
+
- Edit Logstash `Gemfile` and add the local plugin path, for example:
|
51
|
+
```ruby
|
52
|
+
gem "logstash-filter-awesome", :path => "/your/local/logstash-filter-awesome"
|
53
|
+
```
|
54
|
+
- Install plugin
|
55
|
+
```sh
|
56
|
+
bin/plugin install --no-verify
|
57
|
+
```
|
58
|
+
- Run Logstash with your plugin
|
59
|
+
```sh
|
60
|
+
bin/logstash -e 'filter {awesome {}}'
|
61
|
+
```
|
62
|
+
At this point any modifications to the plugin code will be applied to this local Logstash setup. After modifying the plugin, simply rerun Logstash.
|
63
|
+
|
64
|
+
#### 2.2 Run in an installed Logstash
|
65
|
+
|
66
|
+
You can use the same **2.1** method to run your plugin in an installed Logstash by editing its `Gemfile` and pointing the `:path` to your local plugin development directory or you can build the gem and install it using:
|
67
|
+
|
68
|
+
- Build your plugin gem
|
69
|
+
```sh
|
70
|
+
gem build logstash-filter-awesome.gemspec
|
71
|
+
```
|
72
|
+
- Install the plugin from the Logstash home
|
73
|
+
```sh
|
74
|
+
bin/plugin install /your/local/plugin/logstash-filter-awesome.gem
|
75
|
+
```
|
76
|
+
- Start Logstash and proceed to test the plugin
|
77
|
+
|
78
|
+
## Contributing
|
79
|
+
|
80
|
+
All contributions are welcome: ideas, patches, documentation, bug reports, complaints, and even something you drew up on a napkin.
|
81
|
+
|
82
|
+
Programming is not a required skill. Whatever you've seen about open source and maintainers or community members saying "send patches or die" - you will not see that here.
|
83
|
+
|
84
|
+
It is more important to the community that you are able to contribute.
|
85
|
+
|
86
|
+
For more information about contributing, see the [CONTRIBUTING](https://github.com/elasticsearch/logstash/blob/master/CONTRIBUTING.md) file.
|
data/Rakefile
ADDED
@@ -0,0 +1,141 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require "logstash/inputs/base"
|
3
|
+
require "logstash/errors"
|
4
|
+
require "logstash/environment"
|
5
|
+
require "logstash/namespace"
|
6
|
+
require "logstash/util/socket_peer"
|
7
|
+
require "socket"
|
8
|
+
require "timeout"
|
9
|
+
require 'logstash-input-log4j_jars'
|
10
|
+
|
11
|
+
# Read events over a TCP socket from a Log4j SocketAppender.
|
12
|
+
#
|
13
|
+
# Can either accept connections from clients or connect to a server,
|
14
|
+
# depending on `mode`. Depending on which `mode` is configured,
|
15
|
+
# you need a matching SocketAppender or a SocketHubAppender
|
16
|
+
# on the remote side.
|
17
|
+
class LogStash::Inputs::Log4j < LogStash::Inputs::Base
|
18
|
+
|
19
|
+
config_name "log4j"
|
20
|
+
|
21
|
+
# When mode is `server`, the address to listen on.
|
22
|
+
# When mode is `client`, the address to connect to.
|
23
|
+
config :host, :validate => :string, :default => "0.0.0.0"
|
24
|
+
|
25
|
+
# When mode is `server`, the port to listen on.
|
26
|
+
# When mode is `client`, the port to connect to.
|
27
|
+
config :port, :validate => :number, :default => 4560
|
28
|
+
|
29
|
+
# Read timeout in seconds. If a particular TCP connection is
|
30
|
+
# idle for more than this timeout period, we will assume
|
31
|
+
# it is dead and close it.
|
32
|
+
# If you never want to timeout, use -1.
|
33
|
+
config :data_timeout, :validate => :number, :default => 5
|
34
|
+
|
35
|
+
# Mode to operate in. `server` listens for client connections,
|
36
|
+
# `client` connects to a server.
|
37
|
+
config :mode, :validate => ["server", "client"], :default => "server"
|
38
|
+
|
39
|
+
def initialize(*args)
|
40
|
+
super(*args)
|
41
|
+
end # def initialize
|
42
|
+
|
43
|
+
public
|
44
|
+
def register
|
45
|
+
# LogStash::Environment.load_elasticsearch_jars!
|
46
|
+
require "java"
|
47
|
+
require "jruby/serialization"
|
48
|
+
|
49
|
+
begin
|
50
|
+
Java::OrgApacheLog4jSpi.const_get("LoggingEvent")
|
51
|
+
rescue
|
52
|
+
raise(LogStash::PluginLoadingError, "Log4j java library not loaded")
|
53
|
+
end
|
54
|
+
|
55
|
+
if server?
|
56
|
+
@logger.info("Starting Log4j input listener", :address => "#{@host}:#{@port}")
|
57
|
+
@server_socket = TCPServer.new(@host, @port)
|
58
|
+
end
|
59
|
+
@logger.info("Log4j input")
|
60
|
+
end # def register
|
61
|
+
|
62
|
+
private
|
63
|
+
def handle_socket(socket, output_queue)
|
64
|
+
begin
|
65
|
+
# JRubyObjectInputStream uses JRuby class path to find the class to de-serialize to
|
66
|
+
ois = JRubyObjectInputStream.new(java.io.BufferedInputStream.new(socket.to_inputstream))
|
67
|
+
loop do
|
68
|
+
# NOTE: log4j_obj is org.apache.log4j.spi.LoggingEvent
|
69
|
+
log4j_obj = ois.readObject
|
70
|
+
event = LogStash::Event.new("message" => log4j_obj.getRenderedMessage)
|
71
|
+
decorate(event)
|
72
|
+
event["host"] = socket.peer
|
73
|
+
event["path"] = log4j_obj.getLoggerName
|
74
|
+
event["priority"] = log4j_obj.getLevel.toString
|
75
|
+
event["logger_name"] = log4j_obj.getLoggerName
|
76
|
+
event["thread"] = log4j_obj.getThreadName
|
77
|
+
event["class"] = log4j_obj.getLocationInformation.getClassName
|
78
|
+
event["file"] = log4j_obj.getLocationInformation.getFileName + ":" + log4j_obj.getLocationInformation.getLineNumber
|
79
|
+
event["method"] = log4j_obj.getLocationInformation.getMethodName
|
80
|
+
event["NDC"] = log4j_obj.getNDC if log4j_obj.getNDC
|
81
|
+
event["stack_trace"] = log4j_obj.getThrowableStrRep.to_a.join("\n") if log4j_obj.getThrowableInformation
|
82
|
+
|
83
|
+
# Add the MDC context properties to '@fields'
|
84
|
+
if log4j_obj.getProperties
|
85
|
+
log4j_obj.getPropertyKeySet.each do |key|
|
86
|
+
event[key] = log4j_obj.getProperty(key)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
output_queue << event
|
91
|
+
end # loop do
|
92
|
+
rescue => e
|
93
|
+
@logger.debug("Closing connection", :client => socket.peer,
|
94
|
+
:exception => e)
|
95
|
+
rescue Timeout::Error
|
96
|
+
@logger.debug("Closing connection after read timeout",
|
97
|
+
:client => socket.peer)
|
98
|
+
end # begin
|
99
|
+
ensure
|
100
|
+
begin
|
101
|
+
socket.close
|
102
|
+
rescue IOError
|
103
|
+
pass
|
104
|
+
end # begin
|
105
|
+
end
|
106
|
+
|
107
|
+
private
|
108
|
+
def server?
|
109
|
+
@mode == "server"
|
110
|
+
end # def server?
|
111
|
+
|
112
|
+
private
|
113
|
+
def readline(socket)
|
114
|
+
line = socket.readline
|
115
|
+
end # def readline
|
116
|
+
|
117
|
+
public
|
118
|
+
def run(output_queue)
|
119
|
+
if server?
|
120
|
+
loop do
|
121
|
+
# Start a new thread for each connection.
|
122
|
+
Thread.start(@server_socket.accept) do |s|
|
123
|
+
# TODO(sissel): put this block in its own method.
|
124
|
+
|
125
|
+
# monkeypatch a 'peer' method onto the socket.
|
126
|
+
s.instance_eval { class << self; include ::LogStash::Util::SocketPeer end }
|
127
|
+
@logger.debug("Accepted connection", :client => s.peer,
|
128
|
+
:server => "#{@host}:#{@port}")
|
129
|
+
handle_socket(s, output_queue)
|
130
|
+
end # Thread.start
|
131
|
+
end # loop
|
132
|
+
else
|
133
|
+
loop do
|
134
|
+
client_socket = TCPSocket.new(@host, @port)
|
135
|
+
client_socket.instance_eval { class << self; include ::LogStash::Util::SocketPeer end }
|
136
|
+
@logger.debug("Opened connection", :client => "#{client_socket.peer}")
|
137
|
+
handle_socket(client_socket, output_queue)
|
138
|
+
end # loop
|
139
|
+
end
|
140
|
+
end # def run
|
141
|
+
end # class LogStash::Inputs::Log4j
|
@@ -0,0 +1,41 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
|
3
|
+
s.name = 'logstash-input-log4j'
|
4
|
+
s.version = '0.1.3'
|
5
|
+
s.licenses = ['Apache License (2.0)']
|
6
|
+
s.summary = "Read events over a TCP socket from a Log4j SocketAppender"
|
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"
|
8
|
+
s.authors = ["Elasticsearch"]
|
9
|
+
s.email = 'info@elasticsearch.com'
|
10
|
+
s.homepage = "http://www.elasticsearch.org/guide/en/logstash/current/index.html"
|
11
|
+
s.require_paths = ["lib"]
|
12
|
+
|
13
|
+
# Files
|
14
|
+
s.files = `git ls-files`.split($\)+::Dir.glob('vendor/*')
|
15
|
+
|
16
|
+
# Tests
|
17
|
+
s.test_files = s.files.grep(%r{^(test|spec|features)/})
|
18
|
+
|
19
|
+
# Special flag to let us know this is actually a logstash plugin
|
20
|
+
s.metadata = { "logstash_plugin" => "true", "logstash_group" => "input" }
|
21
|
+
|
22
|
+
s.platform = 'java'
|
23
|
+
# Jar dependencies
|
24
|
+
s.requirements << "jar 'log4j:log4j', '1.2.17'"
|
25
|
+
|
26
|
+
# Gem dependencies
|
27
|
+
# Currently there is a blocking issue with the latest (3.1.1.0.9) version of
|
28
|
+
# `ruby-maven` # and installing jars dependencies. If you are declaring a gem
|
29
|
+
# in a gemfile # using the :github option it will make the bundle install crash,
|
30
|
+
# before upgrading this gem you need to test the version with any plugins
|
31
|
+
# that require jars.
|
32
|
+
#
|
33
|
+
# Ticket: https://github.com/elasticsearch/logstash/issues/2595
|
34
|
+
s.add_runtime_dependency 'jar-dependencies', '0.1.7'
|
35
|
+
s.add_runtime_dependency 'ruby-maven', '3.1.1.0.8'
|
36
|
+
s.add_runtime_dependency "maven-tools", '1.0.7'
|
37
|
+
|
38
|
+
s.add_runtime_dependency "logstash-core", '>= 1.4.0', '< 2.0.0'
|
39
|
+
s.add_development_dependency 'logstash-devutils'
|
40
|
+
end
|
41
|
+
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require "logstash/plugin"
|
4
|
+
|
5
|
+
describe "inputs/log4j" do
|
6
|
+
|
7
|
+
it "should register" do
|
8
|
+
input = LogStash::Plugin.lookup("input", "log4j").new("mode" => "client")
|
9
|
+
|
10
|
+
# register will try to load jars and raise if it cannot find jars or if org.apache.log4j.spi.LoggingEvent class is not present
|
11
|
+
expect {input.register}.to_not raise_error
|
12
|
+
end
|
13
|
+
end
|
metadata
ADDED
@@ -0,0 +1,132 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: logstash-input-log4j
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.3
|
5
|
+
platform: java
|
6
|
+
authors:
|
7
|
+
- Elasticsearch
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-02-27 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: jar-dependencies
|
15
|
+
version_requirements: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.1.7
|
20
|
+
requirement: !ruby/object:Gem::Requirement
|
21
|
+
requirements:
|
22
|
+
- - '='
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: 0.1.7
|
25
|
+
prerelease: false
|
26
|
+
type: :runtime
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: ruby-maven
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 3.1.1.0.8
|
34
|
+
requirement: !ruby/object:Gem::Requirement
|
35
|
+
requirements:
|
36
|
+
- - '='
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: 3.1.1.0.8
|
39
|
+
prerelease: false
|
40
|
+
type: :runtime
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: maven-tools
|
43
|
+
version_requirements: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 1.0.7
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
requirements:
|
50
|
+
- - '='
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: 1.0.7
|
53
|
+
prerelease: false
|
54
|
+
type: :runtime
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: logstash-core
|
57
|
+
version_requirements: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 1.4.0
|
62
|
+
- - <
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: 2.0.0
|
65
|
+
requirement: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 1.4.0
|
70
|
+
- - <
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: 2.0.0
|
73
|
+
prerelease: false
|
74
|
+
type: :runtime
|
75
|
+
- !ruby/object:Gem::Dependency
|
76
|
+
name: logstash-devutils
|
77
|
+
version_requirements: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - '>='
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '0'
|
82
|
+
requirement: !ruby/object:Gem::Requirement
|
83
|
+
requirements:
|
84
|
+
- - '>='
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: '0'
|
87
|
+
prerelease: false
|
88
|
+
type: :development
|
89
|
+
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
|
90
|
+
email: info@elasticsearch.com
|
91
|
+
executables: []
|
92
|
+
extensions: []
|
93
|
+
extra_rdoc_files: []
|
94
|
+
files:
|
95
|
+
- .gitignore
|
96
|
+
- CONTRIBUTORS
|
97
|
+
- Gemfile
|
98
|
+
- LICENSE
|
99
|
+
- README.md
|
100
|
+
- Rakefile
|
101
|
+
- lib/logstash/inputs/log4j.rb
|
102
|
+
- logstash-input-log4j.gemspec
|
103
|
+
- spec/inputs/log4j_spec.rb
|
104
|
+
homepage: http://www.elasticsearch.org/guide/en/logstash/current/index.html
|
105
|
+
licenses:
|
106
|
+
- Apache License (2.0)
|
107
|
+
metadata:
|
108
|
+
logstash_plugin: 'true'
|
109
|
+
logstash_group: input
|
110
|
+
post_install_message:
|
111
|
+
rdoc_options: []
|
112
|
+
require_paths:
|
113
|
+
- lib
|
114
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
115
|
+
requirements:
|
116
|
+
- - '>='
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: '0'
|
119
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
120
|
+
requirements:
|
121
|
+
- - '>='
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
version: '0'
|
124
|
+
requirements:
|
125
|
+
- jar 'log4j:log4j', '1.2.17'
|
126
|
+
rubyforge_project:
|
127
|
+
rubygems_version: 2.4.5
|
128
|
+
signing_key:
|
129
|
+
specification_version: 4
|
130
|
+
summary: Read events over a TCP socket from a Log4j SocketAppender
|
131
|
+
test_files:
|
132
|
+
- spec/inputs/log4j_spec.rb
|