fluent-plugin-windows-eventlog 0.1.0

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: 182e98e93e8d43f333025671ae6698ccddefd580
4
+ data.tar.gz: fdeda6fa7866b56938cfa714a0025aae635453ef
5
+ SHA512:
6
+ metadata.gz: 7e46f28f6814ed735edb7db078a5784614f4e620457f1082737496b6ae80188168ed8dd5f3a5233e0ec66a261fb26a5519fc172f6821ab170c11d45ebd9568c1
7
+ data.tar.gz: dcb0c4be720f231921fb7dfa5430563c96cf31b392661086e2e328e2c3d4e42412328258cceb3b062b5ab4db7563a159874c4b9d75f5b159cbd474e7b8b6a627
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /spec/reports/
8
+ pkg/*
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in fluent-plugin-winevtlog.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,203 @@
1
+ Copyright (c) 2014 okahashi117
2
+
3
+ Apache License
4
+ Version 2.0, January 2004
5
+ http://www.apache.org/licenses/
6
+
7
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
8
+
9
+ 1. Definitions.
10
+
11
+ "License" shall mean the terms and conditions for use, reproduction,
12
+ and distribution as defined by Sections 1 through 9 of this document.
13
+
14
+ "Licensor" shall mean the copyright owner or entity authorized by
15
+ the copyright owner that is granting the License.
16
+
17
+ "Legal Entity" shall mean the union of the acting entity and all
18
+ other entities that control, are controlled by, or are under common
19
+ control with that entity. For the purposes of this definition,
20
+ "control" means (i) the power, direct or indirect, to cause the
21
+ direction or management of such entity, whether by contract or
22
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
23
+ outstanding shares, or (iii) beneficial ownership of such entity.
24
+
25
+ "You" (or "Your") shall mean an individual or Legal Entity
26
+ exercising permissions granted by this License.
27
+
28
+ "Source" form shall mean the preferred form for making modifications,
29
+ including but not limited to software source code, documentation
30
+ source, and configuration files.
31
+
32
+ "Object" form shall mean any form resulting from mechanical
33
+ transformation or translation of a Source form, including but
34
+ not limited to compiled object code, generated documentation,
35
+ and conversions to other media types.
36
+
37
+ "Work" shall mean the work of authorship, whether in Source or
38
+ Object form, made available under the License, as indicated by a
39
+ copyright notice that is included in or attached to the work
40
+ (an example is provided in the Appendix below).
41
+
42
+ "Derivative Works" shall mean any work, whether in Source or Object
43
+ form, that is based on (or derived from) the Work and for which the
44
+ editorial revisions, annotations, elaborations, or other modifications
45
+ represent, as a whole, an original work of authorship. For the purposes
46
+ of this License, Derivative Works shall not include works that remain
47
+ separable from, or merely link (or bind by name) to the interfaces of,
48
+ the Work and Derivative Works thereof.
49
+
50
+ "Contribution" shall mean any work of authorship, including
51
+ the original version of the Work and any modifications or additions
52
+ to that Work or Derivative Works thereof, that is intentionally
53
+ submitted to Licensor for inclusion in the Work by the copyright owner
54
+ or by an individual or Legal Entity authorized to submit on behalf of
55
+ the copyright owner. For the purposes of this definition, "submitted"
56
+ means any form of electronic, verbal, or written communication sent
57
+ to the Licensor or its representatives, including but not limited to
58
+ communication on electronic mailing lists, source code control systems,
59
+ and issue tracking systems that are managed by, or on behalf of, the
60
+ Licensor for the purpose of discussing and improving the Work, but
61
+ excluding communication that is conspicuously marked or otherwise
62
+ designated in writing by the copyright owner as "Not a Contribution."
63
+
64
+ "Contributor" shall mean Licensor and any individual or Legal Entity
65
+ on behalf of whom a Contribution has been received by Licensor and
66
+ subsequently incorporated within the Work.
67
+
68
+ 2. Grant of Copyright License. Subject to the terms and conditions of
69
+ this License, each Contributor hereby grants to You a perpetual,
70
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
71
+ copyright license to reproduce, prepare Derivative Works of,
72
+ publicly display, publicly perform, sublicense, and distribute the
73
+ Work and such Derivative Works in Source or Object form.
74
+
75
+ 3. Grant of Patent License. Subject to the terms and conditions of
76
+ this License, each Contributor hereby grants to You a perpetual,
77
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
78
+ (except as stated in this section) patent license to make, have made,
79
+ use, offer to sell, sell, import, and otherwise transfer the Work,
80
+ where such license applies only to those patent claims licensable
81
+ by such Contributor that are necessarily infringed by their
82
+ Contribution(s) alone or by combination of their Contribution(s)
83
+ with the Work to which such Contribution(s) was submitted. If You
84
+ institute patent litigation against any entity (including a
85
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
86
+ or a Contribution incorporated within the Work constitutes direct
87
+ or contributory patent infringement, then any patent licenses
88
+ granted to You under this License for that Work shall terminate
89
+ as of the date such litigation is filed.
90
+
91
+ 4. Redistribution. You may reproduce and distribute copies of the
92
+ Work or Derivative Works thereof in any medium, with or without
93
+ modifications, and in Source or Object form, provided that You
94
+ meet the following conditions:
95
+
96
+ (a) You must give any other recipients of the Work or
97
+ Derivative Works a copy of this License; and
98
+
99
+ (b) You must cause any modified files to carry prominent notices
100
+ stating that You changed the files; and
101
+
102
+ (c) You must retain, in the Source form of any Derivative Works
103
+ that You distribute, all copyright, patent, trademark, and
104
+ attribution notices from the Source form of the Work,
105
+ excluding those notices that do not pertain to any part of
106
+ the Derivative Works; and
107
+
108
+ (d) If the Work includes a "NOTICE" text file as part of its
109
+ distribution, then any Derivative Works that You distribute must
110
+ include a readable copy of the attribution notices contained
111
+ within such NOTICE file, excluding those notices that do not
112
+ pertain to any part of the Derivative Works, in at least one
113
+ of the following places: within a NOTICE text file distributed
114
+ as part of the Derivative Works; within the Source form or
115
+ documentation, if provided along with the Derivative Works; or,
116
+ within a display generated by the Derivative Works, if and
117
+ wherever such third-party notices normally appear. The contents
118
+ of the NOTICE file are for informational purposes only and
119
+ do not modify the License. You may add Your own attribution
120
+ notices within Derivative Works that You distribute, alongside
121
+ or as an addendum to the NOTICE text from the Work, provided
122
+ that such additional attribution notices cannot be construed
123
+ as modifying the License.
124
+
125
+ You may add Your own copyright statement to Your modifications and
126
+ may provide additional or different license terms and conditions
127
+ for use, reproduction, or distribution of Your modifications, or
128
+ for any such Derivative Works as a whole, provided Your use,
129
+ reproduction, and distribution of the Work otherwise complies with
130
+ the conditions stated in this License.
131
+
132
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
133
+ any Contribution intentionally submitted for inclusion in the Work
134
+ by You to the Licensor shall be under the terms and conditions of
135
+ this License, without any additional terms or conditions.
136
+ Notwithstanding the above, nothing herein shall supersede or modify
137
+ the terms of any separate license agreement you may have executed
138
+ with Licensor regarding such Contributions.
139
+
140
+ 6. Trademarks. This License does not grant permission to use the trade
141
+ names, trademarks, service marks, or product names of the Licensor,
142
+ except as required for reasonable and customary use in describing the
143
+ origin of the Work and reproducing the content of the NOTICE file.
144
+
145
+ 7. Disclaimer of Warranty. Unless required by applicable law or
146
+ agreed to in writing, Licensor provides the Work (and each
147
+ Contributor provides its Contributions) on an "AS IS" BASIS,
148
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
149
+ implied, including, without limitation, any warranties or conditions
150
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
151
+ PARTICULAR PURPOSE. You are solely responsible for determining the
152
+ appropriateness of using or redistributing the Work and assume any
153
+ risks associated with Your exercise of permissions under this License.
154
+
155
+ 8. Limitation of Liability. In no event and under no legal theory,
156
+ whether in tort (including negligence), contract, or otherwise,
157
+ unless required by applicable law (such as deliberate and grossly
158
+ negligent acts) or agreed to in writing, shall any Contributor be
159
+ liable to You for damages, including any direct, indirect, special,
160
+ incidental, or consequential damages of any character arising as a
161
+ result of this License or out of the use or inability to use the
162
+ Work (including but not limited to damages for loss of goodwill,
163
+ work stoppage, computer failure or malfunction, or any and all
164
+ other commercial damages or losses), even if such Contributor
165
+ has been advised of the possibility of such damages.
166
+
167
+ 9. Accepting Warranty or Additional Liability. While redistributing
168
+ the Work or Derivative Works thereof, You may choose to offer,
169
+ and charge a fee for, acceptance of support, warranty, indemnity,
170
+ or other liability obligations and/or rights consistent with this
171
+ License. However, in accepting such obligations, You may act only
172
+ on Your own behalf and on Your sole responsibility, not on behalf
173
+ of any other Contributor, and only if You agree to indemnify,
174
+ defend, and hold each Contributor harmless for any liability
175
+ incurred by, or claims asserted against, such Contributor by reason
176
+ of your accepting any such warranty or additional liability.
177
+
178
+ END OF TERMS AND CONDITIONS
179
+
180
+ APPENDIX: How to apply the Apache License to your work.
181
+
182
+ To apply the Apache License to your work, attach the following
183
+ boilerplate notice, with the fields enclosed by brackets "{}"
184
+ replaced with your own identifying information. (Don't include
185
+ the brackets!) The text should be enclosed in the appropriate
186
+ comment syntax for the file format. We also recommend that a
187
+ file or class name and description of purpose be included on the
188
+ same "printed page" as the copyright notice for easier
189
+ identification within third-party archives.
190
+
191
+ Copyright {yyyy} {name of copyright owner}
192
+
193
+ Licensed under the Apache License, Version 2.0 (the "License");
194
+ you may not use this file except in compliance with the License.
195
+ You may obtain a copy of the License at
196
+
197
+ http://www.apache.org/licenses/LICENSE-2.0
198
+
199
+ Unless required by applicable law or agreed to in writing, software
200
+ distributed under the License is distributed on an "AS IS" BASIS,
201
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
202
+ See the License for the specific language governing permissions and
203
+ limitations under the License.
data/README.md ADDED
@@ -0,0 +1,66 @@
1
+ # fluent-plugin-windows-eventlog
2
+
3
+ ## Component
4
+
5
+ #### fluentd Input plugin for Windows Event Log
6
+
7
+ [Fluentd](http://fluentd.org) plugin to read Windows Event Log.
8
+ You must use fluentd 'Windows' brach to use me, and it doesn't work on Linux of course.
9
+
10
+ ## Installation
11
+ gem install fluent-plugin-windows-eventlog
12
+
13
+ ## Configuration
14
+ #### fluentd Input plugin for Windows Event Log
15
+
16
+ <source>
17
+ type windows_eventlog
18
+ channels application,system
19
+ pos_file c:\temp\mypos
20
+ read_interval 2
21
+ tag winevt.raw
22
+ </source>
23
+
24
+
25
+ #### parameters
26
+
27
+ |name | description |
28
+ |:----- |:----- |
29
+ |channels | (option) 'applicaion' as default. one or combination of {application, system, setup, security}. If you want to read setup or security, administrator priv is required to launch fluentd. |
30
+ |pos_file | (option, but higly recommended) a path of position file to save record numbers. |
31
+ |read_interval | (option) a read interval in second. 2 seconds as default.|
32
+ |from_encoding | (option) an input characters encoding. nil as default.|
33
+ |encoding | (option) an output characters encoding. nil as default.|
34
+
35
+
36
+ #### read keys
37
+ This plugin reads follows from Windws Event Log. No customization is allowed currently.
38
+
39
+ |key|
40
+ |:----- |
41
+ |record_number |
42
+ |time_generated|
43
+ |time_written |
44
+ |event_id |
45
+ |event_type |
46
+ |event_category |
47
+ |source_name |
48
+ |computer_name |
49
+ |user |
50
+ |description |
51
+
52
+
53
+
54
+ ## Etc.
55
+ 'read_from_head' is not supporeted currently.You can read newer records after you start first.
56
+ No customize to read information keys.
57
+
58
+
59
+
60
+
61
+ ## Copyright
62
+ ####Copyright
63
+ Copyright(C) 2014- @okahashi117
64
+ ####License
65
+ Apache License, Version 2.0
66
+
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |test|
5
+ test.libs << 'lib' << 'test'
6
+ test.pattern = 'test/**/test_*.rb'
7
+ test.verbose = true
8
+ end
9
+
10
+ task default: :test
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "fluent-plugin-windows-eventlog"
7
+ spec.version = "0.1.0"
8
+ spec.authors = ["okahashi117", "Hiroshi Hatake", "Masahiro Nakagawa"]
9
+ spec.email = ["naruki_okahashi@jbat.co.jp", "cosmo0920.wp@gmail.com", "repeatedly@gmail.com"]
10
+ spec.summary = %q{Fluentd Input plugin to read windows event log.}
11
+ spec.description = %q{Fluentd Input plugin to read windwos event log.}
12
+ spec.homepage = "https://github.com/fluent/fluent-plugin-windows-eventlog"
13
+ spec.license = "Apache-2.0"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0")
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_development_dependency "bundler"
21
+ spec.add_development_dependency "rake"
22
+ spec.add_development_dependency "test-unit", "~> 3.2.0"
23
+ spec.add_runtime_dependency "fluentd", [">= 0.14.11", "< 2"]
24
+ spec.add_runtime_dependency "win32-eventlog"
25
+ end
@@ -0,0 +1,320 @@
1
+ require 'win32/eventlog'
2
+ require 'fluent/plugin/input'
3
+ require 'fluent/plugin'
4
+
5
+ module Fluent::Plugin
6
+ class WindowsEventLogInput < Input
7
+ Fluent::Plugin.register_input('windows_eventlog', self)
8
+
9
+ helpers :timer
10
+
11
+ KEY_MAP = {"record_number" => :record_number,
12
+ "time_generated" => :time_generated,
13
+ "time_written" => :time_written,
14
+ "event_id" => :event_id,
15
+ "event_type" => :event_type,
16
+ "event_category" => :category,
17
+ "source_name" => :source,
18
+ "computer_name" => :computer,
19
+ "user" => :user,
20
+ "description" => :description}
21
+
22
+ config_param :tag, :string
23
+ config_param :read_interval, :time, default: 2
24
+ config_param :pos_file, :string, default: nil
25
+ config_param :channels, :array, default: ['Application']
26
+ config_param :keys, :string, default: []
27
+ config_param :read_from_head, :bool, default: false
28
+ config_param :from_encoding, :string, default: nil
29
+ config_param :encoding, :string, default: nil
30
+
31
+ attr_reader :chs
32
+
33
+ def initialize
34
+ super
35
+ @chs = []
36
+ @keynames = []
37
+ @tails = {}
38
+ end
39
+
40
+ def configure(conf)
41
+ super
42
+ @chs = @channels.map {|ch| ch.strip.downcase }.uniq
43
+ if @chs.empty?
44
+ raise Fluent::ConfigError, "windows_eventlog: 'channels' parameter is required on windows_eventlog input"
45
+ end
46
+ @keynames = @keys.map {|k| k.strip }.uniq
47
+ if @keynames.empty?
48
+ @keynames = KEY_MAP.keys
49
+ end
50
+ @tag = tag
51
+ @stop = false
52
+ configure_encoding
53
+ @receive_handlers = if @encoding
54
+ method(:encode_record)
55
+ else
56
+ method(:no_encode_record)
57
+ end
58
+ end
59
+
60
+ def configure_encoding
61
+ unless @encoding
62
+ if @from_encoding
63
+ raise Fluent::ConfigError, "windows_eventlog: 'from_encoding' parameter must be specied with 'encoding' parameter."
64
+ end
65
+ end
66
+
67
+ @encoding = parse_encoding_param(@encoding) if @encoding
68
+ @from_encoding = parse_encoding_param(@from_encoding) if @from_encoding
69
+ end
70
+
71
+ def parse_encoding_param(encoding_name)
72
+ begin
73
+ Encoding.find(encoding_name) if encoding_name
74
+ rescue ArgumentError => e
75
+ raise Fluent::ConfigError, e.message
76
+ end
77
+ end
78
+
79
+ def encode_record(record)
80
+ if @encoding
81
+ if @from_encoding
82
+ record.encode!(@encoding, @from_encoding)
83
+ else
84
+ record.force_encoding(@encoding)
85
+ end
86
+ end
87
+ end
88
+
89
+ def no_encode_record(record)
90
+ record
91
+ end
92
+
93
+ def start
94
+ super
95
+ if @pos_file
96
+ @pf_file = File.open(@pos_file, File::RDWR|File::CREAT|File::BINARY)
97
+ @pf_file.sync = true
98
+ @pf = PositionFile.parse(@pf_file)
99
+ end
100
+ start_watchers(@chs)
101
+ end
102
+
103
+ def shutdown
104
+ stop_watchers(@tails.keys, true)
105
+ @pf_file.close if @pf_file
106
+ super
107
+ end
108
+
109
+ def setup_wacther(ch, pe)
110
+ wlw = WindowsLogWatcher.new(ch, pe, &method(:receive_lines))
111
+ wlw.attach do |watcher|
112
+ wlw.timer_trigger = timer_execute(:in_winevtlog, @read_interval, &watcher.method(:on_notify))
113
+ end
114
+ wlw
115
+ end
116
+
117
+ def start_watchers(chs)
118
+ chs.each { |ch|
119
+ pe = nil
120
+ if @pf
121
+ pe = @pf[ch]
122
+ if @read_from_head && pe.read_num.zero?
123
+ el = Win32::EventLog.open(ch)
124
+ pe.update(el.oldest_record_number-1,1)
125
+ el.close
126
+ end
127
+ end
128
+ @tails[ch] = setup_wacther(ch, pe)
129
+ }
130
+ end
131
+
132
+ def stop_watchers(chs, unwatched = false)
133
+ chs.each { |ch|
134
+ wlw = @tails.delete(ch)
135
+ if wlw
136
+ wlw.unwatched = unwatched
137
+ close_watcher(wlw)
138
+ end
139
+ }
140
+ end
141
+
142
+ def close_watcher(wlw)
143
+ wlw.close
144
+ # flush_buffer(wlw)
145
+ end
146
+
147
+ def receive_lines(ch, lines, pe)
148
+ return if lines.empty?
149
+ begin
150
+ for r in lines
151
+ h = {"channel" => ch}
152
+ @keynames.each {|k| h[k]=@receive_handlers.call(r.send(KEY_MAP[k]).to_s)}
153
+ #h = Hash[@keynames.map {|k| [k, r.send(KEY_MAP[k]).to_s]}]
154
+ router.emit(@tag, Fluent::Engine.now, h)
155
+ pe[1] +=1
156
+ end
157
+ rescue
158
+ $log.error "unexpected error", error: $!.to_s
159
+ $log.error_backtrace
160
+ end
161
+ end
162
+
163
+
164
+ class WindowsLogWatcher
165
+ def initialize(ch, pe, &receive_lines)
166
+ @ch = ch
167
+ @pe = pe || MemoryPositionEntry.new
168
+ @receive_lines = receive_lines
169
+ @timer_trigger = nil
170
+ end
171
+
172
+ attr_reader :ch
173
+ attr_accessor :unwatched
174
+ attr_accessor :pe
175
+ attr_accessor :timer_trigger
176
+
177
+ def attach
178
+ yield self
179
+ on_notify
180
+ end
181
+
182
+ def detach
183
+ @timer_trigger.detach if @timer_trigger.attached?
184
+ end
185
+
186
+ def close
187
+ detach
188
+ end
189
+
190
+ def on_notify
191
+ el = Win32::EventLog.open(@ch)
192
+ rl_sn = [el.oldest_record_number, el.total_records]
193
+ pe_sn = [@pe.read_start, @pe.read_num]
194
+ # if total_records is zero, oldest_record_number has no meaning.
195
+ if rl_sn[1] == 0
196
+ return
197
+ end
198
+
199
+ if pe_sn[0] == 0 && pe_sn[1] == 0
200
+ @pe.update(rl_sn[0], rl_sn[1])
201
+ return
202
+ end
203
+
204
+ cur_end = rl_sn[0] + rl_sn[1] -1
205
+ old_end = pe_sn[0] + pe_sn[1] -1
206
+
207
+ if (rl_sn[0] < pe_sn[0])
208
+ # may be a record number rotated.
209
+ cur_end += 0xFFFFFFFF
210
+ end
211
+
212
+ if (cur_end < old_end)
213
+ # something occured.
214
+ @pe.update(rl_sn[0], rl_sn[1])
215
+ return
216
+ end
217
+
218
+ read_more = false
219
+ begin
220
+ numlines = cur_end - old_end
221
+
222
+ winlogs = el.read(Win32::EventLog::SEEK_READ | Win32::EventLog::FORWARDS_READ, old_end + 1)
223
+ @receive_lines.call(@ch, winlogs, pe_sn)
224
+
225
+ @pe.update(pe_sn[0], pe_sn[1])
226
+ old_end = pe_sn[0] + pe_sn[1] -1
227
+ end while read_more
228
+ el.close
229
+ end
230
+ end
231
+
232
+ class PositionFile
233
+ def initialize(file, map, last_pos)
234
+ @file = file
235
+ @map = map
236
+ @last_pos = last_pos
237
+ end
238
+
239
+ def [](ch)
240
+ if m = @map[ch]
241
+ return m
242
+ end
243
+ @file.pos = @last_pos
244
+ @file.write ch
245
+ @file.write "\t"
246
+ seek = @file.pos
247
+ @file.write "00000000\t00000000\n"
248
+ @last_pos = @file.pos
249
+ @map[ch] = FilePositionEntry.new(@file, seek)
250
+ end
251
+
252
+ # parsing file and rebuild mysself
253
+ def self.parse(file)
254
+ map = {}
255
+ file.pos = 0
256
+ file.each_line {|line|
257
+ # check and get a matched line as m
258
+ m = /^([^\t]+)\t([0-9a-fA-F]+)\t([0-9a-fA-F]+)/.match(line)
259
+ next unless m
260
+ ch = m[1]
261
+ pos = m[2].to_i(16)
262
+ seek = file.pos - line.bytesize + ch.bytesize + 1
263
+ map[ch] = FilePositionEntry.new(file, seek)
264
+ }
265
+ new(file, map, file.pos)
266
+ end
267
+ end
268
+
269
+ class FilePositionEntry
270
+ START_SIZE = 8
271
+ NUM_OFFSET = 9
272
+ NUM_SIZE = 8
273
+ LN_OFFSET = 17
274
+ SIZE = 18
275
+
276
+ def initialize(file, seek)
277
+ @file = file
278
+ @seek = seek
279
+ end
280
+
281
+ def update(start, num)
282
+ @file.pos = @seek
283
+ @file.write "%08x\t%08x" % [start, num]
284
+ end
285
+
286
+ def read_start
287
+ @file.pos = @seek
288
+ raw = @file.read(START_SIZE)
289
+ raw ? raw.to_i(16) : 0
290
+ end
291
+
292
+ def read_num
293
+ @file.pos = @seek + NUM_OFFSET
294
+ raw = @file.read(NUM_SIZE)
295
+ raw ? raw.to_i(16) : 0
296
+ end
297
+ end
298
+
299
+ class MemoryPositionEntry
300
+ def initialize
301
+ @start = 0
302
+ @num = 0
303
+ end
304
+
305
+ def update(start, num)
306
+ @start = start
307
+ @num = num
308
+ end
309
+
310
+ def read_start
311
+ @start
312
+ end
313
+
314
+ def read_num
315
+ @num
316
+ end
317
+ end
318
+
319
+ end
320
+ end
data/test/helper.rb ADDED
@@ -0,0 +1,29 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'test/unit'
11
+
12
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
13
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
14
+ require 'fluent/test'
15
+ unless ENV.has_key?('VERBOSE')
16
+ nulllogger = Object.new
17
+ nulllogger.instance_eval {|obj|
18
+ def method_missing(method, *args)
19
+ # pass
20
+ end
21
+ }
22
+ $log = nulllogger
23
+ end
24
+
25
+ require 'fluent/test/driver/input'
26
+ require 'fluent/plugin/in_windows_eventlog'
27
+
28
+ class Test::Unit::TestCase
29
+ end
@@ -0,0 +1,51 @@
1
+ require 'helper'
2
+
3
+ class WindowsEventLogInputTest < Test::Unit::TestCase
4
+ def setup
5
+ Fluent::Test.setup
6
+ end
7
+
8
+ CONFIG = %[
9
+ tag fluent.eventlog
10
+ ]
11
+
12
+ def create_driver(conf = CONFIG)
13
+ Fluent::Test::Driver::Input.new(Fluent::Plugin::WindowsEventLogInput).configure(conf)
14
+ end
15
+
16
+ def test_configure
17
+ d = create_driver CONFIG
18
+ assert_equal 'fluent.eventlog', d.instance.tag
19
+ assert_equal 2, d.instance.read_interval
20
+ assert_nil d.instance.pos_file
21
+ assert_equal ['Application'], d.instance.channels
22
+ assert_true d.instance.keys.empty?
23
+ assert_false d.instance.read_from_head
24
+ end
25
+
26
+ def test_format
27
+ d = create_driver
28
+
29
+ # time = Time.parse("2011-01-02 13:14:15 UTC").to_i
30
+ # d.emit({"a"=>1}, time)
31
+ # d.emit({"a"=>2}, time)
32
+
33
+ # d.expect_format %[2011-01-02T13:14:15Z\ttest\t{"a":1}\n]
34
+ # d.expect_format %[2011-01-02T13:14:15Z\ttest\t{"a":2}\n]
35
+
36
+ # d.run
37
+ end
38
+
39
+ def test_write
40
+ d = create_driver
41
+
42
+ # time = Time.parse("2011-01-02 13:14:15 UTC").to_i
43
+ # d.emit({"a"=>1}, time)
44
+ # d.emit({"a"=>2}, time)
45
+
46
+ # ### FileOutput#write returns path
47
+ # path = d.run
48
+ # expect_path = "#{TMP_DIR}/out_file_test._0.log.gz"
49
+ # assert_equal expect_path, path
50
+ end
51
+ end
metadata ADDED
@@ -0,0 +1,135 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fluent-plugin-windows-eventlog
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - okahashi117
8
+ - Hiroshi Hatake
9
+ - Masahiro Nakagawa
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2017-01-23 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: bundler
17
+ requirement: !ruby/object:Gem::Requirement
18
+ requirements:
19
+ - - ">="
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ version: '0'
29
+ - !ruby/object:Gem::Dependency
30
+ name: rake
31
+ requirement: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - ">="
34
+ - !ruby/object:Gem::Version
35
+ version: '0'
36
+ type: :development
37
+ prerelease: false
38
+ version_requirements: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: '0'
43
+ - !ruby/object:Gem::Dependency
44
+ name: test-unit
45
+ requirement: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - "~>"
48
+ - !ruby/object:Gem::Version
49
+ version: 3.2.0
50
+ type: :development
51
+ prerelease: false
52
+ version_requirements: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - "~>"
55
+ - !ruby/object:Gem::Version
56
+ version: 3.2.0
57
+ - !ruby/object:Gem::Dependency
58
+ name: fluentd
59
+ requirement: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: 0.14.11
64
+ - - "<"
65
+ - !ruby/object:Gem::Version
66
+ version: '2'
67
+ type: :runtime
68
+ prerelease: false
69
+ version_requirements: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: 0.14.11
74
+ - - "<"
75
+ - !ruby/object:Gem::Version
76
+ version: '2'
77
+ - !ruby/object:Gem::Dependency
78
+ name: win32-eventlog
79
+ requirement: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ type: :runtime
85
+ prerelease: false
86
+ version_requirements: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ description: Fluentd Input plugin to read windwos event log.
92
+ email:
93
+ - naruki_okahashi@jbat.co.jp
94
+ - cosmo0920.wp@gmail.com
95
+ - repeatedly@gmail.com
96
+ executables: []
97
+ extensions: []
98
+ extra_rdoc_files: []
99
+ files:
100
+ - ".gitignore"
101
+ - Gemfile
102
+ - LICENSE.txt
103
+ - README.md
104
+ - Rakefile
105
+ - fluent-plugin-winevtlog.gemspec
106
+ - lib/fluent/plugin/in_windows_eventlog.rb
107
+ - test/helper.rb
108
+ - test/plugin/test_in_winevtlog.rb
109
+ homepage: https://github.com/fluent/fluent-plugin-windows-eventlog
110
+ licenses:
111
+ - Apache-2.0
112
+ metadata: {}
113
+ post_install_message:
114
+ rdoc_options: []
115
+ require_paths:
116
+ - lib
117
+ required_ruby_version: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - ">="
120
+ - !ruby/object:Gem::Version
121
+ version: '0'
122
+ required_rubygems_version: !ruby/object:Gem::Requirement
123
+ requirements:
124
+ - - ">="
125
+ - !ruby/object:Gem::Version
126
+ version: '0'
127
+ requirements: []
128
+ rubyforge_project:
129
+ rubygems_version: 2.6.8
130
+ signing_key:
131
+ specification_version: 4
132
+ summary: Fluentd Input plugin to read windows event log.
133
+ test_files:
134
+ - test/helper.rb
135
+ - test/plugin/test_in_winevtlog.rb