Showing with 123 additions and 12 deletions.
  1. +1 −1 .gitattributes
  2. +8 −1 CHANGELOG.md
  3. +1 −0 README.md
  4. +4 −2 lib/facter/filebeat_version.rb
  5. +41 −1 manifests/config.pp
  6. +3 −1 manifests/init.pp
  7. +4 −0 manifests/install.pp
  8. +6 −0 manifests/install/openbsd.pp
  9. +28 −3 manifests/params.pp
  10. +2 −2 manifests/prospector.pp
  11. +9 −1 metadata.json
  12. +16 −0 spec/unit/facter/filebeat_version_spec.rb
2 changes: 1 addition & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
*.rb eol=lf
*.rb eol=lf linguist-language=Puppet
*.erb eol=lf
*.pp eol=lf
*.sh eol=lf
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,14 @@ Changelog
=========

## Unreleased
[Full Changelog](https://github.com/pcfens/puppet-filebeat/compare/v3.1.0...HEAD)
[Full Changelog](https://github.com/pcfens/puppet-filebeat/compare/v3.2.0...HEAD)

## [v3.2.0](https://github.com/pcfens/puppet-filebeat/tree/v3.2.0)
[Full Changelog](https://github.com/pcfens/puppet-filebeat/compare/v3.1.0...v3.2.0)

- Add support for xpack monitoring [\#172](https://github.com/pcfens/puppet-filebeat/pull/172)
- Add support for OpenBSD [\#173](https://github.com/pcfens/puppet-filebeat/pull/173)
- Set filebeat_version to false when filebeat isn't installed [\#175](https://github.com/pcfens/puppet-filebeat/pull/175)

## [v3.1.0](https://github.com/pcfens/puppet-filebeat/tree/v3.1.0)
[Full Changelog](https://github.com/pcfens/puppet-filebeat/compare/v3.0.1...v3.1.0)
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ Installs and configures filebeat.
- `processors`: [Hash] Processors that should be configured.
- `prospectors`: [Hash] Prospectors that will be created. Commonly used to create prospectors using hiera
- `setup`: [Hash] Setup that will be created. Commonly used to create setup using hiera
- `xpack`: [Hash] XPack configuration to pass to filebeat

### Private Classes

Expand Down
6 changes: 4 additions & 2 deletions lib/facter/filebeat_version.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
require 'facter'
Facter.add('filebeat_version') do
confine 'kernel' => %w[FreeBSD Linux Windows]
confine 'kernel' => %w[FreeBSD OpenBSD Linux Windows]
if File.executable?('/usr/bin/filebeat')
filebeat_version = Facter::Util::Resolution.exec('/usr/bin/filebeat version')
elsif File.executable?('/usr/local/bin/filebeat')
filebeat_version = Facter::Util::Resolution.exec('/usr/local/bin/filebeat --version')
elsif File.executable?('/usr/share/filebeat/bin/filebeat')
filebeat_version = Facter::Util::Resolution.exec('/usr/share/filebeat/bin/filebeat --version')
elsif File.executable?('/usr/local/sbin/filebeat')
Expand All @@ -11,6 +13,6 @@
filebeat_version = Facter::Util::Resolution.exec('"c:\Program Files\Filebeat\filebeat.exe" --version')
end
setcode do
%r{^filebeat version ([^\s]+)?}.match(filebeat_version)[1] unless filebeat_version.nil?
filebeat_version.nil? ? false : %r{^filebeat version ([^\s]+)?}.match(filebeat_version)[1]
end
end
42 changes: 41 additions & 1 deletion manifests/config.pp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
$major_version = $filebeat::major_version

if versioncmp($major_version, '6') >= 0 {
$filebeat_config = delete_undef_values({
$filebeat_config_temp = delete_undef_values({
'shutdown_timeout' => $filebeat::shutdown_timeout,
'name' => $filebeat::beat_name,
'tags' => $filebeat::tags,
Expand All @@ -30,6 +30,13 @@
'processors' => $filebeat::processors,
'setup' => $filebeat::setup,
})
# Add the 'xpack' section if supported (version >= 6.1.0)
if versioncmp($filebeat::package_ensure, '6.1.0') >= 0 {
$filebeat_config = deep_merge($filebeat_config_temp, {'xpack' => $filebeat::xpack})
}
else {
$filebeat_config = $filebeat_config_temp
}
} else {
$filebeat_config_temp = delete_undef_values({
'shutdown_timeout' => $filebeat::shutdown_timeout,
Expand Down Expand Up @@ -137,6 +144,39 @@
}
} # end FreeBSD

'OpenBSD' : {
$validate_cmd = ($filebeat::disable_config_test or $skip_validation) ? {
true => undef,
default => $major_version ? {
'5' => "${filebeat::filebeat_path} -N -configtest -c %",
default => "${filebeat::filebeat_path} -c % test config",
},
}

file {'filebeat.yml':
ensure => $filebeat::file_ensure,
path => $filebeat::config_file,
content => template($filebeat::conf_template),
owner => $filebeat::config_file_owner,
group => $filebeat::config_file_group,
mode => $filebeat::config_file_mode,
validate_cmd => $validate_cmd,
notify => Service['filebeat'],
require => File['filebeat-config-dir'],
}

file {'filebeat-config-dir':
ensure => $filebeat::directory_ensure,
path => $filebeat::config_dir,
owner => $filebeat::config_dir_owner,
group => $filebeat::config_dir_group,
mode => $filebeat::config_dir_mode,
recurse => $filebeat::purge_conf_dir,
purge => $filebeat::purge_conf_dir,
force => true,
}
} # end OpenBSD

'Windows' : {
$cmd_install_dir = regsubst($filebeat::install_dir, '/', '\\', 'G')
$filebeat_path = join([$cmd_install_dir, 'Filebeat', 'filebeat.exe'], '\\')
Expand Down
4 changes: 3 additions & 1 deletion manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
# @param setup [Hash] setup that will be created. Commonly used to create setup using hiera
# @param prospectors_merge [Boolean] Whether $prospectors should merge all hiera sources, or use simple automatic parameter lookup
# proxy_address [String] Proxy server to use for downloading files
# @param xpack [Hash] Configuration items to export internal stats to a monitoring Elasticsearch cluster
class filebeat (
String $package_ensure = $filebeat::params::package_ensure,
Boolean $manage_repo = $filebeat::params::manage_repo,
Expand Down Expand Up @@ -88,7 +89,8 @@
Hash $setup = {},
Array $modules = [],
Optional[Variant[Stdlib::HTTPUrl, Stdlib::HTTPSUrl]] $proxy_address = undef, # lint:ignore:140chars
Stdlib::Absolutepath $filebeat_path = $filebeat::params::filebeat_path
Stdlib::Absolutepath $filebeat_path = $filebeat::params::filebeat_path,
Optional[Hash] $xpack = $filebeat::params::xpack,
) inherits filebeat::params {

include ::stdlib
Expand Down
4 changes: 4 additions & 0 deletions manifests/install.pp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
}
Anchor['filebeat::install::begin'] -> Class['filebeat::install::freebsd'] -> Anchor['filebeat::install::end']
}
'OpenBSD': {
class{'filebeat::install::openbsd':}
Anchor['filebeat::install::begin'] -> Class['filebeat::install::openbsd'] -> Anchor['filebeat::install::end']
}
'Windows': {
class{'::filebeat::install::windows':
notify => Class['filebeat::service'],
Expand Down
6 changes: 6 additions & 0 deletions manifests/install/openbsd.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# to manage filebeat installation on OpenBSD
class filebeat::install::openbsd {
package {'filebeat':
ensure => $filebeat::package_ensure,
}
}
31 changes: 28 additions & 3 deletions manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
$osfamily_fail_message = "${::osfamily} is not supported by filebeat."
$conf_template = "${module_name}/pure_hash.yml.erb"
$disable_config_test = false
$xpack = undef

# These are irrelevant as long as the template is set based on the major_version parameter
# if versioncmp('1.9.1', $::rubyversion) > 0 {
Expand All @@ -37,14 +38,24 @@
# }
#

# Archlinux has a proper package in the official repos
# we shouldn't manage the repo on it
# Archlinux and OpenBSD have proper packages in the official repos
# we shouldn't manage the repo on them
case $facts['os']['family'] {
'Archlinux': {
$manage_repo = false
$filebeat_path = '/usr/bin/filebeat'
$major_version = '6'
}
'OpenBSD': {
$manage_repo = false
$filebeat_path = '/usr/local/bin/filebeat'
# lint:ignore:only_variable_string
$major_version = versioncmp('6.3', "${::kernelversion}") < 0 ? {
# lint:endignore
true => '6',
default => '5'
}
}
default: {
$manage_repo = true
$filebeat_path = '/usr/share/filebeat/bin/filebeat'
Expand All @@ -61,7 +72,6 @@
$config_dir_owner = 'root'
$config_dir_group = 'root'
$registry_file = '/var/lib/filebeat/registry'

# These parameters are ignored if/until tarball installs are supported in Linux
$tmp_dir = '/tmp'
$install_dir = undef
Expand Down Expand Up @@ -91,6 +101,21 @@
$url_arch = undef
}

'OpenBSD': {
$package_ensure = present
$config_file = '/etc/filebeat/filebeat.yml'
$config_dir = '/etc/filebeat/conf.d'
$config_file_owner = 'root'
$config_file_group = 'wheel'
$config_dir_owner = 'root'
$config_dir_group = 'wheel'
$registry_file = '/var/db/filebeat/.filebeat'
$tmp_dir = '/tmp'
$service_provider = undef
$install_dir = undef
$url_arch = undef
}

'Windows' : {
$package_ensure = '5.6.2'
$config_file_owner = 'Administrator'
Expand Down
4 changes: 2 additions & 2 deletions manifests/prospector.pp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
}

case $::kernel {
'Linux' : {
'Linux', 'OpenBSD' : {
$validate_cmd = ($filebeat::disable_config_test or $skip_validation) ? {
true => undef,
default => $filebeat::major_version ? {
Expand All @@ -69,7 +69,7 @@
ensure => $ensure,
path => "${filebeat::config_dir}/${name}.yml",
owner => 'root',
group => 'root',
group => '0',
mode => $::filebeat::config_file_mode,
content => template("${module_name}/${prospector_template}"),
validate_cmd => $validate_cmd,
Expand Down
10 changes: 9 additions & 1 deletion metadata.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "pcfens-filebeat",
"version": "3.1.0",
"version": "3.2.0",
"author": "pcfens",
"summary": "A module to install and manage the filebeat log shipper",
"license": "Apache-2.0",
Expand Down Expand Up @@ -64,6 +64,14 @@
"8"
]
},
{
"operatingsystem": "OpenBSD",
"operatingsystemrelease": [
"6.1",
"6.2",
"6.3"
]
},
{
"operatingsystem": "Ubuntu",
"operatingsystemrelease": [
Expand Down
16 changes: 16 additions & 0 deletions spec/unit/facter/filebeat_version_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,20 @@
expect(Facter.fact(:filebeat_version).value).to eq('5.1.1')
end
end

context 'when the filebeat package is not installed' do
before :each do
File.stubs(:executable?)
Facter::Util::Resolution.stubs(:exec)
File.expects(:executable?).with('/usr/bin/filebeat').returns false
File.expects(:executable?).with('/usr/local/bin/filebeat').returns false
File.expects(:executable?).with('/usr/share/filebeat/bin/filebeat').returns false
File.expects(:executable?).with('/usr/local/sbin/filebeat').returns false
File.stubs(:exist?)
File.expects(:exist?).with('c:\Program Files\Filebeat\filebeat.exe').returns false
end
it 'returns false' do
expect(Facter.fact(:filebeat_version).value).to eq(false)
end
end
end