7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,13 @@ Changelog
=========

## Unreleased
[Full Changelog](https://github.com/pcfens/puppet-filebeat/compare/v2.3.0...HEAD)
[Full Changelog](https://github.com/pcfens/puppet-filebeat/compare/v2.4.0...HEAD)

## [v2.4.0](https://github.com/pcfens/puppet-filebeat/tree/v2.4.0)
[Full Changelog](https://github.com/pcfens/puppet-filebeat/compare/v2.3.0...v2.4.0)

- Add support for FreeBSD [\#130](https://github.com/pcfens/puppet-filebeat/pull/130)
- Add support for Archlinux [\#147](https://github.com/pcfens/puppet-filebeat/pull/147)

## [v2.3.0](https://github.com/pcfens/puppet-filebeat/tree/v2.3.0)
[Full Changelog](https://github.com/pcfens/puppet-filebeat/compare/v2.2.0...v2.3.0)
Expand Down
4 changes: 3 additions & 1 deletion lib/facter/filebeat_version.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
require 'facter'
Facter.add('filebeat_version') do
confine 'kernel' => %w[Linux Windows]
confine 'kernel' => %w[FreeBSD Linux Windows]
if File.executable?('/usr/bin/filebeat')
filebeat_version = Facter::Util::Resolution.exec('/usr/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')
filebeat_version = Facter::Util::Resolution.exec('/usr/local/sbin/filebeat --version')
elsif File.exist?('c:\Program Files\Filebeat\filebeat.exe')
filebeat_version = Facter::Util::Resolution.exec('"c:\Program Files\Filebeat\filebeat.exe" --version')
end
Expand Down
34 changes: 32 additions & 2 deletions manifests/config.pp
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@
$validate_cmd = $filebeat::disable_config_test ? {
true => undef,
default => $major_version ? {
'5' => '/usr/share/filebeat/bin/filebeat -N -configtest -c %',
default => '/usr/share/filebeat/bin/filebeat -c % test config',
'5' => "${filebeat::filebeat_path} -N -configtest -c %",
default => "${filebeat::filebeat_path} -c % test config",
},
}

Expand Down Expand Up @@ -86,6 +86,36 @@
}
} # end Linux

'FreeBSD' : {
$validate_cmd = $filebeat::disable_config_test ? {
true => undef,
default => '/usr/local/sbin/filebeat -N -configtest -c %',
}

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 FreeBSD

'Windows' : {
$cmd_install_dir = regsubst($filebeat::install_dir, '/', '\\', 'G')
$filebeat_path = join([$cmd_install_dir, 'Filebeat', 'filebeat.exe'], '\\')
Expand Down
79 changes: 40 additions & 39 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -45,45 +45,46 @@
# @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
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,
Optional[Integer] $repo_priority = undef,
Integer $spool_size = $filebeat::params::spool_size,
String $idle_timeout = $filebeat::params::idle_timeout,
Boolean $publish_async = $filebeat::params::publish_async,
String $registry_file = $filebeat::params::registry_file,
String $config_file = $filebeat::params::config_file,
Optional[String] $config_file_owner = $filebeat::params::config_file_owner,
Optional[String] $config_file_group = $filebeat::params::config_file_group,
String[4,4] $config_dir_mode = $filebeat::params::config_dir_mode,
String $config_dir = $filebeat::params::config_dir,
String[4,4] $config_file_mode = $filebeat::params::config_file_mode,
Optional[String] $config_dir_owner = $filebeat::params::config_dir_owner,
Optional[String] $config_dir_group = $filebeat::params::config_dir_group,
Boolean $purge_conf_dir = $filebeat::params::purge_conf_dir,
Hash $outputs = $filebeat::params::outputs,
Hash $shipper = $filebeat::params::shipper,
Hash $logging = $filebeat::params::logging,
Hash $run_options = $filebeat::params::run_options,
String $conf_template = $filebeat::params::conf_template,
Optional[Pattern[/^(http(?:s)?\:\/\/[a-zA-Z0-9]+(?:(?:\.|\-)[a-zA-Z0-9]+)+(?:\:\d+)?(?:\/[\w\-\.]+)*(?:\/?|\/\w+\.[a-zA-Z]{2,4}(?:\?[\w]+\=[\w\-]+)?)?(?:\&[\w]+\=[\w\-]+)*)$/]] $download_url = undef, # lint:ignore:140chars
Optional[String] $install_dir = $filebeat::params::install_dir,
String $tmp_dir = $filebeat::params::tmp_dir,
Integer $shutdown_timeout = $filebeat::params::shutdown_timeout,
String $beat_name = $filebeat::params::beat_name,
Array $tags = $filebeat::params::tags,
Integer $queue_size = $filebeat::params::queue_size,
Optional[Integer] $max_procs = $filebeat::params::max_procs,
Hash $fields = $filebeat::params::fields,
Boolean $fields_under_root = $filebeat::params::fields_under_root,
Boolean $disable_config_test = $filebeat::params::disable_config_test,
Hash $processors = {},
Hash $prospectors = {},
Optional[Pattern[/^(http(?:s)?\:\/\/[a-zA-Z0-9]+(?:(?:\.|\-)[a-zA-Z0-9]+)+(?:\:\d+)?(?:\/[\w\-\.]+)*(?:\/?|\/\w+\.[a-zA-Z]{2,4}(?:\?[\w]+\=[\w\-]+)?)?(?:\&[\w]+\=[\w\-]+)*)$/]] $proxy_address = undef # lint:ignore:140chars
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,
Optional[Integer] $repo_priority = undef,
Integer $spool_size = $filebeat::params::spool_size,
String $idle_timeout = $filebeat::params::idle_timeout,
Boolean $publish_async = $filebeat::params::publish_async,
String $registry_file = $filebeat::params::registry_file,
String $config_file = $filebeat::params::config_file,
Optional[String] $config_file_owner = $filebeat::params::config_file_owner,
Optional[String] $config_file_group = $filebeat::params::config_file_group,
String[4,4] $config_dir_mode = $filebeat::params::config_dir_mode,
String $config_dir = $filebeat::params::config_dir,
String[4,4] $config_file_mode = $filebeat::params::config_file_mode,
Optional[String] $config_dir_owner = $filebeat::params::config_dir_owner,
Optional[String] $config_dir_group = $filebeat::params::config_dir_group,
Boolean $purge_conf_dir = $filebeat::params::purge_conf_dir,
Hash $outputs = $filebeat::params::outputs,
Hash $shipper = $filebeat::params::shipper,
Hash $logging = $filebeat::params::logging,
Hash $run_options = $filebeat::params::run_options,
String $conf_template = $filebeat::params::conf_template,
Optional[Pattern[/^(http(?:s)?\:\/\/[a-zA-Z0-9]+(?:(?:\.|\-)[a-zA-Z0-9]+)+(?:\:\d+)?(?:\/[\w\-\.]+)*(?:\/?|\/\w+\.[a-zA-Z]{2,4}(?:\?[\w]+\ = [\w\-]+)?)?(?:\&[\w]+\=[\w\-]+)*)$/]] $download_url = undef, # lint:ignore:140chars
Optional[String] $install_dir = $filebeat::params::install_dir,
String $tmp_dir = $filebeat::params::tmp_dir,
Integer $shutdown_timeout = $filebeat::params::shutdown_timeout,
String $beat_name = $filebeat::params::beat_name,
Array $tags = $filebeat::params::tags,
Integer $queue_size = $filebeat::params::queue_size,
Optional[Integer] $max_procs = $filebeat::params::max_procs,
Hash $fields = $filebeat::params::fields,
Boolean $fields_under_root = $filebeat::params::fields_under_root,
Boolean $disable_config_test = $filebeat::params::disable_config_test,
Hash $processors = {},
Hash $prospectors = {},
Optional[Pattern[/^(http(?:s)?\:\/\/[a-zA-Z0-9]+(?:(?:\.|\-)[a-zA-Z0-9]+)+(?:\:\d+)?(?:\/[\w\-\.]+)*(?:\/?|\/\w+\.[a-zA-Z]{2,4}(?:\?[\w]+\ = [\w\-]+)?)?(?:\&[\w]+\=[\w\-]+)*)$/]] $proxy_address = undef, # lint:ignore:140chars
Stdlib::Absolutepath $filebeat_path = $filebeat::params::filebeat_path
) inherits filebeat::params {

include ::stdlib
Expand Down
6 changes: 6 additions & 0 deletions manifests/install.pp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@
Class['filebeat::repo'] -> Class['filebeat::install::linux']
}
}
'FreeBSD': {
class{ '::filebeat::install::freebsd':
notify => Class['filebeat::service'],
}
Anchor['filebeat::install::begin'] -> Class['filebeat::install::freebsd'] -> Anchor['filebeat::install::end']
}
'Windows': {
class{'::filebeat::install::windows':
notify => Class['filebeat::service'],
Expand Down
13 changes: 13 additions & 0 deletions manifests/install/freebsd.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# filebeat::install::freebsd
#
# Install the FreeBSD filebeat package
#
# @summary A simple class to install the filebeat package
#
class filebeat::install::freebsd {

# filebeat, heartbeat, metricbeat, packetbeat are all contained in a
# single FreeBSD Package (see https://www.freshports.org/sysutils/beats/ )
ensure_packages (['beats'], {ensure => $filebeat::package_ensure})

}
58 changes: 48 additions & 10 deletions manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
#
# @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 All @@ -29,17 +27,38 @@
$conf_template = "${module_name}/pure_hash.yml.erb"
$disable_config_test = false

$config_file_owner = 'root'
$config_file_group = 'root'
$config_dir_owner = 'root'
$config_dir_group = 'root'
# These are irrelevant as long as the template is set based on the major_version parameter
# if versioncmp('1.9.1', $::rubyversion) > 0 {
# $conf_template = "${module_name}/filebeat.yml.ruby18.erb"
# } else {
# $conf_template = "${module_name}/filebeat.yml.erb"
# }
#

# Archlinux has a proper package in the official repos
# we shouldn't manage the repo on it
case $facts['os']['family'] {
'Archlinux': {
$manage_repo = false
$filebeat_path = '/usr/bin/filebeat'
$major_version = '6'
}
default: {
$manage_repo = true
$filebeat_path = '/usr/share/filebeat/bin/filebeat'
$major_version = '5'
}
}
case $::kernel {
'Linux' : {
$package_ensure = present
$config_file = '/etc/filebeat/filebeat.yml'
$config_dir = '/etc/filebeat/conf.d'
$registry_file = '/var/lib/filebeat/registry'
$package_ensure = present
$config_file = '/etc/filebeat/filebeat.yml'
$config_dir = '/etc/filebeat/conf.d'
$config_file_owner = 'root'
$config_file_group = 'root'
$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'
Expand All @@ -55,8 +74,27 @@
$url_arch = undef
}

'FreeBSD': {
$package_ensure = present
$config_file = '/usr/local/etc/filebeat.yml'
$config_dir = '/usr/local/etc/filebeat.d'
$config_file_owner = 'root'
$config_file_group = 'wheel'
$config_dir_owner = 'root'
$config_dir_group = 'wheel'
$registry_file = '/var/lib/filebeat/registry'
$tmp_dir = '/tmp'
$service_provider = undef
$install_dir = undef
$url_arch = undef
}

'Windows' : {
$package_ensure = '5.6.2'
$config_file_owner = 'Administrator'
$config_file_group = undef
$config_dir_owner = 'Administrator'
$config_dir_group = undef
$config_file = 'C:/Program Files/Filebeat/filebeat.yml'
$config_dir = 'C:/Program Files/Filebeat/conf.d'
$registry_file = 'C:/ProgramData/filebeat/registry'
Expand Down
30 changes: 28 additions & 2 deletions manifests/prospector.pp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
group => 'root',
mode => $::filebeat::config_file_mode,
content => template("${module_name}/${prospector_template}"),
validate_cmd => '/usr/share/filebeat/bin/filebeat -N -configtest -c %',
validate_cmd => "${filebeat::filebeat_path} -N -configtest -c %",
notify => Service['filebeat'],
}
} else {
Expand All @@ -70,12 +70,36 @@
content => template("${module_name}/${prospector_template}"),
notify => Service['filebeat'],
}
}
}

'FreeBSD' : {
if !$filebeat::disable_config_test {
file { "filebeat-${name}":
ensure => $ensure,
path => "${filebeat::config_dir}/${name}.yml",
owner => 'root',
group => 'wheel',
mode => $::filebeat::config_file_mode,
content => template("${module_name}/${prospector_template}"),
validate_cmd => '/usr/local/sbin/filebeat -N -configtest -c %',
notify => Service['filebeat'],
}
} else {
file { "filebeat-${name}":
ensure => $ensure,
path => "${filebeat::config_dir}/${name}.yml",
owner => 'root',
group => 'wheel',
mode => $::filebeat::config_file_mode,
content => template("${module_name}/${prospector_template}"),
notify => Service['filebeat'],
}
}
}

'Windows' : {
$filebeat_path = 'c:\Program Files\Filebeat\filebeat.exe'

if !$filebeat::disable_config_test {
file { "filebeat-${name}":
ensure => $ensure,
Expand All @@ -93,8 +117,10 @@
}
}
}

default : {
fail($filebeat::kernel_fail_message)
}

}
}
5 changes: 4 additions & 1 deletion metadata.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "pcfens-filebeat",
"version": "2.3.0",
"version": "2.4.0",
"author": "pcfens",
"summary": "A module to install and manage the filebeat log shipper",
"license": "Apache-2.0",
Expand Down Expand Up @@ -78,6 +78,9 @@
"2012",
"2012 R2"
]
},
{
"operatingsystem": "Archlinux"
}
],
"requirements": [
Expand Down
4 changes: 2 additions & 2 deletions spec/acceptance/001_basic_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

describe 'filebeat class' do
let(:pp) do
<<-EOS
<<-HEREDOC
if $::osfamily == 'Debian' {
include ::apt
Expand Down Expand Up @@ -73,7 +73,7 @@ class { 'filebeat':
}
}
}
EOS
HEREDOC
end

context 'with $major_version = 5' do
Expand Down
Loading