Skip to content

Commit

Permalink
Merge pull request #158 from chrisminton/remove-deprecated-confdir
Browse files Browse the repository at this point in the history
Fix config directory configuration for filebeat 6.0+
  • Loading branch information
vkhatri authored Apr 1, 2020
2 parents a0292dc + e207bb9 commit a4daed4
Show file tree
Hide file tree
Showing 7 changed files with 100 additions and 29 deletions.
2 changes: 1 addition & 1 deletion .kitchen.dokken.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ platforms:

- name: debian8
driver:
image: debian:8.9
image: dokken/debian-8
pid_one_command: /sbin/init
intermediate_instructions:
- RUN /usr/bin/apt-get update -qq
Expand Down
94 changes: 71 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,26 @@ filebeat Cookbook

This is a [Chef] cookbook to manage [Filebeat].


>> For Production environment, always prefer the [most recent release](https://supermarket.chef.io/cookbooks/filebeat).

## Most Recent Release

```ruby
cookbook 'filebeat', '~> 2.2.0'
```


## From Git

```ruby
cookbook 'filebeat', github: 'vkhatri/chef-filebeat', tag: 'v2.2.0'
```


## Repository

```
```bash
https://github.com/vkhatri/chef-filebeat
```


## Supported OS

- Windows
Expand All @@ -42,20 +37,17 @@ https://github.com/vkhatri/chef-filebeat

Also works on Solaris zones given a physical Solaris 11.2 server. For that, use the .kitchen.zone.yml file. Check usage at (https://github.com/criticalmass/kitchen-zone). You will need an url to a filebeat package that works on Solaris 11.2. Checkout Building-Filebeat-On-Solaris11.md for instructions to build a filebeat package.


## Supported Chef

- Chef 12 (last tested on 12.21.4)

- Chef 13 (last tested on 13.3.42)


## Supported Filebeat

- 5.x
- 6.x


## Cookbook Dependency

- `homebrew`
Expand All @@ -64,12 +56,10 @@ Also works on Solaris zones given a physical Solaris 11.2 server. For that, use
- `runit`
- `windows`


## Recipes

- lwrp_test - LWRP examples recipe


## LWRP Resources

- `filebeat_config` - filebeat configuration resource
Expand All @@ -82,14 +72,12 @@ Also works on Solaris zones given a physical Solaris 11.2 server. For that, use

- `filebeat_runit_service` - filebeat service resource using runit

- `filebeat_prospector` - filebeat prospector resource

- `filebeat_prospector` - filebeat prospector resource (renamed filebeat inputs in version 6.3+)

## Limitations

The Mac OSX setup only allows for package installs and depends on brew, this means that version selection and preview build installs are not supported.


## LWRP filebeat_install

LWRP `filebeat_install` installs filebeat, creates log/prospectors directories, and also enable filebeat service.
Expand Down Expand Up @@ -153,7 +141,6 @@ end
- *service_retries* (optional, Integer) - default `2`, filebeat service resource attribute
- *service_retry_delay* (optional, Integer) - default `0`, filebeat service resource attribute


## LWRP filebeat_config

LWRP `filebeat_config` creates filebeat configuration yaml file `/etc/filebeat/filebeat.yml`.
Expand All @@ -164,8 +151,7 @@ Below filebeat configuration parameters gets overwritten by the LWRP.
- `filebeat.config_dir`
- `logging.files`


**LWRP example**
### Filebeat version < 6.0

```ruby
conf = {
Expand Down Expand Up @@ -199,6 +185,42 @@ filebeat.registry_file: "/var/lib/filebeat/registry"
filebeat.config_dir: "/etc/filebeat/conf.d"
```
### Filebeat version 6.0+
```ruby
conf = {
'filebeat.modules' => [],
'filebeat.inputs' => [],
'logging.level' => 'info',
'logging.to_files' => true,
'logging.files' => { 'name' => 'filebeat' },
'output.elasticsearch' => { 'hosts' => ['127.0.0.1:9200'] }
}

filebeat_config 'default' do
config conf
action :create
end
```

Above LWRP Resource will create a file `/etc/filebeat/filebeat.yml` with content:

```yaml
filebeat.modules: []
prospectors: []
logging.level: info
logging.to_files: true
logging.files:
path: "/var/log/filebeat"
output.elasticsearch:
hosts:
- 127.0.0.1:9200
filebeat.registry_file: "/var/lib/filebeat/registry"
filebeat.config.inputs:
enabled: true
path: "/etc/filebeat/conf.d/*.yml"
```
**LWRP Options**
- *action* (optional) - default `:create`, options: :create, :delete
Expand All @@ -212,8 +234,9 @@ filebeat.config_dir: "/etc/filebeat/conf.d"
- *prefix* (optional, String) - default `lwrp-prospector-`, filebeat prospecteor filename prefix, set to '' if no prefix is desired


## LWRP filebeat_prospector
## LWRP filebeat_prospector (inputs)

### Filebeat version up to 6.3
LWRP `filebeat_prospector` creates a filebeat prospector configuration yaml file under prospectors directory with file name `lwrp-prospector-#{resource_name}.yml`.
`lwrp-prospector-` prefix can be changed with `prefix` property (see above).

Expand Down Expand Up @@ -247,6 +270,36 @@ filebeat:
type: messages_log
```

### Filebeat version 6.3+

With `filebeat.config.inputs` set, Filebeat 6.3+ will read in the files as previous versions and the same config will work as expected

```ruby
conf = {
'type' => 'log',
'enabled' => true,
'paths' => ['/var/log/messages'],
'type' => 'log',
'fields' => {'type' => 'messages_log'}
}
filebeat_prospector 'messages_log' do
config conf
action :create
end
```

the file is created with content:

```yaml
- enabled: true
paths:
- "/var/log/messages"
type: log
fields:
type: messages_log
```

**LWRP Options**

- *action* (optional) - default `:create`, options: :create, :delete
Expand All @@ -257,7 +310,6 @@ filebeat:
- *disable_service* (optional, Boolean) - default `false`, set to `true`, to disable filebeat service
- *notify_restart* (optional, Boolean) - default `true`, set to `false`, to ignore filebeat service restart notify


## LWRP filebeat_runit_service

LWRP `filebeat_runit_service` configures `filebeat` service using `runit`.
Expand Down Expand Up @@ -286,12 +338,10 @@ end

Check out filebeat test cookbook [filebeat_test](test/cookbooks/filebeat_test).


## TODO

- Add other platforms support to install_preview resource


## Contributing

1. Fork the repository on Github
Expand All @@ -303,7 +353,6 @@ Check out filebeat test cookbook [filebeat_test](test/cookbooks/filebeat_test).
7. Write description about changes to PR
8. Submit a Pull Request using Github


## Copyright & License

Authors:: Virender Khatri and [Contributors]
Expand All @@ -322,7 +371,6 @@ See the License for the specific language governing permissions and
limitations under the License.
</pre>


[Chef]: https://www.chef.io/
[Filebeat]: https://www.elastic.co/products/beats/filebeat
[Contributors]: https://github.com/vkhatri/chef-filebeat/graphs/contributors
11 changes: 9 additions & 2 deletions resources/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Resource:: filebeat_config
#

default_config = { 'filebeat.prospectors' => [], 'filebeat.modules' => [], 'prospectors' => [] }
default_config = { 'filebeat.inputs' => [], 'filebeat.prospectors' => [], 'filebeat.modules' => [], 'prospectors' => [] }

resource_name :filebeat_config

Expand All @@ -29,8 +29,15 @@
logging_files_path = node['platform'] == 'windows' ? "#{filebeat_install_resource.conf_dir}/logs" : filebeat_install_resource.log_dir

config['filebeat.registry_file'] = node['platform'] == 'windows' ? "#{filebeat_install_resource.conf_dir}/registry" : '/var/lib/filebeat/registry'
config['filebeat.config_dir'] = filebeat_install_resource.prospectors_dir
config['logging.files']['path'] ||= logging_files_path
if filebeat_install_resource.version.to_f >= 6.0
config['filebeat.config.inputs'] ||= {
'enabled' => true,
'path' => "#{filebeat_install_resource.prospectors_dir}/*.yml",
}
else
config['filebeat.config_dir'] = filebeat_install_resource.prospectors_dir
end

# Filebeat and psych v1.x don't get along.
if Psych::VERSION.start_with?('1')
Expand Down
7 changes: 6 additions & 1 deletion resources/prospector.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,12 @@
end

# file_content = { 'filebeat' => { 'prospectors' => config } }.to_yaml
file_content = JSON.parse({ 'filebeat' => { 'prospectors' => config } }.to_json).to_yaml.lines.to_a[1..-1].join
file_content =
if filebeat_install_resource.version.to_f >= 6.3
JSON.parse(config.to_json).to_yaml.lines.to_a[1..-1].join
else
JSON.parse({ 'filebeat' => { 'prospectors' => config } }.to_json).to_yaml.lines.to_a[1..-1].join
end

# ...and put this back the way we found them.
YAML::ENGINE.yamler = defaultengine if Psych::VERSION.start_with?('1')
Expand Down
2 changes: 0 additions & 2 deletions test/cookbooks/filebeat_test/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
filebeat_test
=====


9 changes: 9 additions & 0 deletions test/smoke/v6/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@
end
end

describe file('/etc/filebeat/filebeat.yml') do
its('content') { should match 'filebeat.config.inputs' }
end

describe command('filebeat test config') do
its('exit_status') { should eq 0 }
its('stdout') { should match 'Config OK' }
end

describe package('filebeat') do
it { should be_installed }
its('version') { should match '6.4.2' }
Expand Down
4 changes: 4 additions & 0 deletions test/smoke/v6runit/default.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
describe command('filebeat test config') do
its('exit_status') { should eq 0 }
its('stdout') { should match 'Config OK' }
end

0 comments on commit a4daed4

Please sign in to comment.