logstash-codec-joinlines 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,140 @@
1
+ # encoding: utf-8
2
+
3
+ def decode_events
4
+ joinlines = LogStash::Codecs::Joinlines.new(options)
5
+
6
+ events = []
7
+ random_number_of_events.times do |n|
8
+ joinlines.decode(sample_event) { |event| events << event }
9
+ end
10
+
11
+ # Grab the in-memory-event
12
+ joinlines.flush { |event| events << event }
13
+ events
14
+ end
15
+
16
+ module Jlc
17
+ class LineListener
18
+ attr_reader :data, :path, :queue, :codec
19
+ # use attr_reader to define noop methods of Listener API
20
+ attr_reader :deleted, :created, :error, :eof #, :line
21
+
22
+ def initialize(queue, codec, path = '')
23
+ # store state from upstream
24
+ @queue = queue
25
+ @codec = codec
26
+ @path = path
27
+ end
28
+
29
+ # receives a line from some upstream source
30
+ # and sends it downstream
31
+ def accept(data)
32
+ @codec.accept dup_adding_state(data)
33
+ end
34
+
35
+ def process_event(event)
36
+ event.set("path", path)
37
+ @queue << event
38
+ end
39
+
40
+ def add_state(data)
41
+ @data = data
42
+ self
43
+ end
44
+
45
+ private
46
+
47
+ # dup and add state for downstream
48
+ def dup_adding_state(line)
49
+ self.class.new(queue, codec, path).add_state(line)
50
+ end
51
+ end
52
+
53
+ class LineErrorListener < LineListener
54
+ def process_event(event)
55
+ raise StandardError.new("OMG, Daleks!")
56
+ end
57
+ end
58
+
59
+ class JoinlinesRspec < LogStash::Codecs::Joinlines
60
+ def internal_buffer
61
+ @buffer
62
+ end
63
+ def buffer_size
64
+ @buffer.size
65
+ end
66
+ end
67
+
68
+ class TracerBase
69
+ def initialize() @tracer = []; end
70
+
71
+ def trace_for(symbol)
72
+ params = @tracer.assoc(symbol)
73
+ params.nil? ? false : params.last
74
+ end
75
+
76
+ def full_trace_for(symbol)
77
+ @tracer.select{|array| array[0] == symbol}.map(&:last)
78
+ end
79
+
80
+ def clear()
81
+ @tracer.clear()
82
+ end
83
+ end
84
+
85
+ class JoinlinesLogTracer < TracerBase
86
+ def warn(*args) @tracer.push [:warn, args]; end
87
+ def error(*args) @tracer.push [:error, args]; end
88
+ def debug(*args) @tracer.push [:debug, args]; end
89
+ def info(*args) @tracer.push [:info, args]; end
90
+ def trace(*args) @tracer.push [:trace, args]; end
91
+
92
+ def info?() true; end
93
+ def debug?() true; end
94
+ def warn?() true; end
95
+ def error?() true; end
96
+ def trace?() true; end
97
+ end
98
+
99
+ class AutoFlushTracer < TracerBase
100
+ def auto_flush() simulate_execution_delay; @tracer.push [:auto_flush, true]; end
101
+ def set_delay(delay)
102
+ @delay = delay
103
+ end
104
+
105
+ def simulate_execution_delay
106
+ return if @delay.nil? || @delay.zero?
107
+ sleep @delay
108
+ @tracer.push [:delay, Time.now.to_f]
109
+ end
110
+ end
111
+
112
+ class IdentityMapCodecTracer < TracerBase
113
+ def clone() self.class.new; end
114
+ def decode(data) @tracer.push [:decode, data]; end
115
+ def encode(event) @tracer.push [:encode, event]; end
116
+ def flush(&block) @tracer.push [:flush, block.call]; end
117
+ def close() @tracer.push [:close, true]; end
118
+ def logger() @logger ||= JoinlinesLogTracer.new; end
119
+ end
120
+ end
121
+
122
+ RSpec::Matchers.define(:have_an_empty_buffer) do
123
+ match do |actual|
124
+ actual.buffer_size.zero?
125
+ end
126
+
127
+ failure_message do
128
+ "Expecting #{actual.buffer_size} to be 0"
129
+ end
130
+ end
131
+
132
+ RSpec::Matchers.define(:match_path_and_line) do |path, line|
133
+ match do |actual|
134
+ actual.get("path") == path && actual.get("message") == line.join($/)
135
+ end
136
+
137
+ failure_message do
138
+ "Expecting #{actual.get('path')} to equal `#{path}` and #{actual.get("message")} to equal #{line.join($/)}"
139
+ end
140
+ end
metadata ADDED
@@ -0,0 +1,132 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: logstash-codec-joinlines
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Svein L. Ellingsen (lovmoen)
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-05-05 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'
19
+ name: logstash-core-plugin-api
20
+ prerelease: false
21
+ type: :runtime
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ name: logstash-codec-line
34
+ prerelease: false
35
+ type: :runtime
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ requirement: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ name: logstash-patterns-core
48
+ prerelease: false
49
+ type: :runtime
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ requirement: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: 0.11.1
61
+ name: jls-grok
62
+ prerelease: false
63
+ type: :runtime
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.11.1
69
+ - !ruby/object:Gem::Dependency
70
+ requirement: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ name: logstash-devutils
76
+ prerelease: false
77
+ type: :development
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: This gem is a Logstash plugin required to be installed on top of the
84
+ Logstash core pipeline using $LS_HOME/bin/logstash-plugin install gemname. This
85
+ gem is not a stand-alone program
86
+ email: lovmoen@gmail.com
87
+ executables: []
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - CHANGELOG.md
92
+ - CONTRIBUTORS
93
+ - DEVELOPER.md
94
+ - Gemfile
95
+ - LICENSE
96
+ - README.md
97
+ - lib/logstash/codecs/auto_flush.rb
98
+ - lib/logstash/codecs/identity_map_codec.rb
99
+ - lib/logstash/codecs/joinlines.rb
100
+ - lib/logstash/codecs/retriggerable_task.rb
101
+ - logstash-codec-joinlines.gemspec
102
+ - spec/codecs/joinlines_spec.rb
103
+ - spec/spec_helper.rb
104
+ homepage: https://github.com/lovmoen/logstash-codec-joinlines
105
+ licenses:
106
+ - Apache-2.0
107
+ metadata:
108
+ logstash_plugin: 'true'
109
+ logstash_group: codec
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
+ rubyforge_project:
126
+ rubygems_version: 2.7.6
127
+ signing_key:
128
+ specification_version: 4
129
+ summary: Merges multiline messages into a single event, allowing for multiple patterns.
130
+ test_files:
131
+ - spec/codecs/joinlines_spec.rb
132
+ - spec/spec_helper.rb