fluent-plugin-windows-eventlog 0.2.1 → 0.4.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitignore +14 -14
- data/CHANGELOG.md +28 -0
- data/Gemfile +4 -4
- data/LICENSE.txt +203 -203
- data/README.md +285 -63
- data/Rakefile +10 -10
- data/appveyor.yml +24 -27
- data/fluent-plugin-winevtlog.gemspec +28 -25
- data/lib/fluent/plugin/in_windows_eventlog.rb +234 -187
- data/lib/fluent/plugin/in_windows_eventlog2.rb +227 -0
- data/test/generate-windows-event.rb +47 -47
- data/test/helper.rb +33 -32
- data/test/plugin/test_in_windows_eventlog2.rb +214 -0
- data/test/plugin/test_in_winevtlog.rb +48 -48
- metadata +50 -4
@@ -1,47 +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
|
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,32 +1,33 @@
|
|
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
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
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
|
+
require 'fluent/plugin/in_windows_eventlog2'
|
28
|
+
|
29
|
+
class Test::Unit::TestCase
|
30
|
+
end
|
31
|
+
require 'fluent/test/helpers'
|
32
|
+
|
33
|
+
include Fluent::Test::Helpers
|
@@ -0,0 +1,214 @@
|
|
1
|
+
require 'helper'
|
2
|
+
require 'fileutils'
|
3
|
+
require 'generate-windows-event'
|
4
|
+
|
5
|
+
class WindowsEventLog2InputTest < Test::Unit::TestCase
|
6
|
+
|
7
|
+
def setup
|
8
|
+
Fluent::Test.setup
|
9
|
+
end
|
10
|
+
|
11
|
+
CONFIG = config_element("ROOT", "", {"tag" => "fluent.eventlog"}, [
|
12
|
+
config_element("storage", "", {
|
13
|
+
'@type' => 'local',
|
14
|
+
'persistent' => false
|
15
|
+
})
|
16
|
+
])
|
17
|
+
|
18
|
+
def create_driver(conf = CONFIG)
|
19
|
+
Fluent::Test::Driver::Input.new(Fluent::Plugin::WindowsEventLog2Input).configure(conf)
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_configure
|
23
|
+
d = create_driver CONFIG
|
24
|
+
assert_equal 'fluent.eventlog', d.instance.tag
|
25
|
+
assert_equal 2, d.instance.read_interval
|
26
|
+
assert_equal ['application'], d.instance.channels
|
27
|
+
assert_false d.instance.read_from_head
|
28
|
+
assert_true d.instance.render_as_xml
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_parse_desc
|
32
|
+
d = create_driver
|
33
|
+
desc =<<-DESC
|
34
|
+
A user's local group membership was enumerated.\r\n\r\nSubject:\r\n\tSecurity ID:\t\tS-X-Y-XX-WWWWWW-VVVV\r\n\tAccount Name:\t\tAdministrator\r\n\tAccount Domain:\t\tDESKTOP-FLUENTTEST\r\n\tLogon ID:\t\t0x3185B1\r\n\r\nUser:\r\n\tSecurity ID:\t\tS-X-Y-XX-WWWWWW-VVVV\r\n\tAccount Name:\t\tAdministrator\r\n\tAccount Domain:\t\tDESKTOP-FLUENTTEST\r\n\r\nProcess Information:\r\n\tProcess ID:\t\t0x50b8\r\n\tProcess Name:\t\tC:\\msys64\\usr\\bin\\make.exe
|
35
|
+
DESC
|
36
|
+
h = {"Description" => desc}
|
37
|
+
expected = {"DescriptionTitle" => "A user's local group membership was enumerated.",
|
38
|
+
"subject.security_id" => "S-X-Y-XX-WWWWWW-VVVV",
|
39
|
+
"subject.account_name" => "Administrator",
|
40
|
+
"subject.account_domain" => "DESKTOP-FLUENTTEST",
|
41
|
+
"subject.logon_id" => "0x3185B1",
|
42
|
+
"user.security_id" => "S-X-Y-XX-WWWWWW-VVVV",
|
43
|
+
"user.account_name" => "Administrator",
|
44
|
+
"user.account_domain" => "DESKTOP-FLUENTTEST",
|
45
|
+
"process_information.process_id" => "0x50b8",
|
46
|
+
"process_information.process_name" => "C:\\msys64\\usr\\bin\\make.exe"}
|
47
|
+
d.instance.parse_desc(h)
|
48
|
+
assert_equal(expected, h)
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_write
|
52
|
+
d = create_driver
|
53
|
+
|
54
|
+
service = Fluent::Plugin::EventService.new
|
55
|
+
|
56
|
+
d.run(expect_emits: 1) do
|
57
|
+
service.run
|
58
|
+
end
|
59
|
+
|
60
|
+
assert(d.events.length >= 1)
|
61
|
+
event = d.events.select {|e| e.last["EventID"] == "65500" }.last
|
62
|
+
record = event.last
|
63
|
+
|
64
|
+
assert_equal("Application", record["Channel"])
|
65
|
+
assert_equal("65500", record["EventID"])
|
66
|
+
assert_equal("4", record["Level"])
|
67
|
+
assert_equal("fluent-plugins", record["ProviderName"])
|
68
|
+
end
|
69
|
+
|
70
|
+
CONFIG_KEYS = config_element("ROOT", "", {
|
71
|
+
"tag" => "fluent.eventlog",
|
72
|
+
"keys" => ["EventID", "Level", "Channel", "ProviderName"]
|
73
|
+
}, [
|
74
|
+
config_element("storage", "", {
|
75
|
+
'@type' => 'local',
|
76
|
+
'persistent' => false
|
77
|
+
})
|
78
|
+
])
|
79
|
+
def test_write_with_keys
|
80
|
+
d = create_driver(CONFIG_KEYS)
|
81
|
+
|
82
|
+
service = Fluent::Plugin::EventService.new
|
83
|
+
|
84
|
+
d.run(expect_emits: 1) do
|
85
|
+
service.run
|
86
|
+
end
|
87
|
+
|
88
|
+
assert(d.events.length >= 1)
|
89
|
+
event = d.events.last
|
90
|
+
record = event.last
|
91
|
+
|
92
|
+
expected = {"EventID" => "65500",
|
93
|
+
"Level" => "4",
|
94
|
+
"Channel" => "Application",
|
95
|
+
"ProviderName" => "fluent-plugins"}
|
96
|
+
|
97
|
+
assert_equal(expected, record)
|
98
|
+
end
|
99
|
+
|
100
|
+
class HashRendered < self
|
101
|
+
def test_write
|
102
|
+
d = create_driver(config_element("ROOT", "", {"tag" => "fluent.eventlog",
|
103
|
+
"render_as_xml" => false}, [
|
104
|
+
config_element("storage", "", {
|
105
|
+
'@type' => 'local',
|
106
|
+
'persistent' => false
|
107
|
+
})
|
108
|
+
]))
|
109
|
+
|
110
|
+
service = Fluent::Plugin::EventService.new
|
111
|
+
|
112
|
+
d.run(expect_emits: 1) do
|
113
|
+
service.run
|
114
|
+
end
|
115
|
+
|
116
|
+
assert(d.events.length >= 1)
|
117
|
+
event = d.events.select {|e| e.last["EventID"] == "65500" }.last
|
118
|
+
record = event.last
|
119
|
+
|
120
|
+
assert_false(d.instance.render_as_xml)
|
121
|
+
assert_equal("Application", record["Channel"])
|
122
|
+
assert_equal("65500", record["EventID"])
|
123
|
+
assert_equal("4", record["Level"])
|
124
|
+
assert_equal("fluent-plugins", record["ProviderName"])
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
class PersistBookMark < self
|
129
|
+
TEST_PLUGIN_STORAGE_PATH = File.join( File.dirname(File.dirname(__FILE__)), 'tmp', 'in_windows_eventlog2', 'store' )
|
130
|
+
CONFIG2 = config_element("ROOT", "", {"tag" => "fluent.eventlog"}, [
|
131
|
+
config_element("storage", "", {
|
132
|
+
'@type' => 'local',
|
133
|
+
'@id' => 'test-02',
|
134
|
+
'path' => File.join(TEST_PLUGIN_STORAGE_PATH,
|
135
|
+
'json', 'test-02.json'),
|
136
|
+
'persistent' => true,
|
137
|
+
})
|
138
|
+
])
|
139
|
+
|
140
|
+
def setup
|
141
|
+
FileUtils.rm_rf(TEST_PLUGIN_STORAGE_PATH)
|
142
|
+
FileUtils.mkdir_p(File.join(TEST_PLUGIN_STORAGE_PATH, 'json'))
|
143
|
+
FileUtils.chmod_R(0755, File.join(TEST_PLUGIN_STORAGE_PATH, 'json'))
|
144
|
+
end
|
145
|
+
|
146
|
+
def test_write
|
147
|
+
d = create_driver(CONFIG2)
|
148
|
+
|
149
|
+
assert !File.exist?(File.join(TEST_PLUGIN_STORAGE_PATH, 'json', 'test-02.json'))
|
150
|
+
|
151
|
+
service = Fluent::Plugin::EventService.new
|
152
|
+
|
153
|
+
d.run(expect_emits: 1) do
|
154
|
+
service.run
|
155
|
+
end
|
156
|
+
|
157
|
+
assert(d.events.length >= 1)
|
158
|
+
event = d.events.select {|e| e.last["EventID"] == "65500" }.last
|
159
|
+
record = event.last
|
160
|
+
|
161
|
+
prev_id = record["EventRecordID"].to_i
|
162
|
+
assert_equal("Application", record["Channel"])
|
163
|
+
assert_equal("65500", record["EventID"])
|
164
|
+
assert_equal("4", record["Level"])
|
165
|
+
assert_equal("fluent-plugins", record["ProviderName"])
|
166
|
+
|
167
|
+
assert File.exist?(File.join(TEST_PLUGIN_STORAGE_PATH, 'json', 'test-02.json'))
|
168
|
+
|
169
|
+
d2 = create_driver(CONFIG2)
|
170
|
+
d2.run(expect_emits: 1) do
|
171
|
+
service.run
|
172
|
+
end
|
173
|
+
|
174
|
+
assert(d2.events.length == 1) # should be tailing after previous context.
|
175
|
+
event2 = d2.events.last
|
176
|
+
record2 = event2.last
|
177
|
+
|
178
|
+
curr_id = record2["EventRecordID"].to_i
|
179
|
+
assert(curr_id > prev_id)
|
180
|
+
|
181
|
+
assert File.exist?(File.join(TEST_PLUGIN_STORAGE_PATH, 'json', 'test-02.json'))
|
182
|
+
end
|
183
|
+
end
|
184
|
+
|
185
|
+
def test_write_with_none_parser
|
186
|
+
d = create_driver(config_element("ROOT", "", {"tag" => "fluent.eventlog"}, [
|
187
|
+
config_element("storage", "", {
|
188
|
+
'@type' => 'local',
|
189
|
+
'persistent' => false
|
190
|
+
}),
|
191
|
+
config_element("parse", "", {
|
192
|
+
'@type' => 'none',
|
193
|
+
}),
|
194
|
+
]))
|
195
|
+
|
196
|
+
service = Fluent::Plugin::EventService.new
|
197
|
+
|
198
|
+
d.run(expect_emits: 1) do
|
199
|
+
service.run
|
200
|
+
end
|
201
|
+
|
202
|
+
assert(d.events.length >= 1)
|
203
|
+
event = d.events.last
|
204
|
+
record = event.last
|
205
|
+
|
206
|
+
assert do
|
207
|
+
# record should be {message: <RAW XML EventLog>}.
|
208
|
+
record["message"]
|
209
|
+
end
|
210
|
+
|
211
|
+
assert_true(record.has_key?("Description"))
|
212
|
+
assert_true(record.has_key?("EventData"))
|
213
|
+
end
|
214
|
+
end
|
@@ -1,48 +1,48 @@
|
|
1
|
-
require 'helper'
|
2
|
-
require 'generate-windows-event'
|
3
|
-
|
4
|
-
class WindowsEventLogInputTest < Test::Unit::TestCase
|
5
|
-
|
6
|
-
def setup
|
7
|
-
Fluent::Test.setup
|
8
|
-
end
|
9
|
-
|
10
|
-
CONFIG = config_element("ROOT", "", {"tag" => "fluent.eventlog"}, [
|
11
|
-
config_element("storage", "", {
|
12
|
-
'@type' => 'local',
|
13
|
-
'persistent' => false
|
14
|
-
})
|
15
|
-
])
|
16
|
-
|
17
|
-
def create_driver(conf = CONFIG)
|
18
|
-
Fluent::Test::Driver::Input.new(Fluent::Plugin::WindowsEventLogInput).configure(conf)
|
19
|
-
end
|
20
|
-
|
21
|
-
def test_configure
|
22
|
-
d = create_driver CONFIG
|
23
|
-
assert_equal 'fluent.eventlog', d.instance.tag
|
24
|
-
assert_equal 2, d.instance.read_interval
|
25
|
-
assert_nil d.instance.pos_file
|
26
|
-
assert_equal ['application'], d.instance.channels
|
27
|
-
assert_true d.instance.keys.empty?
|
28
|
-
assert_false d.instance.read_from_head
|
29
|
-
end
|
30
|
-
|
31
|
-
def test_write
|
32
|
-
d = create_driver
|
33
|
-
|
34
|
-
service = Fluent::Plugin::EventService.new
|
35
|
-
|
36
|
-
d.run(expect_emits: 1) do
|
37
|
-
service.run
|
38
|
-
end
|
39
|
-
|
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"])
|
47
|
-
end
|
48
|
-
end
|
1
|
+
require 'helper'
|
2
|
+
require 'generate-windows-event'
|
3
|
+
|
4
|
+
class WindowsEventLogInputTest < Test::Unit::TestCase
|
5
|
+
|
6
|
+
def setup
|
7
|
+
Fluent::Test.setup
|
8
|
+
end
|
9
|
+
|
10
|
+
CONFIG = config_element("ROOT", "", {"tag" => "fluent.eventlog"}, [
|
11
|
+
config_element("storage", "", {
|
12
|
+
'@type' => 'local',
|
13
|
+
'persistent' => false
|
14
|
+
})
|
15
|
+
])
|
16
|
+
|
17
|
+
def create_driver(conf = CONFIG)
|
18
|
+
Fluent::Test::Driver::Input.new(Fluent::Plugin::WindowsEventLogInput).configure(conf)
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_configure
|
22
|
+
d = create_driver CONFIG
|
23
|
+
assert_equal 'fluent.eventlog', d.instance.tag
|
24
|
+
assert_equal 2, d.instance.read_interval
|
25
|
+
assert_nil d.instance.pos_file
|
26
|
+
assert_equal ['application'], d.instance.channels
|
27
|
+
assert_true d.instance.keys.empty?
|
28
|
+
assert_false d.instance.read_from_head
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_write
|
32
|
+
d = create_driver
|
33
|
+
|
34
|
+
service = Fluent::Plugin::EventService.new
|
35
|
+
|
36
|
+
d.run(expect_emits: 1) do
|
37
|
+
service.run
|
38
|
+
end
|
39
|
+
|
40
|
+
assert(d.events.length >= 1)
|
41
|
+
event = d.events.select {|e| e.last["event_id"] == "65500" }.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"])
|
47
|
+
end
|
48
|
+
end
|