Showing with 171 additions and 42 deletions.
  1. +7 −5 .fixtures.yml
  2. +10 −0 CHANGELOG.md
  3. +1 −0 README.md
  4. +2 −1 manifests/config.pp
  5. +13 −4 manifests/init.pp
  6. +59 −23 manifests/install/windows.pp
  7. +4 −4 manifests/params.pp
  8. +2 −0 manifests/repo.pp
  9. +4 −4 metadata.json
  10. +1 −1 spec/acceptance/nodesets/ubuntu-16.04.yml
  11. +68 −0 spec/classes/filebeat_spec.rb
12 changes: 7 additions & 5 deletions .fixtures.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
fixtures:
repositories:
"stdlib": "https://github.com/puppetlabs/puppetlabs-stdlib.git"
"apt": "https://github.com/puppetlabs/puppetlabs-apt.git"
"powershell": "https://github.com/puppetlabs/puppetlabs-powershell.git"
"remotefile": "https://github.com/lwf/puppet-remote_file.git"
stdlib: "https://github.com/puppetlabs/puppetlabs-stdlib.git"
apt:
repo: "https://github.com/puppetlabs/puppetlabs-apt.git"
ref: '2.4.0'
powershell: "https://github.com/puppetlabs/puppetlabs-powershell.git"
archive: "https://github.com/voxpupuli/puppet-archive.git"
symlinks:
"filebeat": "#{source_dir}"
filebeat: "#{source_dir}"
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@ Changelog
## Unreleased
[Full Changelog](https://github.com/pcfens/puppet-filebeat/compare/v0.11.2...HEAD)

## [v0.12.0](https://github.com/pcfens/puppet-filebeat/tree/v0.12.0)
[Full Changelog](https://github.com/pcfens/puppet-filebeat/compare/v0.11.2...v0.12.0)

Windows users: you may see a restart and replacement of your existing filebeat directory.
There's a very brief discussion of the change in the [pull request](https://github.com/pcfens/puppet-filebeat/pull/113#issuecomment-307628477)

- Support upgrades in Windows [\113](https://github.com/pcfens/puppet-filebeat/pull/113)
- Add optional repo_priority parameter [\#110](https://github.com/pcfens/puppet-filebeat/pull/110)
- Update external dependencies, including pinning apt version

## [v0.11.2](https://github.com/pcfens/puppet-filebeat/tree/v0.11.2)
[Full Changelog](https://github.com/pcfens/puppet-filebeat/compare/v0.11.1...v0.11.2)

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ Installs and configures filebeat.
- `manage_repo`: [Boolean] Whether or not the upstream (elastic) repo should be configured or not (default: true)
- `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)
- `service_provider`: [String] The provider parameter on the filebeat service (default: on RedHat based systems use redhat, otherwise undefined)
- `spool_size`: [Integer] How large the spool should grow before being flushed to the network (default: 2048)
- `idle_timeout`: [String] How often the spooler should be flushed even if spool size isn't reached (default: 5s)
Expand Down
3 changes: 2 additions & 1 deletion manifests/config.pp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@
} # end Linux

'Windows' : {
$filebeat_path = 'c:\Program Files\Filebeat\filebeat.exe'
$cmd_install_dir = regsubst($filebeat::install_dir, '/', '\\', 'G')
$filebeat_path = join([$cmd_install_dir, 'Filebeat', 'filebeat.exe'], '\\')

file {'filebeat.yml':
ensure => $filebeat::file_ensure,
Expand Down
17 changes: 13 additions & 4 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
# @param manage_repo [Boolean] Whether or not the upstream (elastic) repo should be configured or not (default: true)
# @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)
# @param spool_size [Integer] How large the spool should grow before being flushed to the network (default: 2048)
# @param idle_timeout [String] How often the spooler should be flushed even if spool size isn't reached (default: 5s)
# @param publish_async [Boolean] If set to true filebeat will publish while preparing the next batch of lines to send (defualt: false)
Expand Down Expand Up @@ -53,6 +54,7 @@
$service_ensure = $filebeat::params::service_ensure,
$service_enable = $filebeat::params::service_enable,
$service_provider = $filebeat::params::service_provider,
$repo_priority = undef,
$spool_size = $filebeat::params::spool_size,
$idle_timeout = $filebeat::params::idle_timeout,
$publish_async = $filebeat::params::publish_async,
Expand All @@ -67,7 +69,7 @@
$logging = $filebeat::params::logging,
$run_options = $filebeat::params::run_options,
$conf_template = undef,
$download_url = $filebeat::params::download_url,
$download_url = undef,
$install_dir = $filebeat::params::install_dir,
$tmp_dir = $filebeat::params::tmp_dir,
#### v5 only ####
Expand All @@ -81,18 +83,20 @@
$fields_under_root = $filebeat::params::fields_under_root,
$processors = {},
$processors_merge = false,
#### End v5 onlly ####
#### End v5 only ####
$prospectors = {},
$prospectors_merge = false,
$proxy_address = undef
) inherits filebeat::params {

include ::stdlib

$kernel_fail_message = "${::kernel} is not supported by filebeat."

validate_bool($manage_repo, $processors_merge, $prospectors_merge)

if $repo_priority != undef {
validate_integer($repo_priority)
}

if $major_version == undef and getvar('::filebeat_version') == undef {
$real_version = '5'
} elsif $major_version == undef and versioncmp($::filebeat_version, '5.0.0') >= 0 {
Expand All @@ -119,6 +123,11 @@
}
}

$real_download_url = $download_url ? {
undef => "https://artifacts.elastic.co/downloads/beats/filebeat/filebeat-${package_ensure}-windows-x86_64.zip",
default => $download_url,
}

if $prospectors_merge {
$prospectors_final = hiera_hash('filebeat::prospectors', $prospectors)
} else {
Expand Down
82 changes: 59 additions & 23 deletions manifests/install/windows.pp
Original file line number Diff line number Diff line change
@@ -1,40 +1,76 @@
class filebeat::install::windows {
$filename = regsubst($filebeat::download_url, '^https?.*\/([^\/]+)\.[^.].*', '\1')
# I'd like to use chocolatey to do this install, but the package for chocolatey is
# failing for updates and seems rather unpredictable at the moment. We may revisit
# that in the future as it would greatly simplify this code and basically reduce it to
# one package resource with type => chocolatey....

$filename = regsubst($filebeat::real_download_url, '^https?.*\/([^\/]+)\.[^.].*', '\1')
$foldername = 'Filebeat'
$zip_file = join([$filebeat::tmp_dir, "${filename}.zip"], '/')
$install_folder = join([$filebeat::install_dir, $foldername], '/')
$version_file = join([$install_folder, $filename], '/')

Exec {
provider => powershell,
}

file { $filebeat::install_dir:
ensure => directory,
if ! defined(File[$filebeat::install_dir]) {
file { $filebeat::install_dir:
ensure => directory,
}
}

remote_file {"${filebeat::tmp_dir}/${filename}.zip":
ensure => present,
source => $filebeat::download_url,
verify_peer => false,
proxy => $filebeat::proxy_address,
# Note: We can use archive for unzip and cleanup, thus removing the following two resources.
# However, this requires 7zip, which archive can install via chocolatey:
# https://github.com/voxpupuli/puppet-archive/blob/master/manifests/init.pp#L31
# I'm not choosing to impose those dependencies on anyone at this time...
archive { $zip_file:
source => $filebeat::real_download_url,
cleanup => false,
creates => $version_file,
proxy_server => $filebeat::proxy_address,
}

exec { "unzip ${filename}":
command => "\$sh=New-Object -COM Shell.Application;\$sh.namespace((Convert-Path '${filebeat::install_dir}')).Copyhere(\$sh.namespace((Convert-Path '${filebeat::tmp_dir}/${filename}.zip')).items(), 16)",
creates => "${filebeat::install_dir}/Filebeat",
provider => powershell,
require => [
command => "\$sh=New-Object -COM Shell.Application;\$sh.namespace((Convert-Path '${filebeat::install_dir}')).Copyhere(\$sh.namespace((Convert-Path '${zip_file}')).items(), 16)",
creates => $version_file,
require => [
File[$filebeat::install_dir],
Remote_file["${filebeat::tmp_dir}/${filename}.zip"],
Archive[$zip_file],
],
}

exec { 'rename folder':
command => "Rename-Item '${filebeat::install_dir}/${filename}' Filebeat",
creates => "${filebeat::install_dir}/Filebeat",
provider => powershell,
require => Exec["unzip ${filename}"],
# Clean up after ourselves
file { $zip_file:
ensure => absent,
backup => false,
require => Exec["unzip ${filename}"],
}

# You can't remove the old dir while the service has files locked...
exec { "stop service ${filename}":
command => 'Set-Service -Name filebeat -Status Stopped',
creates => $version_file,
onlyif => 'if(Get-WmiObject -Class Win32_Service -Filter "Name=\'filebeat\'") {exit 0} else {exit 1}',
require => Exec["unzip ${filename}"],
}

exec { "rename ${filename}":
command => "Remove-Item '${install_folder}' -Recurse -Force -ErrorAction SilentlyContinue; Rename-Item '${filebeat::install_dir}/${filename}' '${install_folder}'",
creates => $version_file,
require => Exec["stop service ${filename}"],
}

exec { "mark ${filename}":
command => "New-Item '${version_file}' -ItemType file",
creates => $version_file,
require => Exec["rename ${filename}"],
}

exec { "install ${filename}":
cwd => "${filebeat::install_dir}/Filebeat",
command => './install-service-filebeat.ps1',
onlyif => 'if(Get-WmiObject -Class Win32_Service -Filter "Name=\'filebeat\'") { exit 1 } else {exit 0 }',
provider => powershell,
require => Exec['rename folder'],
cwd => $install_folder,
command => './install-service-filebeat.ps1',
refreshonly => true,
subscribe => Exec["mark ${filename}"],
}
}
8 changes: 4 additions & 4 deletions manifests/params.pp
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
class filebeat::params {
$package_ensure = present
$manage_repo = true
$service_ensure = running
$service_enable = true
Expand All @@ -21,6 +20,7 @@
$logging = {}
$run_options = {}
$use_generic_template = false
$kernel_fail_message = "${::kernel} is not supported by filebeat."

# 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 @@ -31,14 +31,14 @@
#
case $::kernel {
'Linux' : {
$package_ensure = present
$config_file = '/etc/filebeat/filebeat.yml'
$config_dir = '/etc/filebeat/conf.d'
$registry_file = '/var/lib/filebeat/registry'

# These parameters are ignored if/until tarball installs are supported in Linux
$tmp_dir = '/tmp'
$install_dir = undef
$download_url = undef
case $::osfamily {
'RedHat': {
$service_provider = 'redhat'
Expand All @@ -50,17 +50,17 @@
}

'Windows' : {
$package_ensure = '5.1.1'
$config_file = 'C:/Program Files/Filebeat/filebeat.yml'
$config_dir = 'C:/Program Files/Filebeat/conf.d'
$registry_file = 'C:/ProgramData/filebeat/registry'
$download_url = 'https://artifacts.elastic.co/downloads/beats/filebeat/filebeat-5.1.1-windows-x86_64.zip'
$install_dir = 'C:/Program Files'
$tmp_dir = 'C:/Windows/Temp'
$service_provider = undef
}

default : {
fail("${::kernel} is not supported by filebeat.")
fail($kernel_fail_message)
}
}
}
2 changes: 2 additions & 0 deletions manifests/repo.pp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
location => $debian_repo_url,
release => 'stable',
repos => 'main',
pin => $::filebeat::repo_priority,
key => {
id => '46095ACC8548582C1A2699A9D27D666CD88E42B4',
source => 'https://artifacts.elastic.co/GPG-KEY-elasticsearch',
Expand All @@ -36,6 +37,7 @@
baseurl => $yum_repo_url,
gpgcheck => 1,
gpgkey => 'https://artifacts.elastic.co/GPG-KEY-elasticsearch',
priority => $::filebeat::repo_priority,
enabled => 1,
}
}
Expand Down
8 changes: 4 additions & 4 deletions metadata.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "pcfens-filebeat",
"version": "0.11.2",
"version": "0.12.0",
"author": "pcfens",
"license": "Apache-2.0",
"summary": "A module to install and manage the filebeat log shipper",
Expand Down Expand Up @@ -77,14 +77,14 @@
"version_requirement": ">= 1.0.1 < 3.0.0"
},
{
"name": "lwf/remote_file",
"version_requirement": ">= 0.2.0 < 2.0.0"
"name": "puppet/archive",
"version_requirement": ">= 0.5.0 < 2.0.0"
}
],
"requirements": [
{
"name": "puppet",
"version_requirement": ">= 3.0.0 < 5.0.0"
"version_requirement": ">= 3.5.0 < 5.0.0"
}
]
}
2 changes: 1 addition & 1 deletion spec/acceptance/nodesets/ubuntu-16.04.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ HOSTS:
docker_cmd: '["/sbin/init"]'
docker_image_commands:
# ensure that upstart is booting correctly in the container
- 'rm /usr/sbin/policy-rc.d && rm /sbin/initctl && dpkg-divert --rename --remove /sbin/initctl && apt-get update && apt-get install -y net-tools wget && locale-gen en_US.UTF-8'
- 'rm /usr/sbin/policy-rc.d && rm /sbin/initctl && dpkg-divert --rename --remove /sbin/initctl && apt-get update && apt-get install -y net-tools wget locales && locale-gen en_US.UTF-8'
CONFIG:
trace_limit: 200
type: foss
68 changes: 68 additions & 0 deletions spec/classes/filebeat_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,74 @@
end
end

context 'when seting repository priority' do
let :facts do
{
kernel: 'Linux',
osfamily: 'Debian',
lsbdistid: 'Ubuntu',
lsbdistrelease: '16.04',
rubyversion: '1.9.3',
puppetversion: Puppet.version,
filebeat_version: '5.2.2'
}
end

let :params do
{
repo_priority: 10
}
end

context 'defaults' do
it { is_expected.to compile.with_all_deps }
it { is_expected.to contain_package('filebeat') }
it { is_expected.to contain_class('filebeat::params') }
it { is_expected.to contain_anchor('filebeat::begin') }
it { is_expected.to contain_anchor('filebeat::end') }
it { is_expected.to contain_class('filebeat::install') }
it { is_expected.to contain_class('filebeat::config') }
it { is_expected.to contain_anchor('filebeat::install::begin') }
it { is_expected.to contain_anchor('filebeat::install::end') }
it { is_expected.to contain_class('filebeat::install::linux') }
it { is_expected.to contain_class('filebeat::repo') }
it { is_expected.to contain_class('filebeat::service') }
it { is_expected.not_to contain_class('filebeat::install::windows') }
it do
is_expected.to contain_apt__source('beats').with(
pin: 10
)
end
end

describe 'on a RHEL system' do
let :facts do
{
kernel: 'Linux',
osfamily: 'RedHat',
rubyversion: '1.8.7',
puppetversion: Puppet.version,
filebeat_version: '5.2.2'
}
end

it { is_expected.to compile.with_all_deps }
it { is_expected.to contain_class('filebeat::params') }
it { is_expected.to contain_anchor('filebeat::begin') }
it { is_expected.to contain_anchor('filebeat::end') }
it { is_expected.to contain_class('filebeat::install') }
it { is_expected.to contain_class('filebeat::config') }
it { is_expected.to contain_anchor('filebeat::install::begin') }
it { is_expected.to contain_anchor('filebeat::install::end') }

it do
is_expected.to contain_yumrepo('beats').with(
priority: 10
)
end
end
end

context 'when uninstalling filebeat' do
let :facts do
{
Expand Down