diff --git a/CHANGELOG.md b/CHANGELOG.md index 30e5981..1b7f2b6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,8 @@ Changelog ## Unreleased [Full Changelog](https://github.com/pcfens/puppet-filebeat/compare/v2.2.0...HEAD) +- Add support for Filebeat 6 + ## [v2.2.0](https://github.com/pcfens/puppet-filebeat/tree/v2.2.0) [Full Changelog](https://github.com/pcfens/puppet-filebeat/compare/v2.1.0...v2.2.0) diff --git a/README.md b/README.md index 654641c..85df8d8 100644 --- a/README.md +++ b/README.md @@ -36,6 +36,11 @@ The `filebeat` module installs and configures the [filebeat log shipper](https:/ By default `filebeat` adds a software repository to your system, and installs filebeat along with required configurations. +### Upgrading to Filebeat 6.x + +To upgrade to Filebeat 6.x, simply set `$filebeat::major_version` to `6` and `$filebeat::package_ensure` to `latest`. + + ### Setup Requirements The `filebeat` module depends on [`puppetlabs/stdlib`](https://forge.puppetlabs.com/puppetlabs/stdlib), and on @@ -220,6 +225,7 @@ Installs and configures filebeat. prospectors and processors passed as parameters are ignored and everything managed by puppet will be removed. (default: present) - `manage_repo`: [Boolean] Whether or not the upstream (elastic) repo should be configured or not (default: true) +- `major_version`: [Enum] The major version of Filebeat to install. Should be either `5` or `6`. The default value is `5`. - `service_ensure`: [String] The ensure parameter on the filebeat service (default: running) - `service_enable`: [String] The enable parameter on the filebeat service (default: true) - `param repo_priority`: [Integer] Repository priority. yum and apt supported (default: undef) diff --git a/manifests/config.pp b/manifests/config.pp index 5be928a..cba75f9 100644 --- a/manifests/config.pp +++ b/manifests/config.pp @@ -4,28 +4,51 @@ # # @summary A private class to manage the filebeat config file class filebeat::config { - $filebeat_config = delete_undef_values({ - 'shutdown_timeout' => $filebeat::shutdown_timeout, - 'name' => $filebeat::beat_name, - 'tags' => $filebeat::tags, - 'queue_size' => $filebeat::queue_size, - 'max_procs' => $filebeat::max_procs, - 'fields' => $filebeat::fields, - 'fields_under_root' => $filebeat::fields_under_root, - 'filebeat' => { - 'spool_size' => $filebeat::spool_size, - 'idle_timeout' => $filebeat::idle_timeout, - 'registry_file' => $filebeat::registry_file, - 'publish_async' => $filebeat::publish_async, - 'config_dir' => $filebeat::config_dir, - 'shutdown_timeout' => $filebeat::shutdown_timeout, - }, - 'output' => $filebeat::outputs, - 'shipper' => $filebeat::shipper, - 'logging' => $filebeat::logging, - 'runoptions' => $filebeat::run_options, - 'processors' => $filebeat::processors, - }) + $major_version = $filebeat::major_version + + if versioncmp($major_version, '6') >= 0 { + $filebeat_config = delete_undef_values({ + 'shutdown_timeout' => $filebeat::shutdown_timeout, + 'name' => $filebeat::beat_name, + 'tags' => $filebeat::tags, + 'max_procs' => $filebeat::max_procs, + 'fields' => $filebeat::fields, + 'fields_under_root' => $filebeat::fields_under_root, + 'filebeat' => { + 'registry_file' => $filebeat::registry_file, + 'config_dir' => $filebeat::config_dir, + 'shutdown_timeout' => $filebeat::shutdown_timeout, + }, + 'output' => $filebeat::outputs, + 'shipper' => $filebeat::shipper, + 'logging' => $filebeat::logging, + 'runoptions' => $filebeat::run_options, + 'processors' => $filebeat::processors, + }) + } else { + $filebeat_config = delete_undef_values({ + 'shutdown_timeout' => $filebeat::shutdown_timeout, + 'name' => $filebeat::beat_name, + 'tags' => $filebeat::tags, + 'queue_size' => $filebeat::queue_size, + 'max_procs' => $filebeat::max_procs, + 'fields' => $filebeat::fields, + 'fields_under_root' => $filebeat::fields_under_root, + 'filebeat' => { + 'spool_size' => $filebeat::spool_size, + 'idle_timeout' => $filebeat::idle_timeout, + 'registry_file' => $filebeat::registry_file, + 'publish_async' => $filebeat::publish_async, + 'config_dir' => $filebeat::config_dir, + 'shutdown_timeout' => $filebeat::shutdown_timeout, + }, + 'output' => $filebeat::outputs, + 'shipper' => $filebeat::shipper, + 'logging' => $filebeat::logging, + 'runoptions' => $filebeat::run_options, + 'processors' => $filebeat::processors, + }) + } Filebeat::Prospector <| |> -> File['filebeat.yml'] @@ -33,7 +56,10 @@ 'Linux' : { $validate_cmd = $filebeat::disable_config_test ? { true => undef, - default => '/usr/share/filebeat/bin/filebeat -N -configtest -c %', + default => $major_version ? { + '5' => '/usr/share/filebeat/bin/filebeat -N -configtest -c %', + default => '/usr/share/filebeat/bin/filebeat -c % test config', + }, } file {'filebeat.yml': diff --git a/manifests/init.pp b/manifests/init.pp index fc2c85f..3827783 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -14,6 +14,7 @@ # # @param package_ensure [String] The ensure parameter for the filebeat package (default: present) # @param manage_repo [Boolean] Whether or not the upstream (elastic) repo should be configured or not (default: true) +# @param major_version [Enum] The major version of Filebeat to be installed. # @param service_ensure [String] The ensure parameter on the filebeat service (default: running) # @param service_enable [String] The enable parameter on the filebeat service (default: true) # @param repo_priority [Integer] Repository priority. yum and apt supported (default: undef) @@ -46,6 +47,7 @@ class filebeat ( String $package_ensure = $filebeat::params::package_ensure, Boolean $manage_repo = $filebeat::params::manage_repo, + Enum['5','6'] $major_version = $filebeat::params::major_version, Variant[Boolean, Enum['stopped', 'running']] $service_ensure = $filebeat::params::service_ensure, Boolean $service_enable = $filebeat::params::service_enable, Optional[String] $service_provider = $filebeat::params::service_provider, diff --git a/manifests/params.pp b/manifests/params.pp index 950cb53..f986e5c 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -5,6 +5,7 @@ # @summary Set a bunch of default parameters class filebeat::params { $manage_repo = true + $major_version = '5' $service_ensure = running $service_enable = true $spool_size = 2048 diff --git a/manifests/repo.pp b/manifests/repo.pp index cc13af4..8133466 100644 --- a/manifests/repo.pp +++ b/manifests/repo.pp @@ -4,8 +4,8 @@ # # @summary Manages the yum, apt, and zypp repositories for Filebeat class filebeat::repo { - $debian_repo_url = 'https://artifacts.elastic.co/packages/5.x/apt' - $yum_repo_url = 'https://artifacts.elastic.co/packages/5.x/yum' + $debian_repo_url = "https://artifacts.elastic.co/packages/${filebeat::major_version}.x/apt" + $yum_repo_url = "https://artifacts.elastic.co/packages/${filebeat::major_version}.x/yum" case $::osfamily { 'Debian': { diff --git a/spec/acceptance/001_basic_spec.rb b/spec/acceptance/001_basic_spec.rb index 3837b6e..433cf91 100644 --- a/spec/acceptance/001_basic_spec.rb +++ b/spec/acceptance/001_basic_spec.rb @@ -1,82 +1,92 @@ require 'spec_helper_acceptance' -describe 'filebeat class' do - package_name = 'filebeat' - service_name = 'filebeat' +RSpec.shared_examples 'filebeat' do + describe package('filebeat') do + it { is_expected.to be_installed } + end - context 'default parameters' do - let(:pp) do - <<-EOS - if $::osfamily == 'Debian' { - include ::apt + describe service('filebeat') do + it { is_expected.to be_enabled } + it { is_expected.to be_running } + end - package { 'apt-transport-https': - ensure => present, - } + describe file('/etc/filebeat/filebeat.yml') do + it { is_expected.to be_file } + it { is_expected.to contain('---') } + it { is_expected.not_to contain('max_procs: !ruby') } + end +end + +describe 'filebeat class' do + let(:pp) do + <<-EOS + if $::osfamily == 'Debian' { + include ::apt + + package { 'apt-transport-https': + ensure => present, } + } - class { 'filebeat': - outputs => { - 'logstash' => { - 'bulk_max_size' => 1024, - 'hosts' => [ - 'localhost:5044', - ], - }, - 'file' => { - 'path' => '/tmp', - 'filename' => 'filebeat', - 'rotate_every_kb' => 10240, - 'number_of_files' => 2, - }, - }, - shipper => { - refresh_topology_freq => 10, - topology_expire => 15, - queue_size => 1000, + class { 'filebeat': + major_version => '#{major_version}', + outputs => { + 'logstash' => { + 'bulk_max_size' => 1024, + 'hosts' => [ + 'localhost:5044', + ], }, - logging => { - files => { - rotateeverybytes => 10485760, - keepfiles => 7, - } + 'file' => { + 'path' => '/tmp', + 'filename' => 'filebeat', + 'rotate_every_kb' => 10240, + 'number_of_files' => 2, }, - prospectors => { - 'system-logs' => { - doc_type => 'system', - paths => [ - '/var/log/dmesg', - ], - fields => { - service => 'system', - file => 'dmesg', - }, - tags => [ - 'tag1', - 'tag2', - 'tag3', - ] - } + }, + shipper => { + refresh_topology_freq => 10, + topology_expire => 15, + queue_size => 1000, + }, + logging => { + files => { + rotateeverybytes => 10485760, + keepfiles => 7, + } + }, + prospectors => { + 'system-logs' => { + doc_type => 'system', + paths => [ + '/var/log/dmesg', + ], + fields => { + service => 'system', + file => 'dmesg', + }, + tags => [ + 'tag1', + 'tag2', + 'tag3', + ] } } - EOS - end + } + EOS + end - it_behaves_like 'an idempotent resource' + context 'with $major_version = 5' do + let(:major_version) { 5 } - describe service(service_name) do - it { is_expected.to be_enabled } - it { is_expected.to be_running } - end + it_behaves_like 'an idempotent resource' + include_examples 'filebeat' + end - describe package(package_name) do - it { is_expected.to be_installed } - end + context 'with $major_version = 6' do + let(:major_version) { 6 } - describe file('/etc/filebeat/filebeat.yml') do - it { is_expected.to be_file } - it { is_expected.to contain('---') } - it { is_expected.not_to contain('max_procs: !ruby') } - end + it_behaves_like 'an idempotent resource' + include_examples 'filebeat' end end diff --git a/spec/classes/config_spec.rb b/spec/classes/config_spec.rb index 82967ce..b89b946 100644 --- a/spec/classes/config_spec.rb +++ b/spec/classes/config_spec.rb @@ -8,52 +8,68 @@ on_supported_os(facterversion: '2.4').each do |os, os_facts| context "on #{os}" do let(:facts) { os_facts } + let(:pre_condition) { "class { 'filebeat': major_version => '#{major_version}' }" } - case os_facts[:kernel] - when 'Linux' - it { is_expected.to compile } - it { - is_expected.to contain_file('filebeat.yml').with( - ensure: 'file', - path: '/etc/filebeat/filebeat.yml', - owner: 'root', - group: 'root', - mode: '0644', - validate_cmd: '/usr/share/filebeat/bin/filebeat -N -configtest -c %', - notify: 'Service[filebeat]', - require: 'File[filebeat-config-dir]', - ) - } + [5, 6].each do |version| + context "with $major_version == #{version}" do + let(:major_version) { version } - it { - is_expected.to contain_file('filebeat-config-dir').with( - ensure: 'directory', - path: '/etc/filebeat/conf.d', - owner: 'root', - group: 'root', - mode: '0755', - recurse: true, - purge: true, - ) - } - when 'Windows' - it { - is_expected.to contain_file('filebeat.yml').with( - ensure: 'file', - path: 'C:/Program Files/Filebeat/filebeat.yml', - notify: 'Service[filebeat]', - require: 'File[filebeat-config-dir]', - ) - } + let(:validate_cmd) do + case major_version + when 5 + '/usr/share/filebeat/bin/filebeat -N -configtest -c %' + else + '/usr/share/filebeat/bin/filebeat -c % test config' + end + end - it { - is_expected.to contain_file('filebeat-config-dir').with( - ensure: 'directory', - path: 'C:/Program Files/Filebeat/conf.d', - recurse: true, - purge: true, - ) - } + case os_facts[:kernel] + when 'Linux' + it { is_expected.to compile } + it { + is_expected.to contain_file('filebeat.yml').with( + ensure: 'file', + path: '/etc/filebeat/filebeat.yml', + owner: 'root', + group: 'root', + mode: '0644', + validate_cmd: validate_cmd, + notify: 'Service[filebeat]', + require: 'File[filebeat-config-dir]', + ) + } + + it { + is_expected.to contain_file('filebeat-config-dir').with( + ensure: 'directory', + path: '/etc/filebeat/conf.d', + owner: 'root', + group: 'root', + mode: '0755', + recurse: true, + purge: true, + ) + } + when 'Windows' + it { + is_expected.to contain_file('filebeat.yml').with( + ensure: 'file', + path: 'C:/Program Files/Filebeat/filebeat.yml', + notify: 'Service[filebeat]', + require: 'File[filebeat-config-dir]', + ) + } + + it { + is_expected.to contain_file('filebeat-config-dir').with( + ensure: 'directory', + path: 'C:/Program Files/Filebeat/conf.d', + recurse: true, + purge: true, + ) + } + end + end end end end diff --git a/spec/classes/repo_spec.rb b/spec/classes/repo_spec.rb index f09ac53..3016b65 100644 --- a/spec/classes/repo_spec.rb +++ b/spec/classes/repo_spec.rb @@ -1,35 +1,38 @@ require 'spec_helper' describe 'filebeat::repo' do - let :pre_condition do - 'include ::filebeat' - end - on_supported_os(facterversion: '2.4').each do |os, os_facts| context "on #{os}" do let(:facts) { os_facts } + let(:pre_condition) { "class { 'filebeat': major_version => '#{major_version}' }" } + + [5, 6].each do |version| + context "with $major_version == #{version}" do + let(:major_version) { version } - case os_facts[:kernel] - when 'Linux' - it { is_expected.to compile } - case os_facts[:osfamily] - when 'Debian' - it { - is_expected.to contain_apt__source('beats').with( - ensure: 'present', - location: 'https://artifacts.elastic.co/packages/5.x/apt', - ) - } - when 'RedHat' - it { - is_expected.to contain_yumrepo('beats').with( - ensure: 'present', - baseurl: 'https://artifacts.elastic.co/packages/5.x/yum', - ) - } + case os_facts[:kernel] + when 'Linux' + it { is_expected.to compile } + case os_facts[:osfamily] + when 'Debian' + it { + is_expected.to contain_apt__source('beats').with( + ensure: 'present', + location: "https://artifacts.elastic.co/packages/#{major_version}.x/apt", + ) + } + when 'RedHat' + it { + is_expected.to contain_yumrepo('beats').with( + ensure: 'present', + baseurl: "https://artifacts.elastic.co/packages/#{major_version}.x/yum", + ) + } + end + else + it { is_expected.not_to compile } + end end - else - it { is_expected.not_to compile } end end end diff --git a/templates/filebeat.yml.erb b/templates/filebeat.yml.erb index aaa4565..9b9435a 100644 --- a/templates/filebeat.yml.erb +++ b/templates/filebeat.yml.erb @@ -1,8 +1,10 @@ #========================= Filebeat global options ============================ +<% unless scope.function_versioncmp([@major_version, '6']) >= 0 -%> filebeat.spool_size: <%= @filebeat_config['filebeat']['spool_size'] %> filebeat.publish_async: <%= @filebeat_config['filebeat']['publish_async'] %> filebeat.idle_timeout: <%= @filebeat_config['filebeat']['idle_timeout'] %> +<% end -%> filebeat.registry_file: <%= @filebeat_config['filebeat']['registry_file'] %> filebeat.config_dir: <%= @filebeat_config['filebeat']['config_dir'] %> filebeat.shutdown_timeout: <%= @filebeat_config['filebeat']['shutdown_timeout'] %> @@ -25,7 +27,9 @@ fields: <%- end -%> fields_under_root: <%= @filebeat_config['fields_under_root'] %> +<% unless scope.function_versioncmp([@major_version, '6']) >= 0 -%> queue_size: <%= @filebeat_config['queue_size'] %> +<% end -%> # The internal queue size for bulk events in the processing pipeline. # Do not modify this value. diff --git a/templates/prospector.yml.erb b/templates/prospector.yml.erb index 6ca052a..1d1fcfa 100644 --- a/templates/prospector.yml.erb +++ b/templates/prospector.yml.erb @@ -1,7 +1,7 @@ --- filebeat: prospectors: - - input_type: <%= @input_type %> + - <% if scope.function_versioncmp([scope.lookupvar('filebeat::major_version'), '6']) >= 0 %>type<% else %>input_type<% end %>: <%= @input_type %> paths: <%- @paths.each do |log_path| -%> - <%= log_path %>