diff --git a/manifests/config.pp b/manifests/config.pp index 986a0eb..fbb2b0c 100644 --- a/manifests/config.pp +++ b/manifests/config.pp @@ -5,13 +5,12 @@ # # @summary Manages Metricbeat's configuration file class metricbeat::config inherits metricbeat { - # Use lookup to merge metricbeat::modules config from different levels of hiera $modules_lookup = lookup('metricbeat::modules', undef, 'unique', undef) # Check to see if anything has been confiugred in hiera if $modules_lookup { $modules_arr = $modules_lookup - # check if array is empty, no need to create a config entry then + # check if array is empty, no need to create a config entry then } elsif $metricbeat::modules[0].length() > 0 { $modules_arr = $metricbeat::modules } else { @@ -20,44 +19,44 @@ # if fields are "under root", then remove prefix if $metricbeat::fields_under_root == true { - $fields_tmp = $metricbeat::fields.each | $key, $value | { {$key => $value} } + $fields_tmp = $metricbeat::fields.each | $key, $value | {{ $key => $value } } } else { - $fields_tmp = $metricbeat::fields + $fields_tmp = $metricbeat::fields } if $metricbeat::major_version == '5' { $metricbeat_config_base = delete_undef_values({ - 'cloud.id' => $metricbeat::cloud_id, - 'cloud.auth' => $metricbeat::cloud_auth, - 'name' => $metricbeat::beat_name, - 'tags' => $metricbeat::tags, - 'logging' => $metricbeat::logging, - 'processors' => $metricbeat::processors, - 'queue_size' => $metricbeat::queue_size, - 'metricbeat' => { - 'modules' => $metricbeat::modules, - }, - 'output' => $metricbeat::outputs, - 'metricbeat.config.modules.path' => "${metricbeat::config_dir}/modules.d/*.yml", - 'setup' => $metricbeat::setup, + 'cloud.id' => $metricbeat::cloud_id, + 'cloud.auth' => $metricbeat::cloud_auth, + 'name' => $metricbeat::beat_name, + 'tags' => $metricbeat::tags, + 'logging' => $metricbeat::logging, + 'processors' => $metricbeat::processors, + 'queue_size' => $metricbeat::queue_size, + 'metricbeat' => { + 'modules' => $metricbeat::modules, + }, + 'output' => $metricbeat::outputs, + 'metricbeat.config.modules.path' => "${metricbeat::config_dir}/modules.d/*.yml", + 'setup' => $metricbeat::setup, }) $metricbeat_config = deep_merge($metricbeat_config_base, $fields_tmp) } else { $metricbeat_config_base = delete_undef_values({ - 'cloud.id' => $metricbeat::cloud_id, - 'cloud.auth' => $metricbeat::cloud_auth, - 'name' => $metricbeat::beat_name, - 'tags' => $metricbeat::tags, - 'logging' => $metricbeat::logging, - 'processors' => $metricbeat::processors, - 'queue' => $metricbeat::queue, - 'fields_under_root' => $metricbeat::fields_under_root, - 'metricbeat.modules' => $modules_arr, - 'output' => $metricbeat::outputs, - 'metricbeat.config.modules.path' => "${metricbeat::config_dir}/modules.d/*.yml", - 'setup' => $metricbeat::setup, + 'cloud.id' => $metricbeat::cloud_id, + 'cloud.auth' => $metricbeat::cloud_auth, + 'name' => $metricbeat::beat_name, + 'tags' => $metricbeat::tags, + 'logging' => $metricbeat::logging, + 'processors' => $metricbeat::processors, + 'queue' => $metricbeat::queue, + 'fields_under_root' => $metricbeat::fields_under_root, + 'metricbeat.modules' => $modules_arr, + 'output' => $metricbeat::outputs, + 'metricbeat.config.modules.path' => "${metricbeat::config_dir}/modules.d/*.yml", + 'setup' => $metricbeat::setup, }) if $fields_tmp { @@ -69,12 +68,11 @@ # Add the 'xpack' section if supported (version >= 6.2.0) if versioncmp($metricbeat::package_ensure, '6.2.0') >= 0 { - $metricbeat_config = deep_merge($metricbeat_config_temp, {'xpack' => $metricbeat::xpack}) + $metricbeat_config = deep_merge($metricbeat_config_temp, { 'xpack' => $metricbeat::xpack }) } else { $metricbeat_config = $metricbeat_config_temp } - } # Create modules.d files that exist in hiera then collect any created via exported resources @@ -84,7 +82,7 @@ } Metricbeat::Modulesd <<||>> - case $::kernel { + case $facts['kernel'] { 'Linux': { $validate_cmd = $metricbeat::disable_configtest ? { true => undef, @@ -94,7 +92,7 @@ } } - file{'metricbeat.yml': + file { 'metricbeat.yml': ensure => $metricbeat::ensure, path => "${metricbeat::config_dir}/metricbeat.yml", owner => 'root', @@ -115,7 +113,7 @@ } } - file{'metricbeat.yml': + file { 'metricbeat.yml': ensure => $metricbeat::ensure, path => "${metricbeat::config_dir}/metricbeat.yml", content => inline_template('<%= @metricbeat_config.to_yaml() %>'), @@ -123,7 +121,7 @@ } } default: { - fail("${::kernel} is not supported by metricbeat.") + fail("${facts['kernel']} is not supported by metricbeat.") } } } diff --git a/manifests/init.pp b/manifests/init.pp index b27a8ec..5809562 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -165,7 +165,7 @@ # * `setup` # [Hash] Setup that will be created. Commonly used to create setup using hiera # -class metricbeat( +class metricbeat ( Optional[Variant[Stdlib::HTTPUrl, Stdlib::HTTPSUrl]] $apt_repo_url = $metricbeat::params::apt_repo_url, Optional[String] $cloud_id = $metricbeat::params::cloud_id, Optional[String] $cloud_auth = $metricbeat::params::cloud_auth, @@ -200,14 +200,13 @@ Optional[Variant[Stdlib::HTTPUrl, Stdlib::HTTPSUrl]] $yum_repo_url = $metricbeat::params::yum_repo_url, Hash $setup = {}, ) inherits metricbeat::params { - $real_download_url = $download_url ? { undef => "https://artifacts.elastic.co/downloads/beats/metricbeat/metricbeat-${package_ensure}-windows-${metricbeat::params::url_arch}.zip", default => $download_url, } if $manage_repo { - class{'metricbeat::repo':} + class { 'metricbeat::repo': } Class['metricbeat::repo'] -> Class['metricbeat::install'] @@ -228,8 +227,8 @@ -> Class['metricbeat::install'] } - anchor{'metricbeat::begin':} - class{'metricbeat::config':} - class{'metricbeat::install':} - class{'metricbeat::service':} + anchor { 'metricbeat::begin': } + class { 'metricbeat::config': } + class { 'metricbeat::install': } + class { 'metricbeat::service': } } diff --git a/manifests/install.pp b/manifests/install.pp index b702224..fd6ae45 100644 --- a/manifests/install.pp +++ b/manifests/install.pp @@ -5,7 +5,7 @@ # # @summary Manages the state of Package['metricbeat'] class metricbeat::install inherits metricbeat { - if $::kernel == 'Windows' { + if $facts['kernel'] == 'Windows' { $filename = regsubst($metricbeat::real_download_url, '^https?.*\/([^\/]+)\.[^.].*', '\1') $foldername = 'Metricbeat' $zip_file = join([$metricbeat::tmp_dir, "${filename}.zip"], '/') @@ -17,7 +17,7 @@ } if !defined(File[$metricbeat::install_dir]) { - file{$metricbeat::install_dir: + file { $metricbeat::install_dir: ensure => directory, } } @@ -30,7 +30,7 @@ proxy_server => $metricbeat::proxy_address, } - exec{"unzip ${filename}": + exec { "unzip ${filename}": command => "\$sh=New-Object -COM Shell.Application;\$sh.namespace((Convert-Path '${metricbeat::install_dir}')).Copyhere(\$sh.namespace((Convert-Path '${zip_file}')).items(), 16)", # lint:ignore:140chars creates => $version_file, require => [ @@ -39,13 +39,12 @@ ], } # Clean up after ourselves - file{$zip_file: + file { $zip_file: ensure => absent, backup => false, require => Exec["unzip ${filename}"], before => Exec["stop service ${filename}"], } - } else { archive { $zip_file: source => $metricbeat::real_download_url, @@ -58,24 +57,23 @@ } } - # You can't remove the old dir while the service has files locked... - exec{"stop service ${filename}": + exec { "stop service ${filename}": command => 'Set-Service -Name metricbeat -Status Stopped', creates => $version_file, onlyif => 'if(Get-WmiObject -Class Win32_Service -Filter "Name=\'metricbeat\'") {exit 0} else {exit 1}', } - exec{"rename ${filename}": + exec { "rename ${filename}": command => "Remove-Item '${install_folder}' -Recurse -Force -ErrorAction SilentlyContinue;Rename-Item '${metricbeat::install_dir}/${filename}' '${install_folder}'", # lint:ignore:140chars creates => $version_file, require => Exec["stop service ${filename}"], } - exec{"mark ${filename}": + exec { "mark ${filename}": command => "New-Item '${version_file}' -ItemType file", creates => $version_file, require => Exec["rename ${filename}"], } - exec{"install ${filename}": + exec { "install ${filename}": cwd => $install_folder, command => './install-service-metricbeat.ps1', refreshonly => true, @@ -90,7 +88,7 @@ $package_ensure = $metricbeat::ensure } - package{'metricbeat': + package { 'metricbeat': ensure => $package_ensure, } } diff --git a/manifests/modulesd.pp b/manifests/modulesd.pp index ef92598..705fdc0 100644 --- a/manifests/modulesd.pp +++ b/manifests/modulesd.pp @@ -1,11 +1,11 @@ # Enable a modules.d file either via a custom source, custom template or default module template # $config can be used to pass down parameters into an .erb template -define metricbeat::modulesd( +define metricbeat::modulesd ( String $template_name = $name, Hash $config = {}, Optional[String] $source = undef, Optional[String] $content = undef, -){ +) { # Use the default template as the source if non specified if ! $source and ! $content { $default_source = "puppet:///modules/metricbeat/${template_name}.yml" @@ -13,13 +13,13 @@ $default_source = $source } file { "${metricbeat::config_dir}/modules.d/${template_name}.yml": - ensure => present, + ensure => file, source => $default_source, content => $content, owner => 'root', group => 'root', mode => '0644', - require => Class['::metricbeat'], - notify => Class['::metricbeat::service'], + require => Class['metricbeat'], + notify => Class['metricbeat::service'], } } diff --git a/manifests/params.pp b/manifests/params.pp index 6f5341b..28d76fc 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -39,7 +39,7 @@ $apt_repo_url = undef $yum_repo_url = undef - case $::kernel { + case $facts['kernel'] { 'Linux': { $config_dir = '/etc/metricbeat' $install_dir = undef @@ -96,7 +96,7 @@ } } default: { - fail("${::kernel} is not supported by metricbeat.") + fail("${facts['kernel']} is not supported by metricbeat.") } } } diff --git a/manifests/repo.pp b/manifests/repo.pp index 9fc674b..20de78e 100644 --- a/manifests/repo.pp +++ b/manifests/repo.pp @@ -16,10 +16,10 @@ case $facts['os']['family'] { 'Debian': { - include ::apt + include apt if !defined(Apt::Source['beats']) { - apt::source{'beats': + apt::source { 'beats': location => $apt_repo_url, release => 'stable', repos => 'main', @@ -33,7 +33,7 @@ } 'RedHat': { if !defined(Yumrepo['beats']) { - yumrepo{'beats': + yumrepo { 'beats': descr => "Elastic repository for ${metricbeat::major_version}.x packages", baseurl => $yum_repo_url, gpgcheck => 1, @@ -46,10 +46,10 @@ exec { 'topbeat_suse_import_gpg': command => '/usr/bin/rpmkeys --import https://artifacts.elastic.co/GPG-KEY-elasticsearch', unless => '/usr/bin/test $(rpm -qa gpg-pubkey | grep -i "D88E42B4" | wc -l) -eq 1 ', - notify => [ Zypprepo['beats'] ], + notify => [Zypprepo['beats']], } if !defined (Zypprepo['beats']) { - zypprepo{'beats': + zypprepo { 'beats': baseurl => $yum_repo_url, enabled => 1, autorefresh => 1, diff --git a/manifests/service.pp b/manifests/service.pp index 3a5de11..96ba506 100644 --- a/manifests/service.pp +++ b/manifests/service.pp @@ -32,7 +32,7 @@ $service_enable = false } - service{'metricbeat': + service { 'metricbeat': ensure => $service_ensure, enable => $service_enable, hasrestart => $metricbeat::service_has_restart,