fluent-plugin-windows-eventlog 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e4ec43a83a8b3f54edc73e2f26ee4ec43005ba73
4
- data.tar.gz: 1f225569741fe7768cf373c8d287f9ff1c11cdab
3
+ metadata.gz: 44561910d111a16a85de6b5d9faee8cf052fed71
4
+ data.tar.gz: 2bc58308403d20000efe50f2b6f73e86a9a6585a
5
5
  SHA512:
6
- metadata.gz: 343bbf9e3c173ca9707821599602fa767e3d693756c823bcafb5eeea2f87d073eefc3bae34eafaa55a15745f6875cd7c670fcd0c6ac6b096d82a9f842adec025
7
- data.tar.gz: 1c30bc7385783027f6d2e3c509e3b811aede90c42cd27bc9da9b786f4de960262892a8a56c3d3b59cd42cc707af303fd499a59f7283ad41de960415a8aa41564
6
+ metadata.gz: 194172daa6b8dd788a785d89e392e3698fe7ed6b8ffa0de360ddc89bf2bd9d37818d8abd43bf5c6e71434cffdd603a91126f674ab80c45455aeffe969a5101c2
7
+ data.tar.gz: 2b45ac6f8ce1c4d142ce1aae21104945c2bdb706db26c57eb6f9a0e2ef90ba468a7b3fd5172242817c6e43f3b1575b2167bcd5f65ebd52600f4f461f3c0780ad
data/README.md CHANGED
@@ -2,72 +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
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
22
- @id windows_eventlog
23
21
  <storage>
24
- @type local # @type local is default.
25
- persistent true # persistent true is default.
22
+ @type local # @type local is the default.
23
+ persistent true # default is true. Set to false to use in-memory storage.
26
24
  path ./tmp/storage.json # This is required when persistent is true.
27
- # Or, please consider to use <system> section's root_dir parameter.
25
+ # Or, please consider using <system> section's `root_dir` parameter.
28
26
  </storage>
29
27
  </source>
30
28
 
31
-
32
29
  #### parameters
33
30
 
34
31
  |name | description |
35
32
  |:----- |:----- |
36
- |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. |
37
- |pos_file | (option, but higly recommended) a path of position file to save record numbers. |
38
- |read_interval | (option) a read interval in second. 2 seconds as default.|
39
- |from_encoding | (option) an input characters encoding. nil as default.|
40
- |encoding | (option) an output characters encoding. nil as default.|
41
-
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`.|
42
40
 
43
41
  #### read keys
44
- This plugin reads follows from Windws Event Log. No customization is allowed currently.
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.
45
43
 
46
44
  |key|
47
45
  |:----- |
48
- |record_number |
49
- |time_generated|
50
- |time_written |
51
- |event_id |
52
- |event_type |
53
- |event_category |
54
- |source_name |
55
- |computer_name |
56
- |user |
57
- |description |
58
-
59
-
60
-
61
- ## Etc.
62
- 'read_from_head' is not supporeted currently.You can read newer records after you start first.
63
- No customize to read information keys.
64
-
65
-
66
-
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`|
67
57
 
68
58
  ## Copyright
69
- ####Copyright
59
+ #### Copyright
70
60
  Copyright(C) 2014- @okahashi117
71
- ####License
61
+ #### License
72
62
  Apache License, Version 2.0
73
63
 
@@ -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,7 +4,7 @@ $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.2.0"
7
+ spec.version = "0.2.1"
8
8
  spec.authors = ["okahashi117", "Hiroshi Hatake", "Masahiro Nakagawa"]
9
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.}
@@ -9,23 +9,24 @@ module Fluent::Plugin
9
9
  helpers :timer, :storage
10
10
 
11
11
  DEFAULT_STORAGE_TYPE = 'local'
12
- KEY_MAP = {"record_number" => :record_number,
13
- "time_generated" => :time_generated,
14
- "time_written" => :time_written,
15
- "event_id" => :event_id,
16
- "event_type" => :event_type,
17
- "event_category" => :category,
18
- "source_name" => :source,
19
- "computer_name" => :computer,
20
- "user" => :user,
21
- "description" => :description}
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]}
22
23
 
23
24
  config_param :tag, :string
24
25
  config_param :read_interval, :time, default: 2
25
26
  config_param :pos_file, :string, default: nil,
26
27
  obsoleted: "This section is not used anymore. Use 'store_pos' instead."
27
- config_param :channels, :array, default: ['Application']
28
- config_param :keys, :string, default: []
28
+ config_param :channels, :array, default: ['application']
29
+ config_param :keys, :array, default: []
29
30
  config_param :read_from_head, :bool, default: false
30
31
  config_param :from_encoding, :string, default: nil
31
32
  config_param :encoding, :string, default: nil
@@ -123,8 +124,19 @@ module Fluent::Plugin
123
124
  begin
124
125
  for r in lines
125
126
  h = {"channel" => ch}
126
- @keynames.each {|k| h[k]=@receive_handlers.call(r.send(KEY_MAP[k]).to_s)}
127
- #h = Hash[@keynames.map {|k| [k, r.send(KEY_MAP[k]).to_s]}]
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]}]
128
140
  router.emit(@tag, Fluent::Engine.now, h)
129
141
  end
130
142
  rescue => e
@@ -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
@@ -27,3 +27,6 @@ require 'fluent/plugin/in_windows_eventlog'
27
27
 
28
28
  class Test::Unit::TestCase
29
29
  end
30
+ require 'fluent/test/helpers'
31
+
32
+ include Fluent::Test::Helpers
@@ -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
- tag fluent.eventlog
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 ['Application'], d.instance.channels
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
- # time = Time.parse("2011-01-02 13:14:15 UTC").to_i
43
- # d.emit({"a"=>1}, time)
44
- # d.emit({"a"=>2}, time)
34
+ service = Fluent::Plugin::EventService.new
35
+
36
+ d.run(expect_emits: 1) do
37
+ service.run
38
+ end
45
39
 
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
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.2.0
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-03-08 00:00:00.000000000 Z
13
+ date: 2017-06-06 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: bundler
@@ -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.5.2
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