fluent-plugin-windows-eventlog 0.1.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +32 -35
- data/appveyor.yml +27 -0
- data/fluent-plugin-winevtlog.gemspec +3 -3
- data/lib/fluent/plugin/in_windows_eventlog.rb +78 -211
- data/test/generate-windows-event.rb +47 -0
- data/test/helper.rb +3 -0
- data/test/plugin/test_in_winevtlog.rb +21 -24
- metadata +9 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 44561910d111a16a85de6b5d9faee8cf052fed71
|
4
|
+
data.tar.gz: 2bc58308403d20000efe50f2b6f73e86a9a6585a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 194172daa6b8dd788a785d89e392e3698fe7ed6b8ffa0de360ddc89bf2bd9d37818d8abd43bf5c6e71434cffdd603a91126f674ab80c45455aeffe969a5101c2
|
7
|
+
data.tar.gz: 2b45ac6f8ce1c4d142ce1aae21104945c2bdb706db26c57eb6f9a0e2ef90ba468a7b3fd5172242817c6e43f3b1575b2167bcd5f65ebd52600f4f461f3c0780ad
|
data/README.md
CHANGED
@@ -2,65 +2,62 @@
|
|
2
2
|
|
3
3
|
## Component
|
4
4
|
|
5
|
-
#### fluentd Input plugin for Windows Event Log
|
5
|
+
#### fluentd Input plugin for the Windows Event Log
|
6
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.
|
7
|
+
[Fluentd](http://fluentd.org) plugin to read the Windows Event Log.
|
9
8
|
|
10
9
|
## Installation
|
11
10
|
gem install fluent-plugin-windows-eventlog
|
12
11
|
|
13
12
|
## Configuration
|
14
|
-
#### fluentd Input plugin for Windows Event Log
|
13
|
+
#### fluentd Input plugin for the Windows Event Log
|
15
14
|
|
16
15
|
<source>
|
17
|
-
type windows_eventlog
|
16
|
+
@type windows_eventlog
|
17
|
+
@id windows_eventlog
|
18
18
|
channels application,system
|
19
|
-
pos_file c:\temp\mypos
|
20
19
|
read_interval 2
|
21
20
|
tag winevt.raw
|
21
|
+
<storage>
|
22
|
+
@type local # @type local is the default.
|
23
|
+
persistent true # default is true. Set to false to use in-memory storage.
|
24
|
+
path ./tmp/storage.json # This is required when persistent is true.
|
25
|
+
# Or, please consider using <system> section's `root_dir` parameter.
|
26
|
+
</storage>
|
22
27
|
</source>
|
23
28
|
|
24
|
-
|
25
29
|
#### parameters
|
26
30
|
|
27
31
|
|name | description |
|
28
32
|
|:----- |:----- |
|
29
|
-
|
30
|
-
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
33
|
+
|`channels` | (option) 'application' as default. One or more of {'application', 'system', 'setup', 'security'}. If you want to read 'setup' or 'security' logs, you must launch fluentd with administrator privileges.|
|
34
|
+
|`keys` | (option) A subset of [keys](#read-keys) to read. Defaults to all keys.|
|
35
|
+
|`read_interval` | (option) Read interval in seconds. 2 seconds as default.|
|
36
|
+
|`from_encoding` | (option) Input character encoding. `nil` as default.|
|
37
|
+
|`encoding` | (option) Output character encoding. `nil` as default.|
|
38
|
+
|`read_from_head`| (option) Start to read the entries from the oldest, not from when fluentd is started. Defaults to `false`.|
|
39
|
+
|`<storage>` | Setting for `storage` plugin for recording read position like `in_tail`'s `pos_file`.|
|
35
40
|
|
36
41
|
#### read keys
|
37
|
-
This plugin reads
|
42
|
+
This plugin reads the following fields from Windows Event Log entries. Use the `keys` configuration option to select a subset. No other customization is allowed for now.
|
38
43
|
|
39
44
|
|key|
|
40
45
|
|:----- |
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
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
|
-
|
46
|
+
|`record_number` |
|
47
|
+
|`time_generated`|
|
48
|
+
|`time_written` |
|
49
|
+
|`event_id` |
|
50
|
+
|`event_type` |
|
51
|
+
|`event_category`|
|
52
|
+
|`source_name` |
|
53
|
+
|`computer_name` |
|
54
|
+
|`user` |
|
55
|
+
|`description` |
|
56
|
+
|`string_inserts`|
|
60
57
|
|
61
58
|
## Copyright
|
62
|
-
####Copyright
|
59
|
+
#### Copyright
|
63
60
|
Copyright(C) 2014- @okahashi117
|
64
|
-
####License
|
61
|
+
#### License
|
65
62
|
Apache License, Version 2.0
|
66
63
|
|
data/appveyor.yml
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
version: '{build}'
|
2
|
+
|
3
|
+
# init:
|
4
|
+
# - ps: iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/appveyor/ci/master/scripts/enable-rdp.ps1'))
|
5
|
+
|
6
|
+
install:
|
7
|
+
- SET PATH=C:\Ruby%ruby_version%\bin;%PATH%
|
8
|
+
- "%devkit%\\devkitvars.bat"
|
9
|
+
- ruby --version
|
10
|
+
- gem --version
|
11
|
+
- bundle install
|
12
|
+
build: off
|
13
|
+
test_script:
|
14
|
+
- bundle exec rake test
|
15
|
+
# - bundle exec rake test TESTOPTS=-v
|
16
|
+
|
17
|
+
branches:
|
18
|
+
only:
|
19
|
+
- master
|
20
|
+
|
21
|
+
# https://www.appveyor.com/docs/installed-software/#ruby
|
22
|
+
environment:
|
23
|
+
matrix:
|
24
|
+
- ruby_version: "23-x64"
|
25
|
+
devkit: C:\Ruby23-x64\DevKit
|
26
|
+
- ruby_version: "23"
|
27
|
+
devkit: C:\Ruby23\DevKit
|
@@ -4,9 +4,9 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
|
5
5
|
Gem::Specification.new do |spec|
|
6
6
|
spec.name = "fluent-plugin-windows-eventlog"
|
7
|
-
spec.version = "0.1
|
7
|
+
spec.version = "0.2.1"
|
8
8
|
spec.authors = ["okahashi117", "Hiroshi Hatake", "Masahiro Nakagawa"]
|
9
|
-
spec.email = ["naruki_okahashi@jbat.co.jp", "cosmo0920.
|
9
|
+
spec.email = ["naruki_okahashi@jbat.co.jp", "cosmo0920.oucc@gmail.com", "repeatedly@gmail.com"]
|
10
10
|
spec.summary = %q{Fluentd Input plugin to read windows event log.}
|
11
11
|
spec.description = %q{Fluentd Input plugin to read windwos event log.}
|
12
12
|
spec.homepage = "https://github.com/fluent/fluent-plugin-windows-eventlog"
|
@@ -20,6 +20,6 @@ Gem::Specification.new do |spec|
|
|
20
20
|
spec.add_development_dependency "bundler"
|
21
21
|
spec.add_development_dependency "rake"
|
22
22
|
spec.add_development_dependency "test-unit", "~> 3.2.0"
|
23
|
-
spec.add_runtime_dependency "fluentd", [">= 0.14.
|
23
|
+
spec.add_runtime_dependency "fluentd", [">= 0.14.12", "< 2"]
|
24
24
|
spec.add_runtime_dependency "win32-eventlog"
|
25
25
|
end
|
@@ -6,28 +6,37 @@ module Fluent::Plugin
|
|
6
6
|
class WindowsEventLogInput < Input
|
7
7
|
Fluent::Plugin.register_input('windows_eventlog', self)
|
8
8
|
|
9
|
-
helpers :timer
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
"
|
14
|
-
"
|
15
|
-
"
|
16
|
-
"
|
17
|
-
"
|
18
|
-
"
|
19
|
-
"
|
20
|
-
"
|
9
|
+
helpers :timer, :storage
|
10
|
+
|
11
|
+
DEFAULT_STORAGE_TYPE = 'local'
|
12
|
+
KEY_MAP = {"record_number" => [:record_number, :string],
|
13
|
+
"time_generated" => [:time_generated, :string],
|
14
|
+
"time_written" => [:time_written, :string],
|
15
|
+
"event_id" => [:event_id, :string],
|
16
|
+
"event_type" => [:event_type, :string],
|
17
|
+
"event_category" => [:category, :string],
|
18
|
+
"source_name" => [:source, :string],
|
19
|
+
"computer_name" => [:computer, :string],
|
20
|
+
"user" => [:user, :string],
|
21
|
+
"description" => [:description, :string],
|
22
|
+
"string_inserts" => [:string_inserts, :array]}
|
21
23
|
|
22
24
|
config_param :tag, :string
|
23
25
|
config_param :read_interval, :time, default: 2
|
24
|
-
config_param :pos_file, :string, default: nil
|
25
|
-
|
26
|
-
config_param :
|
26
|
+
config_param :pos_file, :string, default: nil,
|
27
|
+
obsoleted: "This section is not used anymore. Use 'store_pos' instead."
|
28
|
+
config_param :channels, :array, default: ['application']
|
29
|
+
config_param :keys, :array, default: []
|
27
30
|
config_param :read_from_head, :bool, default: false
|
28
31
|
config_param :from_encoding, :string, default: nil
|
29
32
|
config_param :encoding, :string, default: nil
|
30
33
|
|
34
|
+
config_section :storage do
|
35
|
+
config_set_default :usage, "positions"
|
36
|
+
config_set_default :@type, DEFAULT_STORAGE_TYPE
|
37
|
+
config_set_default :persistent, true
|
38
|
+
end
|
39
|
+
|
31
40
|
attr_reader :chs
|
32
41
|
|
33
42
|
def initialize
|
@@ -55,6 +64,7 @@ module Fluent::Plugin
|
|
55
64
|
else
|
56
65
|
method(:no_encode_record)
|
57
66
|
end
|
67
|
+
@pos_storage = storage_create(usage: "positions")
|
58
68
|
end
|
59
69
|
|
60
70
|
def configure_encoding
|
@@ -92,229 +102,86 @@ module Fluent::Plugin
|
|
92
102
|
|
93
103
|
def start
|
94
104
|
super
|
95
|
-
|
96
|
-
|
97
|
-
@
|
98
|
-
|
99
|
-
|
100
|
-
|
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
|
105
|
+
@chs.each do |ch|
|
106
|
+
start, num = @pos_storage.get(ch)
|
107
|
+
if @read_from_head || (!num || num.zero?)
|
108
|
+
el = Win32::EventLog.open(ch)
|
109
|
+
@pos_storage.put(ch, [el.oldest_record_number - 1, 1])
|
110
|
+
el.close
|
127
111
|
end
|
128
|
-
|
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)
|
112
|
+
timer_execute("in_windows_eventlog_#{escape_channel(ch)}".to_sym, @read_interval) do
|
113
|
+
on_notify(ch)
|
138
114
|
end
|
139
|
-
|
115
|
+
end
|
140
116
|
end
|
141
117
|
|
142
|
-
def
|
143
|
-
|
144
|
-
# flush_buffer(wlw)
|
118
|
+
def escape_channel(ch)
|
119
|
+
ch.gsub(/[^a-zA-Z0-9]/, '_')
|
145
120
|
end
|
146
121
|
|
147
|
-
def receive_lines(ch, lines
|
122
|
+
def receive_lines(ch, lines)
|
148
123
|
return if lines.empty?
|
149
124
|
begin
|
150
125
|
for r in lines
|
151
126
|
h = {"channel" => ch}
|
152
|
-
@keynames.each
|
153
|
-
|
127
|
+
@keynames.each do |k|
|
128
|
+
type = KEY_MAP[k][1]
|
129
|
+
value = r.send(KEY_MAP[k][0])
|
130
|
+
h[k]=case type
|
131
|
+
when :string
|
132
|
+
@receive_handlers.call(value.to_s)
|
133
|
+
when :array
|
134
|
+
value.map {|v| @receive_handlers.call(v.to_s)}
|
135
|
+
else
|
136
|
+
raise "Unknown value type: #{type}"
|
137
|
+
end
|
138
|
+
end
|
139
|
+
#h = Hash[@keynames.map {|k| [k, r.send(KEY_MAP[k][0]).to_s]}]
|
154
140
|
router.emit(@tag, Fluent::Engine.now, h)
|
155
|
-
pe[1] +=1
|
156
141
|
end
|
157
|
-
rescue
|
158
|
-
|
159
|
-
|
142
|
+
rescue => e
|
143
|
+
log.error "unexpected error", error: e
|
144
|
+
log.error_backtrace
|
160
145
|
end
|
161
146
|
end
|
162
147
|
|
148
|
+
def on_notify(ch)
|
149
|
+
el = Win32::EventLog.open(ch)
|
163
150
|
|
164
|
-
|
165
|
-
|
166
|
-
@ch = ch
|
167
|
-
@pe = pe || MemoryPositionEntry.new
|
168
|
-
@receive_lines = receive_lines
|
169
|
-
@timer_trigger = nil
|
170
|
-
end
|
151
|
+
current_oldest_record_number = el.oldest_record_number
|
152
|
+
current_total_records = el.total_records
|
171
153
|
|
172
|
-
|
173
|
-
attr_accessor :unwatched
|
174
|
-
attr_accessor :pe
|
175
|
-
attr_accessor :timer_trigger
|
154
|
+
read_start, read_num = @pos_storage.get(ch)
|
176
155
|
|
177
|
-
|
178
|
-
|
179
|
-
|
156
|
+
# if total_records is zero, oldest_record_number has no meaning.
|
157
|
+
if current_total_records == 0
|
158
|
+
return
|
180
159
|
end
|
181
160
|
|
182
|
-
|
183
|
-
@
|
161
|
+
if read_start == 0 && read_num == 0
|
162
|
+
@pos_storage.put(ch, [current_oldest_record_number, current_total_records])
|
163
|
+
return
|
184
164
|
end
|
185
165
|
|
186
|
-
|
187
|
-
|
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
|
166
|
+
current_end = current_oldest_record_number + current_total_records - 1
|
167
|
+
old_end = read_start + read_num - 1
|
217
168
|
|
218
|
-
|
219
|
-
|
220
|
-
|
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
|
169
|
+
if current_oldest_record_number < read_start
|
170
|
+
# may be a record number rotated.
|
171
|
+
current_end += 0xFFFFFFFF
|
229
172
|
end
|
230
|
-
end
|
231
173
|
|
232
|
-
|
233
|
-
|
234
|
-
@
|
235
|
-
|
236
|
-
@last_pos = last_pos
|
174
|
+
if current_end < old_end
|
175
|
+
# something occured.
|
176
|
+
@pos_storage.put(ch, [current_oldest_record_number, current_total_records])
|
177
|
+
return
|
237
178
|
end
|
238
179
|
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
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
|
180
|
+
winlogs = el.read(Win32::EventLog::SEEK_READ | Win32::EventLog::FORWARDS_READ, old_end + 1)
|
181
|
+
receive_lines(ch, winlogs)
|
182
|
+
@pos_storage.put(ch, [read_start, read_num + winlogs.size])
|
183
|
+
ensure
|
184
|
+
el.close
|
267
185
|
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
186
|
end
|
320
187
|
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'win32/eventlog'
|
2
|
+
|
3
|
+
class EventLog
|
4
|
+
def initialize
|
5
|
+
@logger = Win32::EventLog.new
|
6
|
+
@app_source = "fluent-plugins"
|
7
|
+
end
|
8
|
+
|
9
|
+
def info(event_id, message)
|
10
|
+
@logger.report_event(
|
11
|
+
source: @app_source,
|
12
|
+
event_type: Win32::EventLog::INFO_TYPE,
|
13
|
+
event_id: event_id,
|
14
|
+
data: message
|
15
|
+
)
|
16
|
+
end
|
17
|
+
|
18
|
+
def warn(event_id, message)
|
19
|
+
@logger.report_event(
|
20
|
+
source: @app_source,
|
21
|
+
event_type: Win32::EventLog::WARN_TYPE,
|
22
|
+
event_id: event_id,
|
23
|
+
data: message
|
24
|
+
)
|
25
|
+
end
|
26
|
+
|
27
|
+
def crit(event_id, message)
|
28
|
+
@logger.report_event(
|
29
|
+
source: @app_source,
|
30
|
+
event_type: Win32::EventLog::ERROR_TYPE,
|
31
|
+
event_id: event_id,
|
32
|
+
data: message
|
33
|
+
)
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
|
38
|
+
module Fluent
|
39
|
+
module Plugin
|
40
|
+
class EventService
|
41
|
+
def run
|
42
|
+
eventlog = EventLog.new()
|
43
|
+
eventlog.info(65500, "Hi, from fluentd-plugins!! at " + Time.now.strftime("%Y/%m/%d %H:%M:%S "))
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
data/test/helper.rb
CHANGED
@@ -1,13 +1,18 @@
|
|
1
1
|
require 'helper'
|
2
|
+
require 'generate-windows-event'
|
2
3
|
|
3
4
|
class WindowsEventLogInputTest < Test::Unit::TestCase
|
5
|
+
|
4
6
|
def setup
|
5
7
|
Fluent::Test.setup
|
6
8
|
end
|
7
9
|
|
8
|
-
CONFIG =
|
9
|
-
|
10
|
-
|
10
|
+
CONFIG = config_element("ROOT", "", {"tag" => "fluent.eventlog"}, [
|
11
|
+
config_element("storage", "", {
|
12
|
+
'@type' => 'local',
|
13
|
+
'persistent' => false
|
14
|
+
})
|
15
|
+
])
|
11
16
|
|
12
17
|
def create_driver(conf = CONFIG)
|
13
18
|
Fluent::Test::Driver::Input.new(Fluent::Plugin::WindowsEventLogInput).configure(conf)
|
@@ -18,34 +23,26 @@ class WindowsEventLogInputTest < Test::Unit::TestCase
|
|
18
23
|
assert_equal 'fluent.eventlog', d.instance.tag
|
19
24
|
assert_equal 2, d.instance.read_interval
|
20
25
|
assert_nil d.instance.pos_file
|
21
|
-
assert_equal ['
|
26
|
+
assert_equal ['application'], d.instance.channels
|
22
27
|
assert_true d.instance.keys.empty?
|
23
28
|
assert_false d.instance.read_from_head
|
24
29
|
end
|
25
30
|
|
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
31
|
def test_write
|
40
32
|
d = create_driver
|
41
33
|
|
42
|
-
|
43
|
-
|
44
|
-
|
34
|
+
service = Fluent::Plugin::EventService.new
|
35
|
+
|
36
|
+
d.run(expect_emits: 1) do
|
37
|
+
service.run
|
38
|
+
end
|
45
39
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
40
|
+
assert(d.events.length >= 1)
|
41
|
+
event = d.events.last
|
42
|
+
record = event.last
|
43
|
+
assert_equal("application", record["channel"])
|
44
|
+
assert_equal("65500", record["event_id"])
|
45
|
+
assert_equal("information", record["event_type"])
|
46
|
+
assert_equal("fluent-plugins", record["source_name"])
|
50
47
|
end
|
51
48
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fluent-plugin-windows-eventlog
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- okahashi117
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2017-
|
13
|
+
date: 2017-06-06 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: bundler
|
@@ -60,7 +60,7 @@ dependencies:
|
|
60
60
|
requirements:
|
61
61
|
- - ">="
|
62
62
|
- !ruby/object:Gem::Version
|
63
|
-
version: 0.14.
|
63
|
+
version: 0.14.12
|
64
64
|
- - "<"
|
65
65
|
- !ruby/object:Gem::Version
|
66
66
|
version: '2'
|
@@ -70,7 +70,7 @@ dependencies:
|
|
70
70
|
requirements:
|
71
71
|
- - ">="
|
72
72
|
- !ruby/object:Gem::Version
|
73
|
-
version: 0.14.
|
73
|
+
version: 0.14.12
|
74
74
|
- - "<"
|
75
75
|
- !ruby/object:Gem::Version
|
76
76
|
version: '2'
|
@@ -91,7 +91,7 @@ dependencies:
|
|
91
91
|
description: Fluentd Input plugin to read windwos event log.
|
92
92
|
email:
|
93
93
|
- naruki_okahashi@jbat.co.jp
|
94
|
-
- cosmo0920.
|
94
|
+
- cosmo0920.oucc@gmail.com
|
95
95
|
- repeatedly@gmail.com
|
96
96
|
executables: []
|
97
97
|
extensions: []
|
@@ -102,8 +102,10 @@ files:
|
|
102
102
|
- LICENSE.txt
|
103
103
|
- README.md
|
104
104
|
- Rakefile
|
105
|
+
- appveyor.yml
|
105
106
|
- fluent-plugin-winevtlog.gemspec
|
106
107
|
- lib/fluent/plugin/in_windows_eventlog.rb
|
108
|
+
- test/generate-windows-event.rb
|
107
109
|
- test/helper.rb
|
108
110
|
- test/plugin/test_in_winevtlog.rb
|
109
111
|
homepage: https://github.com/fluent/fluent-plugin-windows-eventlog
|
@@ -126,10 +128,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
126
128
|
version: '0'
|
127
129
|
requirements: []
|
128
130
|
rubyforge_project:
|
129
|
-
rubygems_version: 2.6.
|
131
|
+
rubygems_version: 2.6.11
|
130
132
|
signing_key:
|
131
133
|
specification_version: 4
|
132
134
|
summary: Fluentd Input plugin to read windows event log.
|
133
135
|
test_files:
|
136
|
+
- test/generate-windows-event.rb
|
134
137
|
- test/helper.rb
|
135
138
|
- test/plugin/test_in_winevtlog.rb
|