logstash-tsn-log4j2 6.0.21-java
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +3 -0
- data/README.md +47 -0
- data/lib/logstash/inputs/log4j2.rb +163 -0
- data/logstash-tsn-log4j2.gemspec +29 -0
- data/vendor/disruptor-3.3.0.jar +0 -0
- metadata +84 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: fb8c1adca8612be4764cb0d94cc7a01710ab1dd3
|
4
|
+
data.tar.gz: a3e4605d851e1d4f265fde0d158901faf600e590
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 52f1182d8a283239c542ecef110a175086c0d3d7f2b083c40115cf9f7e9d78458b3ac9fa884fbc18c174944a9dc8710a3b6299957c5e8c69bc229ab21f518185
|
7
|
+
data.tar.gz: 192aef8bce43c504b24af7bd7352c49a85b2b341def60b708e4549c6ba8044b381920999e05b3f1bffeb35fb2d964cd8dd6a58eada946bdd1b75e374234d6369
|
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,47 @@
|
|
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 5+
|
11
|
+
|
12
|
+
Use the install method
|
13
|
+
|
14
|
+
```$LS_HOME/bin/plugin-install logstash-tsn-log4j2```
|
15
|
+
|
16
|
+
## Setup log4j2
|
17
|
+
Set log4j2.xml in your project
|
18
|
+
```xml
|
19
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
20
|
+
<Configuration>
|
21
|
+
<Appenders>
|
22
|
+
<Socket name="A1" host="localHost" port="7000">
|
23
|
+
<SerializedLayout />
|
24
|
+
</Socket>
|
25
|
+
</Appenders>
|
26
|
+
<Loggers>
|
27
|
+
<Root level="debug">
|
28
|
+
<AppenderRef ref="A1"/>
|
29
|
+
</Root>
|
30
|
+
</Loggers>
|
31
|
+
</Configuration>
|
32
|
+
```
|
33
|
+
|
34
|
+
## Setup Logstash
|
35
|
+
|
36
|
+
```
|
37
|
+
input {
|
38
|
+
log4j2 {
|
39
|
+
port => 7000
|
40
|
+
mode => "server"
|
41
|
+
}
|
42
|
+
}
|
43
|
+
|
44
|
+
output {
|
45
|
+
stdout { codec => rubydebug }
|
46
|
+
}
|
47
|
+
```
|
@@ -0,0 +1,163 @@
|
|
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.6.2.jar")
|
51
|
+
# require File.join(vendor_dir, "log4j-core-2.6.2.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.set('host', socket.peer)
|
89
|
+
event.set('marker', log4j_obj.getMarker.getName) if log4j_obj.getMarker
|
90
|
+
event.set('path', log4j_obj.getLoggerName)
|
91
|
+
event.set('priority', log4j_obj.getLevel.toString)
|
92
|
+
event.set('logger_name', log4j_obj.getLoggerName)
|
93
|
+
event.set('thread', log4j_obj.getThreadName)
|
94
|
+
if log4j_obj.getSource()
|
95
|
+
event.set('class', log4j_obj.getSource().getClassName)
|
96
|
+
event.set('file', log4j_obj.getSource().getFileName + ":" + log4j_obj.getSource().getLineNumber.to_s)
|
97
|
+
event.set('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.set('cmap_"+key', log4j_obj.contextMap.get(key))
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
proxy = log4j_obj.getThrownProxy
|
107
|
+
if proxy
|
108
|
+
event.set('stack_trace', pretty_print_stack_trace(proxy))
|
109
|
+
end
|
110
|
+
|
111
|
+
event.set('cstack', log4j_obj.getContextStack.to_a) if log4j_obj.getContextStack
|
112
|
+
output_queue << event
|
113
|
+
end # loop do
|
114
|
+
rescue => e
|
115
|
+
@logger.info("Closing connection", :client => socket.peer,
|
116
|
+
:exception => e)
|
117
|
+
rescue Timeout::Error
|
118
|
+
@logger.info("Closing connection after read timeout",
|
119
|
+
:client => socket.peer)
|
120
|
+
end # begin
|
121
|
+
ensure
|
122
|
+
begin
|
123
|
+
socket.close
|
124
|
+
rescue IOError
|
125
|
+
pass
|
126
|
+
end # begin
|
127
|
+
end
|
128
|
+
|
129
|
+
private
|
130
|
+
def server?
|
131
|
+
@mode == "server"
|
132
|
+
end # def server?
|
133
|
+
|
134
|
+
private
|
135
|
+
def readline(socket)
|
136
|
+
line = socket.readline
|
137
|
+
end # def readline
|
138
|
+
|
139
|
+
public
|
140
|
+
def run(output_queue)
|
141
|
+
if server?
|
142
|
+
loop do
|
143
|
+
# Start a new thread for each connection.
|
144
|
+
Thread.start(@server_socket.accept) do |s|
|
145
|
+
# TODO(sissel): put this block in its own method.
|
146
|
+
|
147
|
+
# monkeypatch a 'peer' method onto the socket.
|
148
|
+
s.instance_eval { class << self; include ::LogStash::Util::SocketPeer end }
|
149
|
+
@logger.info("Accepted connection", :client => s.peer,
|
150
|
+
:server => "#{@host}:#{@port}")
|
151
|
+
handle_socket(s, output_queue)
|
152
|
+
end # Thread.start
|
153
|
+
end # loop
|
154
|
+
else
|
155
|
+
loop do
|
156
|
+
client_socket = TCPSocket.new(@host, @port)
|
157
|
+
client_socket.instance_eval { class << self; include ::LogStash::Util::SocketPeer end }
|
158
|
+
@logger.info("Opened connection", :client => "#{client_socket.peer}")
|
159
|
+
handle_socket(client_socket, output_queue)
|
160
|
+
end # loop
|
161
|
+
end
|
162
|
+
end # def run
|
163
|
+
end # class LogStash::Inputs::Log4j2
|
@@ -0,0 +1,29 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = 'logstash-tsn-log4j2'
|
3
|
+
s.version = '6.0.21'
|
4
|
+
s.licenses = ['Apache-2.0']
|
5
|
+
s.summary = "Read events over a TCP socket from a Log4j2 SocketAppender"
|
6
|
+
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"
|
7
|
+
s.authors = ["Jurriaan Mous / Modified by TSN"]
|
8
|
+
s.email = 'wardeon+2@gmail.com'
|
9
|
+
s.homepage = "https://github.com/tnoeding/logstash-log4j2"
|
10
|
+
s.require_paths = ["lib"]
|
11
|
+
|
12
|
+
# Files
|
13
|
+
#s.files = `git ls-files`.split($\)+::Dir.glob('vendor/*')
|
14
|
+
|
15
|
+
|
16
|
+
s.files = Dir['lib/**/*','spec/**/*','vendor/**/*','*.gemspec','*.md','CONTRIBUTORS','Gemfile','LICENSE','NOTICE.TXT']
|
17
|
+
|
18
|
+
# Tests
|
19
|
+
s.test_files = s.files.grep(%r{^(test|spec|features)/})
|
20
|
+
|
21
|
+
# Special flag to let us know this is actually a logstash plugin
|
22
|
+
s.metadata = { "logstash_plugin" => "true", "logstash_group" => "input" }
|
23
|
+
|
24
|
+
s.platform = 'java'
|
25
|
+
|
26
|
+
s.add_runtime_dependency "logstash-core", ">= 2.0.0.beta2", "< 6.0.0"
|
27
|
+
|
28
|
+
s.add_development_dependency 'logstash-devutils'
|
29
|
+
end
|
Binary file
|
metadata
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: logstash-tsn-log4j2
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 6.0.21
|
5
|
+
platform: java
|
6
|
+
authors:
|
7
|
+
- Jurriaan Mous / Modified by TSN
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-02-03 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
15
|
+
requirements:
|
16
|
+
- - ">="
|
17
|
+
- !ruby/object:Gem::Version
|
18
|
+
version: 2.0.0.beta2
|
19
|
+
- - "<"
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 6.0.0
|
22
|
+
name: logstash-core
|
23
|
+
prerelease: false
|
24
|
+
type: :runtime
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 2.0.0.beta2
|
30
|
+
- - "<"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 6.0.0
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
requirement: !ruby/object:Gem::Requirement
|
35
|
+
requirements:
|
36
|
+
- - ">="
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: '0'
|
39
|
+
name: logstash-devutils
|
40
|
+
prerelease: false
|
41
|
+
type: :development
|
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 Logstash core pipeline using $LS_HOME/bin/plugin install gemname. This gem is not a stand-alone program
|
48
|
+
email: wardeon+2@gmail.com
|
49
|
+
executables: []
|
50
|
+
extensions: []
|
51
|
+
extra_rdoc_files: []
|
52
|
+
files:
|
53
|
+
- Gemfile
|
54
|
+
- README.md
|
55
|
+
- lib/logstash/inputs/log4j2.rb
|
56
|
+
- logstash-tsn-log4j2.gemspec
|
57
|
+
- vendor/disruptor-3.3.0.jar
|
58
|
+
homepage: https://github.com/tnoeding/logstash-log4j2
|
59
|
+
licenses:
|
60
|
+
- Apache-2.0
|
61
|
+
metadata:
|
62
|
+
logstash_plugin: 'true'
|
63
|
+
logstash_group: input
|
64
|
+
post_install_message:
|
65
|
+
rdoc_options: []
|
66
|
+
require_paths:
|
67
|
+
- lib
|
68
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
69
|
+
requirements:
|
70
|
+
- - ">="
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: '0'
|
73
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
requirements: []
|
79
|
+
rubyforge_project:
|
80
|
+
rubygems_version: 2.6.8
|
81
|
+
signing_key:
|
82
|
+
specification_version: 4
|
83
|
+
summary: Read events over a TCP socket from a Log4j2 SocketAppender
|
84
|
+
test_files: []
|