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

Add support for Filebeat 6 #141

Merged
merged 1 commit into from
Nov 20, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
72 changes: 49 additions & 23 deletions manifests/config.pp
Original file line number Diff line number Diff line change
Expand Up @@ -4,36 +4,62 @@
#
# @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']

case $::kernel {
'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':
Expand Down
2 changes: 2 additions & 0 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions manifests/repo.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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': {
Expand Down
142 changes: 76 additions & 66 deletions spec/acceptance/001_basic_spec.rb
Original file line number Diff line number Diff line change
@@ -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
Loading