logstash-input-log4j2 5.1-java

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 99611e5057c9de11a347854d2a90a554248e0302
4
+ data.tar.gz: 2ff90bd66be4acb7fadb4e405a2a7bf533ee62f4
5
+ SHA512:
6
+ metadata.gz: 401998783421437e5f6b0673304c02801c8d804d5f8d86a3af02870fd00d7d0296880b4628ffb5a79d4b0b653c9d5456b3350fb502ff86a96fa744f65fd2e95a
7
+ data.tar.gz: afd37dcfdabe842bfd2100f49b9560c2a9098afcc7723cfc664638cb9991fe5eeb671e65d20d24581cff88c151944b14ec2f1166b067dda42d0fdd64c7ac6605
data/.gitignore ADDED
@@ -0,0 +1,37 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /test/tmp/
9
+ /test/version_tmp/
10
+ /tmp/
11
+
12
+ ## Specific to RubyMotion:
13
+ .dat*
14
+ .repl_history
15
+ build/
16
+
17
+ ## Documentation cache and generated files:
18
+ /.yardoc/
19
+ /_yardoc/
20
+ /doc/
21
+ /rdoc/
22
+
23
+ ## Environment normalisation:
24
+ /.bundle/
25
+ /lib/bundler/man/
26
+
27
+ # for a library or gem, you might want to ignore these files since the code is
28
+ # intended to run in multiple environments; otherwise, check them in:
29
+ # Gemfile.lock
30
+ # .ruby-version
31
+ # .ruby-gemset
32
+
33
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
34
+ .rvmrc
35
+
36
+ # vendor files (jars)
37
+ vendor/
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
3
+ gem "logstash", :github => "elasticsearch/logstash", :branch => "1.5"
data/README.md ADDED
@@ -0,0 +1,55 @@
1
+ # logstash-log4j2
2
+
3
+ Log4j2 plugin for logstash.
4
+
5
+ ## Supported Log4J2 versions:
6
+ Version: 2.1+
7
+
8
+ ## Get the plugin
9
+
10
+ ### Logstash 1.5+
11
+
12
+ Use the install method
13
+
14
+ ```$LS_HOME/bin/plugin install logstash-input-log4j2```
15
+
16
+ ### Logstash 1.4
17
+
18
+ Download the latest release at: https://github.com/jurmous/logstash-log4j2/releases and unzip it.
19
+
20
+ If you download the source you also need rake to run ```rake vendor``` to download the correct log4j2 jars.
21
+
22
+ To run the plugin you need to start logstash with the plugin path `./bin/logstash --pluginpath PATH_TO_PLUGIN -f YOUR_CONF.conf`
23
+
24
+ ## Setup log4j2
25
+ Set log4j2.xml in your project
26
+ ```xml
27
+ <?xml version="1.0" encoding="UTF-8"?>
28
+ <Configuration>
29
+ <Appenders>
30
+ <Socket name="A1" host="localHost" port="7000">
31
+ <SerializedLayout />
32
+ </Socket>
33
+ </Appenders>
34
+ <Loggers>
35
+ <Root level="debug">
36
+ <AppenderRef ref="A1"/>
37
+ </Root>
38
+ </Loggers>
39
+ </Configuration>
40
+ ```
41
+
42
+ ## Setup Logstash
43
+
44
+ ```
45
+ input {
46
+ log4j2 {
47
+ port => 7000
48
+ mode => "server"
49
+ }
50
+ }
51
+
52
+ output {
53
+ stdout { codec => rubydebug }
54
+ }
55
+ ```
data/Rakefile ADDED
@@ -0,0 +1,11 @@
1
+ @files=[
2
+ {'url' => "https://repo1.maven.org/maven2/org/apache/logging/log4j/log4j-core/2.1/log4j-core-2.1.jar", 'sha1' => '31823dcde108f2ea4a5801d1acc77869d7696533' },
3
+ {'url' => "https://repo1.maven.org/maven2/org/apache/logging/log4j/log4j-api/2.1/log4j-api-2.1.jar", 'sha1' => '588c32c91544d80cc706447aa2b8037230114931'},
4
+ {'url' => "https://repo1.maven.org/maven2/com/lmax/disruptor/3.3.0/disruptor-3.3.0.jar", 'sha1' => '6925c7787741f6ac1535188ea450f04fa1246acf'}
5
+ ]
6
+
7
+ task :default do
8
+ system("rake -T")
9
+ end
10
+
11
+ require "logstash/devutils/rake"
@@ -0,0 +1,164 @@
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
+
10
+ # Read events over a TCP socket from a Log4j2 SocketAppender.
11
+ #
12
+ # Can either accept connections from clients or connect to a server,
13
+ # depending on `mode`. Depending on which `mode` is configured,
14
+ # you need a matching SocketAppender or a SocketHubAppender
15
+ # on the remote side.
16
+ class LogStash::Inputs::Log4j2 < LogStash::Inputs::Base
17
+
18
+ config_name "log4j2"
19
+ milestone 1
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
+ require "java"
46
+ require "jruby/serialization"
47
+
48
+ begin
49
+ vendor_dir = ::File.expand_path("../../../vendor/", ::File.dirname(__FILE__))
50
+ require File.join(vendor_dir, "log4j-api-2.1.jar")
51
+ require File.join(vendor_dir, "log4j-core-2.1.jar")
52
+ require File.join(vendor_dir, "disruptor-3.3.0.jar")
53
+
54
+ Java::OrgApacheLoggingLog4jCoreImpl.const_get("Log4jLogEvent")
55
+ rescue
56
+ raise(LogStash::PluginLoadingError, "Log4j2 java library not loaded")
57
+ end
58
+
59
+ if server?
60
+ @logger.info("Starting Log4j2 input listener", :address => "#{@host}:#{@port}")
61
+ @server_socket = TCPServer.new(@host, @port)
62
+ end
63
+ @logger.info("Log4j input")
64
+ end # def register
65
+
66
+ private
67
+ def pretty_print_stack_trace(proxy)
68
+ indentation = "\n\t"
69
+ result = "#{proxy.getName}: #{proxy.getMessage.to_s}#{indentation}#{proxy.getExtendedStackTrace.to_a.join(indentation)}"
70
+ cause = proxy.getCauseProxy
71
+ while cause
72
+ result += "\nCaused by: #{cause.getName}: #{cause.getMessage.to_s}#{indentation}#{cause.getExtendedStackTrace.to_a.join(indentation)}"
73
+ cause = cause.getCauseProxy
74
+ end
75
+ result
76
+ end
77
+
78
+ private
79
+ def handle_socket(socket, output_queue)
80
+ begin
81
+ # JRubyObjectInputStream uses JRuby class path to find the class to de-serialize to
82
+ ois = JRubyObjectInputStream.new(java.io.BufferedInputStream.new(socket.to_inputstream))
83
+ loop do
84
+ # NOTE: log4j_obj is org.apache.logging.log4j.core.impl.Log4jLogEvent
85
+ log4j_obj = ois.readObject
86
+ event = LogStash::Event.new("message" => log4j_obj.getMessage.getFormattedMessage, LogStash::Event::TIMESTAMP => Time.at(log4j_obj.getTimeMillis/1000,log4j_obj.getTimeMillis%1000*1000).gmtime)
87
+ decorate(event)
88
+ event["host"] = socket.peer
89
+ event["marker"] = log4j_obj.getMarker.getName if log4j_obj.getMarker
90
+ event["path"] = log4j_obj.getLoggerName
91
+ event["priority"] = log4j_obj.getLevel.toString
92
+ event["logger_name"] = log4j_obj.getLoggerName
93
+ event["thread"] = log4j_obj.getThreadName
94
+ if log4j_obj.getSource()
95
+ event["class"] = log4j_obj.getSource().getClassName
96
+ event["file"] = log4j_obj.getSource().getFileName + ":" + log4j_obj.getSource().getLineNumber.to_s
97
+ event["method"] = log4j_obj.getSource().getMethodName
98
+ end
99
+ # Add the context properties to '@fields'
100
+ if log4j_obj.contextMap
101
+ log4j_obj.contextMap.keySet.each do |key|
102
+ event["cmap_"+key] = log4j_obj.contextMap.get(key)
103
+ end
104
+ end
105
+
106
+ proxy = log4j_obj.getThrownProxy
107
+ if proxy
108
+ event["stack_trace"] = pretty_print_stack_trace(proxy)
109
+ end
110
+
111
+ event["cstack"] = log4j_obj.getContextStack.to_a if log4j_obj.getContextStack
112
+ output_queue << event
113
+ end # loop do
114
+ rescue => e
115
+ @logger.debug(e)
116
+ @logger.debug("Closing connection", :client => socket.peer,
117
+ :exception => e)
118
+ rescue Timeout::Error
119
+ @logger.debug("Closing connection after read timeout",
120
+ :client => socket.peer)
121
+ end # begin
122
+ ensure
123
+ begin
124
+ socket.close
125
+ rescue IOError
126
+ pass
127
+ end # begin
128
+ end
129
+
130
+ private
131
+ def server?
132
+ @mode == "server"
133
+ end # def server?
134
+
135
+ private
136
+ def readline(socket)
137
+ line = socket.readline
138
+ end # def readline
139
+
140
+ public
141
+ def run(output_queue)
142
+ if server?
143
+ loop do
144
+ # Start a new thread for each connection.
145
+ Thread.start(@server_socket.accept) do |s|
146
+ # TODO(sissel): put this block in its own method.
147
+
148
+ # monkeypatch a 'peer' method onto the socket.
149
+ s.instance_eval { class << self; include ::LogStash::Util::SocketPeer end }
150
+ @logger.debug("Accepted connection", :client => s.peer,
151
+ :server => "#{@host}:#{@port}")
152
+ handle_socket(s, output_queue)
153
+ end # Thread.start
154
+ end # loop
155
+ else
156
+ loop do
157
+ client_socket = TCPSocket.new(@host, @port)
158
+ client_socket.instance_eval { class << self; include ::LogStash::Util::SocketPeer end }
159
+ @logger.debug("Opened connection", :client => "#{client_socket.peer}")
160
+ handle_socket(client_socket, output_queue)
161
+ end # loop
162
+ end
163
+ end # def run
164
+ end # class LogStash::Inputs::Log4j2
@@ -0,0 +1,26 @@
1
+ Gem::Specification.new do |s|
2
+
3
+ s.name = 'logstash-input-log4j2'
4
+ s.version = '5.1'
5
+ s.licenses = ['Apache License (2.0)']
6
+ s.summary = "Read events over a TCP socket from a Log4j2 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 = ["Jurriaan Mous"]
9
+ s.email = 'jurmous@jurmo.us'
10
+ s.homepage = "https://github.com/jurmous/logstash-log4j2"
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
+
24
+ s.add_runtime_dependency "logstash-core", '>= 1.4.0', '< 2.0.0'
25
+ s.add_development_dependency 'logstash-devutils'
26
+ end
metadata ADDED
@@ -0,0 +1,90 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: logstash-input-log4j2
3
+ version: !ruby/object:Gem::Version
4
+ version: '5.1'
5
+ platform: java
6
+ authors:
7
+ - Jurriaan Mous
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-04-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: logstash-core
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: 1.4.0
20
+ - - <
21
+ - !ruby/object:Gem::Version
22
+ version: 2.0.0
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - '>='
28
+ - !ruby/object:Gem::Version
29
+ version: 1.4.0
30
+ - - <
31
+ - !ruby/object:Gem::Version
32
+ version: 2.0.0
33
+ - !ruby/object:Gem::Dependency
34
+ name: logstash-devutils
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - '>='
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ type: :development
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - '>='
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ description: This gem is a logstash plugin required to be installed on top of the
48
+ Logstash core pipeline using $LS_HOME/bin/plugin install gemname. This gem is not
49
+ a stand-alone program
50
+ email: jurmous@jurmo.us
51
+ executables: []
52
+ extensions: []
53
+ extra_rdoc_files: []
54
+ files:
55
+ - .gitignore
56
+ - Gemfile
57
+ - README.md
58
+ - Rakefile
59
+ - lib/logstash/inputs/log4j2.rb
60
+ - logstash-input-log4j2.gemspec
61
+ - vendor/disruptor-3.3.0.jar
62
+ - vendor/log4j-api-2.1.jar
63
+ - vendor/log4j-core-2.1.jar
64
+ homepage: https://github.com/jurmous/logstash-log4j2
65
+ licenses:
66
+ - Apache License (2.0)
67
+ metadata:
68
+ logstash_plugin: 'true'
69
+ logstash_group: input
70
+ post_install_message:
71
+ rdoc_options: []
72
+ require_paths:
73
+ - lib
74
+ required_ruby_version: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - '>='
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ required_rubygems_version: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - '>='
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ requirements: []
85
+ rubyforge_project:
86
+ rubygems_version: 2.0.14
87
+ signing_key:
88
+ specification_version: 4
89
+ summary: Read events over a TCP socket from a Log4j2 SocketAppender
90
+ test_files: []