Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add JSON support to windows sources #193

Merged
merged 29 commits into from
May 11, 2022
Merged
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
5396938
changelog 1.6.2
rjury-sumo May 4, 2022
e307c53
docs for windows json support
rjury-sumo May 4, 2022
930aef7
add windows json support
rjury-sumo May 4, 2022
17581db
add windows json support
rjury-sumo May 4, 2022
49732b0
fix typo
rjury-sumo May 5, 2022
51a5d4a
chore(vagrant): fix ip
May 5, 2022
ea44765
feat: add json related fields to windows event sources
May 5, 2022
2f52d7d
refactor: create types for windows related properties
May 5, 2022
2ec141c
refactor: inherit windows remote source from windows local source
May 5, 2022
4bd53b8
docs(README): update
May 5, 2022
bbb9db5
fix: fix imports
May 5, 2022
749a47c
fix: lint
May 5, 2022
d58cf90
feat: add enable_json_events property to windows sources
May 6, 2022
8d72c5f
feat: add enable_json_events configuration to README
May 6, 2022
c066ec1
refactor: makes lint happy
May 6, 2022
5cea251
fix: add missing change
May 6, 2022
a05a1c9
tests: add tests for windows json events
May 6, 2022
44c08e7
chore(changelog): update
sumo-drosiek May 6, 2022
dfa356b
Apply suggestions from code review
sumo-drosiek May 6, 2022
7a38601
docs: update due to review
May 6, 2022
43f5f58
docs: update due to review
May 6, 2022
2c6d199
feat: remove enable_json_events
May 10, 2022
4af3065
Update CHANGELOG.md
sumo-drosiek May 10, 2022
f1c9584
Apply suggestions from code review
sumo-drosiek May 10, 2022
24e812f
Delete remote_win_event_json_log_create_spec.rb
sumo-drosiek May 10, 2022
21764e6
Delete local_win_event_json_log_create_spec.rb
sumo-drosiek May 10, 2022
aad1c66
tests: fix
May 10, 2022
3714d98
fix: defaults
May 10, 2022
fee192f
feat!: change default event_message to :message
andrzej-stencel May 11, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ This project adheres to [Semantic Versioning](http://semver.org/).

This CHANGELOG (now) follows the format listed at [Keep A Changelog](http://keepachangelog.com/)

## Unreleased
### Added
- feat: add JSON support to windows sources [#193]

[#193]: https://github.com/SumoLogic/sumologic-collector-chef-cookbook/pull/193

## [1.6.2] - 2022-01-05
### Added
- added `fields` support to sources (@majormoses) [#189]
Expand Down
37 changes: 36 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,10 @@ The following attribute parameters are in addition to the generic parameters
listed above.

- `log_names` - **required**
- `event_format` - `:legacy` for legacy format or `:json` for JSON format
- `event_message` - Use with JSON format. `:complete`, `:message` (recommended), or `:metadata` for metadata only.
- `allowlist` - Available in Collector version 19.351-4 and later. A comma-separated list of event IDs.
- `denylist` - Available in Collector version 19.351-4 and later. A comma-separated list of event IDs.

### Examples

Expand All @@ -391,6 +395,19 @@ sumo_source_local_windows_event_log 'local_win_event_log' do
end
```

Use JSON log format instead of legacy format:

```ruby
sumo_source_local_windows_event_log 'local_win_event_log' do
source_json_directory node['sumologic']['sumo_json_path']
log_names ['security', 'application']
event_format :json
event_message :message
allowlist ""
denylist ""
end
```

sumo_source_remote_file
---------

Expand Down Expand Up @@ -445,7 +462,7 @@ sumo_source_remote_windows_event_log
See the [Sumo Logic documentation](https://help.sumologic.com/Send_Data/Sources/Use_JSON_to_Configure_Sources)
for more information about these attributes.

The following attribute parameters are in addition to the generic parameters
The following attribute parameters are in addition to the generic and [sumo_source_local_windows_event_log](#sumosourcelocalwindowseventlog) parameters
listed above.

- `domain` - **required**
Expand All @@ -467,6 +484,24 @@ sumo_source_remote_windows_event_log 'remote_win_event_log' do
end
```

Use JSON log format instead of legacy format:

```ruby
sumo_source_remote_windows_event_log 'remote_win_event_log' do
source_json_directory node['sumologic']['sumo_json_path']
domain 'mydomain'
username 'user'
password 'password'
hosts ['myremotehost1']
log_names ['security', 'application']
event_format :json
event_message :message
allowlist ""
denylist ""

end
```

sumo_source_script
---------

Expand Down
2 changes: 1 addition & 1 deletion Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Vagrant.configure('2') do |config|
config.disksize.size = '50GB'
config.vm.box_check_update = false
config.vm.host_name = 'sumologic-collector-chef-cookbook'
config.vm.network :private_network, ip: "192.168.78.46"
config.vm.network :private_network, ip: "192.168.56.46"

config.vm.provider 'virtualbox' do |vb|
vb.gui = false
Expand Down
5 changes: 5 additions & 0 deletions libraries/provider_local_win_event_log_source.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

require 'chef/provider/lwrp_base'
require_relative 'provider_source'
require_relative 'types'

class Chef
class Provider
Expand All @@ -11,6 +12,10 @@ class SumoSourceLocalWindowsEventLog < Chef::Provider::SumoSource
def config_hash
hash = super
hash['source']['logNames'] = new_resource.log_names
hash['source']['eventFormat'] = EVENT_FORMAT[new_resource.event_format]
hash['source']['eventMessage'] = EVENT_MESSAGE[new_resource.event_message]
hash['source']['allowlist'] = new_resource.allowlist
hash['source']['denylist'] = new_resource.denylist
hash
end
end
Expand Down
5 changes: 2 additions & 3 deletions libraries/provider_remote_win_event_log_source.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# frozen_string_literal: true

require 'chef/provider/lwrp_base'
require_relative 'provider_source'
require_relative 'provider_local_win_event_log_source'

class Chef
class Provider
class SumoSourceRemoteWindowsEventLog < Chef::Provider::SumoSource
class SumoSourceRemoteWindowsEventLog < Chef::Provider::SumoSourceLocalWindowsEventLog
andrzej-stencel marked this conversation as resolved.
Show resolved Hide resolved
provides :sumo_source_remote_windows_event_log if respond_to?(:provides)

def config_hash
Expand All @@ -14,7 +14,6 @@ def config_hash
hash['source']['username'] = new_resource.username
hash['source']['password'] = new_resource.password
hash['source']['hosts'] = new_resource.hosts
hash['source']['logNames'] = new_resource.log_names
hash
end
end
Expand Down
5 changes: 5 additions & 0 deletions libraries/resource_local_win_event_log_source.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

require 'chef/resource/lwrp_base'
require_relative 'resource_source'
require_relative 'types'

class Chef
class Resource
Expand All @@ -10,6 +11,10 @@ class SumoSourceLocalWindowsEventLog < Chef::Resource::SumoSource

attribute :source_type, kind_of: Symbol, default: :local_windows_event_log, equal_to: [:local_windows_event_log]
attribute :log_names, kind_of: Array, required: true
attribute :event_format, kind_of: Symbol, default: :json, equal_to: EVENT_FORMAT.keys
attribute :event_message, kind_of: Symbol, default: :message, equal_to: EVENT_MESSAGE.keys
attribute :allowlist, kind_of: String
attribute :denylist, kind_of: String
end
end
end
5 changes: 2 additions & 3 deletions libraries/resource_remote_win_event_log_source.rb
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
# frozen_string_literal: true

require 'chef/resource/lwrp_base'
require_relative 'resource_source'
require_relative 'resource_local_win_event_log_source'

class Chef
class Resource
class SumoSourceRemoteWindowsEventLog < Chef::Resource::SumoSource
class SumoSourceRemoteWindowsEventLog < Chef::Resource::SumoSourceLocalWindowsEventLog
provides :sumo_source_remote_windows_event_log if respond_to?(:provides)

attribute :source_type, kind_of: Symbol, default: :remote_windows_event_log, equal_to: [:remote_windows_event_log]
attribute :domain, kind_of: String, required: true
attribute :username, kind_of: String, required: true
attribute :password, kind_of: String, required: true
attribute :hosts, kind_of: Array, required: true
attribute :log_names, kind_of: Array, required: true
end
end
end
14 changes: 14 additions & 0 deletions libraries/types.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# frozen_string_literal: true

EVENT_FORMAT = {
nil => nil,
:legacy => 0,
:json => 1
}.freeze

EVENT_MESSAGE = {
nil => nil,
:complete => 0,
:message => 1,
:metadata => 2
}.freeze
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# frozen_string_literal: true

sumo_source_local_windows_event_log 'local_win_event_json_log' do
source_json_directory node['sumologic']['sumo_json_path']
log_names %w[security application]

event_format :legacy
event_message :message
allowlist "el1,el2"
denylist "el3,el4"
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# frozen_string_literal: true

sumo_source_remote_windows_event_log 'remote_win_event_json_log' do
source_json_directory node['sumologic']['sumo_json_path']
domain 'mydomain'
username 'user'
password 'password'
hosts ['myremotehost1']
log_names %w[security application]

event_format :legacy
event_message :message
allowlist "el1,el2"
denylist "el3,el4"
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# frozen_string_literal: true

require 'spec_helper'

describe file('/etc/sumo.json/local_win_event_json_log.json') do
it { is_expected.to exist }

its(:content) { is_expected.to match(/"eventFormat": 0/) }
its(:content) { is_expected.to match(/"eventMessage": 1/) }
its(:content) { is_expected.to match(/"allowlist": "el1,el2"/) }
its(:content) { is_expected.to match(/"denylist": "el3,el4"/) }
end
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,9 @@

describe file('/etc/sumo.json/local_win_event_log.json') do
it { is_expected.to exist }

its(:content) { is_expected.not_to match(/"eventFormat":/) }
its(:content) { is_expected.not_to match(/"eventMessage":/) }
its(:content) { is_expected.not_to match(/"allowlist":/) }
its(:content) { is_expected.not_to match(/"denylist":/) }
sumo-drosiek marked this conversation as resolved.
Show resolved Hide resolved
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# frozen_string_literal: true

require 'spec_helper'

describe file('/etc/sumo.json/remote_win_event_json_log.json') do
it { is_expected.to exist }

its(:content) { is_expected.to match(/"eventFormat": 0/) }
its(:content) { is_expected.to match(/"eventMessage": 1/) }
its(:content) { is_expected.to match(/"allowlist": "el1,el2"/) }
its(:content) { is_expected.to match(/"denylist": "el3,el4"/) }
end
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,9 @@

describe file('/etc/sumo.json/remote_win_event_log.json') do
it { is_expected.to exist }

its(:content) { is_expected.not_to match(/"eventFormat":/) }
its(:content) { is_expected.not_to match(/"eventMessage":/) }
its(:content) { is_expected.not_to match(/"allowlist":/) }
its(:content) { is_expected.not_to match(/"denylist":/) }
sumo-drosiek marked this conversation as resolved.
Show resolved Hide resolved
end