Skip to content

Commit

Permalink
overide default logging with filebeat version 7 (#223)
Browse files Browse the repository at this point in the history
  • Loading branch information
freibuis authored and pcfens committed Aug 21, 2019
1 parent 96a95cc commit e1e3eb2
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 26 deletions.
40 changes: 40 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
54 changes: 28 additions & 26 deletions manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
37 changes: 37 additions & 0 deletions manifests/service.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}

}
2 changes: 2 additions & 0 deletions templates/systemd/logging.conf.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[Service]
Environment="BEAT_LOG_OPTS=<%= @systemd_beat_log_opts_override %>"

0 comments on commit e1e3eb2

Please sign in to comment.