diff --git a/README.md b/README.md index 1f00ebf..56728e1 100644 --- a/README.md +++ b/README.md @@ -252,6 +252,7 @@ Installs and configures filebeat. - `outputs`: [Hash] Will be converted to YAML for the required outputs section of the configuration (see documentation, and above) - `shipper`: [Hash] Will be converted to YAML to create the optional shipper section of the filebeat config (see documentation) - `logging`: [Hash] Will be converted to YAML to create the optional logging section of the filebeat config (see documentation) +- `systemd_beat_log_opts_override`: [String] Will overide the default `BEAT_LOG_OPTS=-e`. Required if using `logging` hash on systems running with systemd. required: Puppet 6.1+, Filebeat 7+, - `modules`: [Array] Will be converted to YAML to create the optional modules section of the filebeat config (see documentation) - `conf_template`: [String] The configuration template to use to generate the main filebeat.yml config file. - `download_url`: [String] The URL of the zip file that should be downloaded to install filebeat (windows only) @@ -383,6 +384,45 @@ file { '/etc/filebeat/filebeat.yml': ``` to ensure that services are managed like you might expect. +### Logging on systems with Systemd and with version filebeat 7.0+ installed +With filebeat version 7+ running on systems with systemd, the filebeat systemd service file contains a default that will ignore the logging hash parameter + +``` +Environment="BEAT_LOG_OPTS=-e` +``` +to overide this default, you will need to set the systemd_beat_log_opts_override parameter to empty string + +example: +```puppet +class {'filebeat': + logging => { + 'level' => 'debug', + 'to_syslog' => false, + 'to_files' => true, + 'files' => { + 'path' => '/var/log/filebeat', + 'name' => 'filebeat', + 'keepfiles' => '7', + 'permissions' => '0644' + }, + systemd_beat_log_opts_override => "", +} +``` + +this will only work on systems with puppet version 6.1+. On systems with puppet version < 6.1 you will need to `systemctl daemon-reload`. This can be achived by using the [camptocamp-systemd](https://forge.puppet.com/camptocamp/systemd) + +```puppet +include systemd::systemctl::daemon_reload + +class {'filebeat': + logging => { +... + }, + systemd_beat_log_opts_override => "", + notify => Class['systemd::systemctl::daemon_reload'], +} +``` + ## Development Pull requests and bug reports are welcome. If you're sending a pull request, please consider diff --git a/manifests/init.pp b/manifests/init.pp index 7951147..2c00a6b 100755 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -97,6 +97,10 @@ Integer $queue_size = 4096, String $registry_file = 'filebeat.yml', + Optional[String] $systemd_beat_log_opts_override = undef, + String $systemd_beat_log_opts_template = $filebeat::params::systemd_beat_log_opts_template, + String $systemd_override_dir = $filebeat::params::systemd_override_dir, + ) inherits filebeat::params { include ::stdlib diff --git a/manifests/params.pp b/manifests/params.pp index a97b5d0..66db94e 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -4,32 +4,34 @@ # # @summary Set a bunch of default parameters class filebeat::params { - $service_ensure = running - $service_enable = true - $spool_size = 2048 - $idle_timeout = '5s' - $publish_async = false - $shutdown_timeout = '0' - $beat_name = $::fqdn - $tags = [] - $max_procs = undef - $config_file_mode = '0644' - $config_dir_mode = '0755' - $purge_conf_dir = true - $enable_conf_modules = false - $fields = {} - $fields_under_root = false - $http = {} - $outputs = {} - $shipper = {} - $logging = {} - $run_options = {} - $modules = [] - $kernel_fail_message = "${::kernel} is not supported by filebeat." - $osfamily_fail_message = "${::osfamily} is not supported by filebeat." - $conf_template = "${module_name}/pure_hash.yml.erb" - $disable_config_test = false - $xpack = undef + $service_ensure = running + $service_enable = true + $spool_size = 2048 + $idle_timeout = '5s' + $publish_async = false + $shutdown_timeout = '0' + $beat_name = $::fqdn + $tags = [] + $max_procs = undef + $config_file_mode = '0644' + $config_dir_mode = '0755' + $purge_conf_dir = true + $enable_conf_modules = false + $fields = {} + $fields_under_root = false + $http = {} + $outputs = {} + $shipper = {} + $logging = {} + $run_options = {} + $modules = [] + $kernel_fail_message = "${::kernel} is not supported by filebeat." + $osfamily_fail_message = "${::osfamily} is not supported by filebeat." + $conf_template = "${module_name}/pure_hash.yml.erb" + $disable_config_test = false + $xpack = undef + $systemd_override_dir = '/etc/systemd/system/filebeat.service.d' + $systemd_beat_log_opts_template = "${module_name}/systemd/logging.conf.erb" # These are irrelevant as long as the template is set based on the major_version parameter # if versioncmp('1.9.1', $::rubyversion) > 0 { diff --git a/manifests/service.pp b/manifests/service.pp index 80afd08..2536285 100644 --- a/manifests/service.pp +++ b/manifests/service.pp @@ -9,4 +9,41 @@ enable => $filebeat::service_enable, provider => $filebeat::service_provider, } + + $major_version = $filebeat::major_version + $systemd_beat_log_opts_override = $filebeat::systemd_beat_log_opts_override + + #make sure puppet client version 6.1+ with filebeat version 7+, running on systemd + if ( versioncmp( $major_version, '7' ) >= 0 and + $::service_provider == 'systemd' ) { + + if ( versioncmp( $::clientversion, '6.1' ) >= 0 ) { + + unless $systemd_beat_log_opts_override == undef { + $ensure_overide = 'present' + } else { + $ensure_overide = 'absent' + } + + ensure_resource('file', + $filebeat::systemd_override_dir, + { + ensure => 'directory', + } + ) + + file { "${filebeat::systemd_override_dir}/logging.conf": + ensure => $ensure_overide, + content => template($filebeat::systemd_beat_log_opts_template), + require => File[$filebeat::systemd_override_dir], + notify => Service['filebeat'], + } + + } else { + unless defined('systemd') { + warning('You\'ve specified an $systemd_beat_log_opts_override varible on a system running puppet version < 6.1 and not declared "systemd" resource See README.md for more information') # lint:ignore:140chars + } + } + } + } diff --git a/templates/systemd/logging.conf.erb b/templates/systemd/logging.conf.erb new file mode 100644 index 0000000..42762f9 --- /dev/null +++ b/templates/systemd/logging.conf.erb @@ -0,0 +1,2 @@ +[Service] +Environment="BEAT_LOG_OPTS=<%= @systemd_beat_log_opts_override %>" \ No newline at end of file