From f4261821a138a555162a983ff560910b44b321b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Romain=20Tarti=C3=A8re?= Date: Tue, 5 Sep 2023 11:49:23 -1000 Subject: [PATCH 1/9] Add support for FreeBSD --- manifests/init.pp | 1 + 1 file changed, 1 insertion(+) diff --git a/manifests/init.pp b/manifests/init.pp index 7848c90..59c409e 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -17,6 +17,7 @@ case $facts['os']['family'] { 'RedHat': { $real_package_name = 'syslog-ng' } 'Debian': { $real_package_name = 'syslog-ng-core' } + 'FreeBSD': { $real_package_name = 'syslog-ng' } default: { fail("unsupported osfamily: ${facts['os']['family']}") } } } From a65a89af787f18ef174e602445e51e503f8c01ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Romain=20Tarti=C3=A8re?= Date: Sun, 10 Sep 2023 14:37:36 -1000 Subject: [PATCH 2/9] Rely on Hiera to get the package name Using Hiera hierarchy, we can provide a default value that makes sense for the current operating system and still allow the user to provide their own custom package name if necessary. Makes the code simpler without changing the logic. --- data/default.yaml | 1 + data/osfamily/Debian.yaml | 2 ++ manifests/init.pp | 14 ++------------ spec/classes/patterndb_spec.rb | 7 ------- 4 files changed, 5 insertions(+), 19 deletions(-) create mode 100644 data/osfamily/Debian.yaml diff --git a/data/default.yaml b/data/default.yaml index 6515103..f87cece 100644 --- a/data/default.yaml +++ b/data/default.yaml @@ -3,6 +3,7 @@ patterndb::base_dir: / patterndb::temp_dir: /tmp/syslog-ng patterndb::package_name: false patterndb::manage_package: true +patterndb::package_name: syslog-ng patterndb::syslogng_modules: [] patterndb::use_hiera: false patterndb::_manage_top_dirs: true diff --git a/data/osfamily/Debian.yaml b/data/osfamily/Debian.yaml new file mode 100644 index 0000000..4191941 --- /dev/null +++ b/data/osfamily/Debian.yaml @@ -0,0 +1,2 @@ +--- +patterndb::package_name: syslog-ng-core diff --git a/manifests/init.pp b/manifests/init.pp index 59c409e..d55d222 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -1,8 +1,8 @@ # class patterndb ( + String[1] $package_name, String[1] $base_dir = '/', String[1] $temp_dir = "${base_dir}/tmp/syslog-ng", - Variant[String[1],Boolean] $package_name = false, Boolean $manage_package = true, Array[String[1]] $syslogng_modules = [], Boolean $use_hiera = false, @@ -11,17 +11,7 @@ ) { # package if $manage_package { - if $package_name =~ String { - $real_package_name = $package_name - } else { - case $facts['os']['family'] { - 'RedHat': { $real_package_name = 'syslog-ng' } - 'Debian': { $real_package_name = 'syslog-ng-core' } - 'FreeBSD': { $real_package_name = 'syslog-ng' } - default: { fail("unsupported osfamily: ${facts['os']['family']}") } - } - } - ensure_resource ( 'package', $real_package_name, { 'ensure' => 'installed' }) + ensure_resource ( 'package', $package_name, { 'ensure' => 'installed' }) } ensure_resource ( 'file', $temp_dir, { ensure => directory }) if $_manage_top_dirs { diff --git a/spec/classes/patterndb_spec.rb b/spec/classes/patterndb_spec.rb index 722d436..ff387a9 100644 --- a/spec/classes/patterndb_spec.rb +++ b/spec/classes/patterndb_spec.rb @@ -37,13 +37,6 @@ end end end - context 'Unsupported OS without package_name' do - let :facts do - { osfamily: 'UnsupportedOne' } - end - - it { is_expected.to raise_error(Puppet::Error) } - end context 'Any OS with a package name' do let :params do From cee5229f36c4bc0755fe97e95234ca1a694cf49d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Romain=20Tarti=C3=A8re?= Date: Sun, 10 Sep 2023 14:41:09 -1000 Subject: [PATCH 3/9] Rely on Hiera to get the config directory This directory is operating-system dependant. --- data/default.yaml | 2 +- data/osfamily/FreeBSD.yaml | 2 ++ manifests/init.pp | 4 ++-- manifests/parser.pp | 4 ++-- manifests/raw/ruleset.pp | 4 ++-- manifests/simple/ruleset.pp | 2 +- spec/defines/raw_ruleset_spec.rb | 20 ++++++++++++-------- spec/defines/simple_rule_spec.rb | 17 ++++++++++++++--- spec/defines/simple_ruleset_spec.rb | 29 +++++++++++++++++++++++++---- 9 files changed, 61 insertions(+), 23 deletions(-) create mode 100644 data/osfamily/FreeBSD.yaml diff --git a/data/default.yaml b/data/default.yaml index f87cece..605edb4 100644 --- a/data/default.yaml +++ b/data/default.yaml @@ -9,4 +9,4 @@ patterndb::use_hiera: false patterndb::_manage_top_dirs: true patterndb::test_before_deploy: &test_before_deploy true patterndb::parser::test_before_deploy: *test_before_deploy - +patterndb::config_dir: /etc/syslog-ng/patterndb.d diff --git a/data/osfamily/FreeBSD.yaml b/data/osfamily/FreeBSD.yaml new file mode 100644 index 0000000..b4b0ef7 --- /dev/null +++ b/data/osfamily/FreeBSD.yaml @@ -0,0 +1,2 @@ +--- +patterndb::config_dir: /usr/local/etc/patterndb.d diff --git a/manifests/init.pp b/manifests/init.pp index d55d222..4f9f1f1 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -1,6 +1,7 @@ # class patterndb ( String[1] $package_name, + Stdlib::Absolutepath $config_dir, String[1] $base_dir = '/', String[1] $temp_dir = "${base_dir}/tmp/syslog-ng", Boolean $manage_package = true, @@ -35,8 +36,7 @@ recurse => true } ) - $pdb_dir = "${base_dir}/etc/syslog-ng/patterndb.d" - file { $pdb_dir: + file { $config_dir: ensure => directory, purge => true, force => true, diff --git a/manifests/parser.pp b/manifests/parser.pp index 811ddf3..ed4954e 100644 --- a/manifests/parser.pp +++ b/manifests/parser.pp @@ -15,7 +15,7 @@ $tmp = join($_modules,' --module=') $modules = "--module=${tmp}" } - ensure_resource('file', "${patterndb::pdb_dir}/${name}", { + ensure_resource('file', "${patterndb::config_dir}/${name}", { 'ensure' => 'directory', 'purge' => true, 'force' => true, @@ -29,7 +29,7 @@ 'path' => "${patterndb::base_dir}/var/lib/syslog-ng/patterndb/${name}.xml" }) exec { "patterndb::merge::${name}": - command => "pdbtool merge -r --glob \\*.pdb -D ${patterndb::pdb_dir}/${name} -p ${patterndb::temp_dir}/patterndb/${name}.xml", + command => "pdbtool merge -r --glob \\*.pdb -D ${patterndb::config_dir}/${name} -p ${patterndb::temp_dir}/patterndb/${name}.xml", path => $facts['path'], logoutput => true, refreshonly => true, diff --git a/manifests/raw/ruleset.pp b/manifests/raw/ruleset.pp index 39e8e8b..498c4de 100644 --- a/manifests/raw/ruleset.pp +++ b/manifests/raw/ruleset.pp @@ -20,7 +20,7 @@ } if $ensure == 'directory' { - file { "${patterndb::pdb_dir}/${parser}/${name}": + file { "${patterndb::config_dir}/${parser}/${name}": ensure => $ensure, recurse => $recurse, mode => '0644', @@ -31,7 +31,7 @@ notify => Exec["patterndb::merge::${parser}"], } } else { - file { "${patterndb::pdb_dir}/${parser}/${name}.pdb": + file { "${patterndb::config_dir}/${parser}/${name}.pdb": ensure => $ensure, mode => '0644', source => $source, diff --git a/manifests/simple/ruleset.pp b/manifests/simple/ruleset.pp index 207f6a5..5db2fd5 100644 --- a/manifests/simple/ruleset.pp +++ b/manifests/simple/ruleset.pp @@ -25,7 +25,7 @@ } } - $pdb_file = "${patterndb::pdb_dir}/${parser}/${order}${name}.pdb" + $pdb_file = "${patterndb::config_dir}/${parser}/${order}${name}.pdb" concat { "patterndb_simple_ruleset-${title}": path => $pdb_file, diff --git a/spec/defines/raw_ruleset_spec.rb b/spec/defines/raw_ruleset_spec.rb index 542e21d..f2ea1cb 100644 --- a/spec/defines/raw_ruleset_spec.rb +++ b/spec/defines/raw_ruleset_spec.rb @@ -31,9 +31,12 @@ } end - it { - is_expected.to contain_file('BASEDIR/etc/syslog-ng/patterndb.d/default/myrawruleset.pdb') - } + case facts[:osfamily] + when 'FreeBSD' + it { is_expected.to contain_file('BASEDIR/usr/local/etc/patterndb.d/default/myrawruleset.pdb') } + else + it { is_expected.to contain_file('BASEDIR/etc/syslog-ng/patterndb.d/default/myrawruleset.pdb') } + end end context 'Raw rulesets with directory' do @@ -44,11 +47,12 @@ } end - it { - is_expected.to contain_file('BASEDIR/etc/syslog-ng/patterndb.d/default/myrawruleset').with( - ensure: 'directory' - ) - } + case facts[:osfamily] + when 'FreeBSD' + it { is_expected.to contain_file('BASEDIR/usr/local/etc/patterndb.d/default/myrawruleset').with(ensure: 'directory') } + else + it { is_expected.to contain_file('BASEDIR/etc/syslog-ng/patterndb.d/default/myrawruleset').with(ensure: 'directory') } + end end end end diff --git a/spec/defines/simple_rule_spec.rb b/spec/defines/simple_rule_spec.rb index 1f41e53..f65d0f2 100644 --- a/spec/defines/simple_rule_spec.rb +++ b/spec/defines/simple_rule_spec.rb @@ -74,10 +74,21 @@ ) } + case facts[:osfamily] + when 'FreeBSD' + it { + is_expected.to contain_concat('patterndb_simple_ruleset-myruleset').with( + path: '/BASEDIR/usr/local/etc/patterndb.d/default/myruleset.pdb' + ) + } + else + it { + is_expected.to contain_concat('patterndb_simple_ruleset-myruleset').with( + path: '/BASEDIR/etc/syslog-ng/patterndb.d/default/myruleset.pdb' + ) + } + end it { - is_expected.to contain_concat('patterndb_simple_ruleset-myruleset').with( - path: '/BASEDIR/etc/syslog-ng/patterndb.d/default/myruleset.pdb' - ) is_expected.to contain_concat__fragment('patterndb_simple_rule-myrule-header').with( target: 'patterndb_simple_ruleset-myruleset' ).with_content( diff --git a/spec/defines/simple_ruleset_spec.rb b/spec/defines/simple_ruleset_spec.rb index 0c72cdd..8be632a 100644 --- a/spec/defines/simple_ruleset_spec.rb +++ b/spec/defines/simple_ruleset_spec.rb @@ -59,8 +59,13 @@ it { is_expected.to contain_patterndb__parser('default') } + case facts[:osfamily] + when 'FreeBSD' + it { is_expected.to contain_concat('patterndb_simple_ruleset-myruleset').with('path' => '/BASEDIR/usr/local/etc/patterndb.d/default/myruleset.pdb') } + else + it { is_expected.to contain_concat('patterndb_simple_ruleset-myruleset').with('path' => '/BASEDIR/etc/syslog-ng/patterndb.d/default/myruleset.pdb') } + end it { - is_expected.to contain_concat('patterndb_simple_ruleset-myruleset').with('path' => '/BASEDIR/etc/syslog-ng/patterndb.d/default/myruleset.pdb') is_expected.to contain_concat__fragment('patterndb_simple_ruleset-myruleset-header').with_content( %r{.*P1.*}m ) @@ -79,8 +84,13 @@ it { is_expected.to contain_patterndb__parser('default') } + case facts[:osfamily] + when 'FreeBSD' + it { is_expected.to contain_concat('patterndb_simple_ruleset-myruleset').with('path' => '/BASEDIR/usr/local/etc/patterndb.d/default/myruleset.pdb') } + else + it { is_expected.to contain_concat('patterndb_simple_ruleset-myruleset').with('path' => '/BASEDIR/etc/syslog-ng/patterndb.d/default/myruleset.pdb') } + end it { - is_expected.to contain_concat('patterndb_simple_ruleset-myruleset').with('path' => '/BASEDIR/etc/syslog-ng/patterndb.d/default/myruleset.pdb') is_expected.to contain_concat('patterndb_simple_ruleset-myruleset').that_notifies( 'Exec[patterndb::merge::default]' ) @@ -135,7 +145,13 @@ it { is_expected.not_to contain_patterndb__parser('default') } it { is_expected.to contain_patterndb__parser('PARSER') } - it { is_expected.to contain_concat('patterndb_simple_ruleset-myruleset').with('path' => '/BASEDIR/etc/syslog-ng/patterndb.d/PARSER/myruleset.pdb') } + + case facts[:osfamily] + when 'FreeBSD' + it { is_expected.to contain_concat('patterndb_simple_ruleset-myruleset').with('path' => '/BASEDIR/usr/local/etc/patterndb.d/PARSER/myruleset.pdb') } + else + it { is_expected.to contain_concat('patterndb_simple_ruleset-myruleset').with('path' => '/BASEDIR/etc/syslog-ng/patterndb.d/PARSER/myruleset.pdb') } + end it { is_expected.to contain_concat__fragment('patterndb_simple_ruleset-myruleset-header').with( @@ -304,8 +320,13 @@ it { is_expected.to contain_patterndb__parser('default') } + case facts[:osfamily] + when 'FreeBSD' + it { is_expected.to contain_concat('patterndb_simple_ruleset-myruleset').with('path' => '/BASEDIR/usr/local/etc/patterndb.d/default/123myruleset.pdb') } + else + it { is_expected.to contain_concat('patterndb_simple_ruleset-myruleset').with('path' => '/BASEDIR/etc/syslog-ng/patterndb.d/default/123myruleset.pdb') } + end it { - is_expected.to contain_concat('patterndb_simple_ruleset-myruleset').with('path' => '/BASEDIR/etc/syslog-ng/patterndb.d/default/123myruleset.pdb') is_expected.to contain_concat__fragment('patterndb_simple_ruleset-myruleset-header').with_content( %r{.*P1.*}m ) From 960f7d315b280f1ab1b713247fcb12e61f9b4450 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Romain=20Tarti=C3=A8re?= Date: Sun, 10 Sep 2023 14:47:41 -1000 Subject: [PATCH 4/9] Strip resource that do not belong to the module These directory only make sense on some operating systems and should already be part of base system or the syslog-ng package. Do need to manage these in the patterndb module. --- manifests/init.pp | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/manifests/init.pp b/manifests/init.pp index 4f9f1f1..954990a 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -7,7 +7,6 @@ Boolean $manage_package = true, Array[String[1]] $syslogng_modules = [], Boolean $use_hiera = false, - Boolean $_manage_top_dirs = true, Boolean $test_before_deploy = true ) { # package @@ -15,15 +14,6 @@ ensure_resource ( 'package', $package_name, { 'ensure' => 'installed' }) } ensure_resource ( 'file', $temp_dir, { ensure => directory }) - if $_manage_top_dirs { - ensure_resource ( 'file', "${base_dir}/etc", { ensure => 'directory' }) - ensure_resource ( 'file', "${base_dir}/var", { ensure => 'directory' }) - ensure_resource ( 'file', "${base_dir}/var/lib", { ensure => 'directory' }) - } - ensure_resource ( - 'file', "${base_dir}/etc/syslog-ng", - { ensure => 'directory' } - ) ensure_resource ( 'file', "${base_dir}/var/lib/syslog-ng", { ensure => 'directory' } From c8e98b6fef7f06ddb55998ee3a24e2590f125e07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Romain=20Tarti=C3=A8re?= Date: Sun, 10 Sep 2023 15:09:12 -1000 Subject: [PATCH 5/9] Replate temp_dir with cache_dir According to hier(7), /var/cache/ is used to store miscellaneous cached files, precisely what merged patterns not yet installed are. --- README.md | 4 ++-- data/default.yaml | 1 - manifests/init.pp | 4 ++-- manifests/parser.pp | 10 +++++----- 4 files changed, 9 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index d2e861a..78c4644 100644 --- a/README.md +++ b/README.md @@ -28,12 +28,12 @@ This module will manage the pattern databases of *syslog-ng* by using existing f ### What patterndb affects -Depending on the top-level configuration variables `$base_dir` and `$temp_dir`, this module will manage and execute the following elements in order: +Depending on the top-level configuration variables `$base_dir` and `$cache_dir`, this module will manage and execute the following elements in order: 0. (OPTIONAL) Manage package `syslog-ng` 1. Manage `$base_dir/etc/syslog-ng/patterndb.d` recursively 2. Manage the contents of the above directory using [existing](#defined-type-patterndbrawruleset) or [generated](#defined-type-patterndbsimpleruleset) patterndb *ruleset* files -3. Merge the contents of the latter using `pdbtool` into a temporary file `${temp_dir}/syslog-ng/patterndb/${parser}.xml` where `$parser` is the name of the *patterndb* (you can have as many as you want, *e.g.* for *staged parsing*. +3. Merge the contents of the latter using `pdbtool` into a temporary file `${cache_dir}/syslog-ng/patterndb/${parser}.xml` where `$parser` is the name of the *patterndb* (you can have as many as you want, *e.g.* for *staged parsing*. 4. (OPTIONAL) Test the resulting patterndbs 5. Deploy the temporary files into `${base_dir}/var/lib/syslog-ng/patterndb/${parser}.xml` diff --git a/data/default.yaml b/data/default.yaml index 605edb4..91348fd 100644 --- a/data/default.yaml +++ b/data/default.yaml @@ -1,6 +1,5 @@ --- patterndb::base_dir: / -patterndb::temp_dir: /tmp/syslog-ng patterndb::package_name: false patterndb::manage_package: true patterndb::package_name: syslog-ng diff --git a/manifests/init.pp b/manifests/init.pp index 954990a..d439f86 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -2,8 +2,8 @@ class patterndb ( String[1] $package_name, Stdlib::Absolutepath $config_dir, + Stdlib::Absolutepath $cache_dir = '/var/cache/syslog-ng', String[1] $base_dir = '/', - String[1] $temp_dir = "${base_dir}/tmp/syslog-ng", Boolean $manage_package = true, Array[String[1]] $syslogng_modules = [], Boolean $use_hiera = false, @@ -13,7 +13,7 @@ if $manage_package { ensure_resource ( 'package', $package_name, { 'ensure' => 'installed' }) } - ensure_resource ( 'file', $temp_dir, { ensure => directory }) + ensure_resource ( 'file', $cache_dir, { ensure => directory }) ensure_resource ( 'file', "${base_dir}/var/lib/syslog-ng", { ensure => 'directory' } diff --git a/manifests/parser.pp b/manifests/parser.pp index ed4954e..af2261f 100644 --- a/manifests/parser.pp +++ b/manifests/parser.pp @@ -21,7 +21,7 @@ 'force' => true, 'recurse' => true, }) - ensure_resource ('file', "${patterndb::temp_dir}/patterndb", { + ensure_resource ('file', "${patterndb::cache_dir}/patterndb", { 'ensure' => 'directory', }) ensure_resource ('file', "patterndb::file::${name}", { @@ -29,22 +29,22 @@ 'path' => "${patterndb::base_dir}/var/lib/syslog-ng/patterndb/${name}.xml" }) exec { "patterndb::merge::${name}": - command => "pdbtool merge -r --glob \\*.pdb -D ${patterndb::config_dir}/${name} -p ${patterndb::temp_dir}/patterndb/${name}.xml", + command => "pdbtool merge -r --glob \\*.pdb -D ${patterndb::config_dir}/${name} -p ${patterndb::cache_dir}/patterndb/${name}.xml", path => $facts['path'], logoutput => true, refreshonly => true, } exec { "patterndb::test::${name}": - #command => "/usr/bin/pdbtool --validate test ${::patterndb::temp_dir}/patterndb/${name}.xml $modules", - command => "pdbtool test ${patterndb::temp_dir}/patterndb/${name}.xml ${modules}", + #command => "/usr/bin/pdbtool --validate test ${::patterndb::cache_dir}/patterndb/${name}.xml $modules", + command => "pdbtool test ${patterndb::cache_dir}/patterndb/${name}.xml ${modules}", path => $facts['path'], logoutput => true, refreshonly => true, } exec { "patterndb::deploy::${name}": - command => "cp ${patterndb::temp_dir}/patterndb/${name}.xml ${patterndb::base_dir}/var/lib/syslog-ng/patterndb/", + command => "cp ${patterndb::cache_dir}/patterndb/${name}.xml ${patterndb::base_dir}/var/lib/syslog-ng/patterndb/", logoutput => true, path => $facts['path'], refreshonly => true, From b320c7ae8cb1e9bdd8ff115b60f936d664dad2ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Romain=20Tarti=C3=A8re?= Date: Sun, 10 Sep 2023 15:15:34 -1000 Subject: [PATCH 6/9] Rely on Hiera to get var directory --- data/default.yaml | 1 + data/osfamily/FreeBSD.yaml | 1 + examples/NOK_mismatching_action.pp | 1 - examples/OK_getent.pp | 1 - examples/OK_hiera.pp | 1 - examples/OK_hiera_puppet5.pp | 1 - examples/OK_hybrid.pp | 1 - examples/OK_ltgt.pp | 1 - examples/OK_modules.pp | 1 - examples/OK_multiple_pdb.pp | 1 - examples/OK_notest.pp | 1 - examples/OK_raw.pp | 1 - examples/OK_s.pp | 1 - examples/OK_separate_action.pp | 1 - examples/OK_separate_rules.pp | 1 - examples/OK_separate_rules_and_actions.pp | 1 - examples/OK_simple.pp | 1 - examples/OK_simple_action.pp | 1 - examples/OK_simple_coerce.pp | 1 - examples/OK_simple_context.pp | 1 - examples/OK_simple_empty.pp | 1 - examples/OK_yum.pp | 1 - manifests/init.pp | 18 ++++++++---------- manifests/parser.pp | 4 ++-- spec/defines/raw_ruleset_spec.rb | 10 +++++----- spec/defines/simple_action_spec.rb | 2 +- spec/defines/simple_rule_spec.rb | 6 +++--- spec/defines/simple_ruleset_spec.rb | 18 +++++++++--------- 28 files changed, 30 insertions(+), 50 deletions(-) diff --git a/data/default.yaml b/data/default.yaml index 91348fd..a72a3e9 100644 --- a/data/default.yaml +++ b/data/default.yaml @@ -9,3 +9,4 @@ patterndb::_manage_top_dirs: true patterndb::test_before_deploy: &test_before_deploy true patterndb::parser::test_before_deploy: *test_before_deploy patterndb::config_dir: /etc/syslog-ng/patterndb.d +patterndb::var_dir: /var/lib/syslog-ng diff --git a/data/osfamily/FreeBSD.yaml b/data/osfamily/FreeBSD.yaml index b4b0ef7..ec4f07d 100644 --- a/data/osfamily/FreeBSD.yaml +++ b/data/osfamily/FreeBSD.yaml @@ -1,2 +1,3 @@ --- patterndb::config_dir: /usr/local/etc/patterndb.d +patterndb::var_dir: /var/syslog-ng diff --git a/examples/NOK_mismatching_action.pp b/examples/NOK_mismatching_action.pp index dcac8d7..4c5bef7 100644 --- a/examples/NOK_mismatching_action.pp +++ b/examples/NOK_mismatching_action.pp @@ -1,7 +1,6 @@ # class { 'patterndb': manage_package => false, - base_dir => '/tmp/', } Exec { diff --git a/examples/OK_getent.pp b/examples/OK_getent.pp index d4f0ebb..5269ba7 100644 --- a/examples/OK_getent.pp +++ b/examples/OK_getent.pp @@ -1,7 +1,6 @@ # class { 'patterndb': manage_package => false, - base_dir => '/tmp/', syslogng_modules => ['tfgetent'], } diff --git a/examples/OK_hiera.pp b/examples/OK_hiera.pp index 0b4fbcd..0b847d0 100644 --- a/examples/OK_hiera.pp +++ b/examples/OK_hiera.pp @@ -1,6 +1,5 @@ # class { 'patterndb': - base_dir => '/tmp/', manage_package => false, syslogng_modules => [], use_hiera => true, diff --git a/examples/OK_hiera_puppet5.pp b/examples/OK_hiera_puppet5.pp index 132679d..90368ee 100644 --- a/examples/OK_hiera_puppet5.pp +++ b/examples/OK_hiera_puppet5.pp @@ -1,6 +1,5 @@ # class { 'patterndb': - base_dir => '/tmp/', manage_package => false, syslogng_modules => [], use_hiera => true, diff --git a/examples/OK_hybrid.pp b/examples/OK_hybrid.pp index 8629feb..9705ae3 100644 --- a/examples/OK_hybrid.pp +++ b/examples/OK_hybrid.pp @@ -1,7 +1,6 @@ # class { 'patterndb': manage_package => false, - base_dir => '/tmp/', } patterndb::raw::ruleset { 'raw': diff --git a/examples/OK_ltgt.pp b/examples/OK_ltgt.pp index 5835b16..0603c34 100644 --- a/examples/OK_ltgt.pp +++ b/examples/OK_ltgt.pp @@ -1,6 +1,5 @@ # class { 'patterndb': - base_dir => '/tmp/', manage_package => false, syslogng_modules => [], } diff --git a/examples/OK_modules.pp b/examples/OK_modules.pp index c6dac52..c0cbe42 100644 --- a/examples/OK_modules.pp +++ b/examples/OK_modules.pp @@ -4,7 +4,6 @@ } class { 'patterndb': manage_package => false, - base_dir => '/tmp/', syslogng_modules => ['basicfuncs'], } diff --git a/examples/OK_multiple_pdb.pp b/examples/OK_multiple_pdb.pp index a0994de..91be537 100644 --- a/examples/OK_multiple_pdb.pp +++ b/examples/OK_multiple_pdb.pp @@ -1,7 +1,6 @@ # class { 'patterndb': manage_package => false, - base_dir => '/tmp/', } patterndb::simple::ruleset { 'dhclient': diff --git a/examples/OK_notest.pp b/examples/OK_notest.pp index a9d027a..c297cb5 100644 --- a/examples/OK_notest.pp +++ b/examples/OK_notest.pp @@ -1,7 +1,6 @@ # class { 'patterndb': manage_package => false, - base_dir => '/tmp/', syslogng_modules => ['pdbtool_test_would_fail_with_this_module'], test_before_deploy => false, } diff --git a/examples/OK_raw.pp b/examples/OK_raw.pp index 0177e28..98ac7ef 100644 --- a/examples/OK_raw.pp +++ b/examples/OK_raw.pp @@ -1,7 +1,6 @@ # class { 'patterndb': manage_package => false, - base_dir => '/tmp/', syslogng_modules => [], } diff --git a/examples/OK_s.pp b/examples/OK_s.pp index 37a2b42..4ec1012 100644 --- a/examples/OK_s.pp +++ b/examples/OK_s.pp @@ -1,7 +1,6 @@ # class { 'patterndb': manage_package => false, - base_dir => '/tmp/', } Patterndb::Simple::Rule { diff --git a/examples/OK_separate_action.pp b/examples/OK_separate_action.pp index b5ef392..c886875 100644 --- a/examples/OK_separate_action.pp +++ b/examples/OK_separate_action.pp @@ -1,7 +1,6 @@ # class { 'patterndb': manage_package => false, - base_dir => '/tmp/', } Exec { diff --git a/examples/OK_separate_rules.pp b/examples/OK_separate_rules.pp index 489ce27..2677fb8 100644 --- a/examples/OK_separate_rules.pp +++ b/examples/OK_separate_rules.pp @@ -1,7 +1,6 @@ # class { 'patterndb': manage_package => false, - base_dir => '/tmp/', } patterndb::simple::ruleset { 'empty_ruleset': diff --git a/examples/OK_separate_rules_and_actions.pp b/examples/OK_separate_rules_and_actions.pp index f8d396b..8f7f243 100644 --- a/examples/OK_separate_rules_and_actions.pp +++ b/examples/OK_separate_rules_and_actions.pp @@ -1,7 +1,6 @@ # class { 'patterndb': manage_package => false, - base_dir => '/tmp/', } Exec { diff --git a/examples/OK_simple.pp b/examples/OK_simple.pp index 5ee33d0..9df1a42 100644 --- a/examples/OK_simple.pp +++ b/examples/OK_simple.pp @@ -1,7 +1,6 @@ # class { 'patterndb': manage_package => false, - base_dir => '/tmp/', } patterndb::simple::ruleset { 'dhclient': diff --git a/examples/OK_simple_action.pp b/examples/OK_simple_action.pp index a429061..70f4c64 100644 --- a/examples/OK_simple_action.pp +++ b/examples/OK_simple_action.pp @@ -1,7 +1,6 @@ # class { 'patterndb': manage_package => false, - base_dir => '/tmp/', } patterndb::simple::ruleset { 'dhclient': diff --git a/examples/OK_simple_coerce.pp b/examples/OK_simple_coerce.pp index 806af69..1cd304e 100644 --- a/examples/OK_simple_coerce.pp +++ b/examples/OK_simple_coerce.pp @@ -1,7 +1,6 @@ # class { 'patterndb': manage_package => false, - base_dir => '/tmp/', } patterndb::simple::ruleset { 'plop': diff --git a/examples/OK_simple_context.pp b/examples/OK_simple_context.pp index 69bfc58..471b4ab 100644 --- a/examples/OK_simple_context.pp +++ b/examples/OK_simple_context.pp @@ -1,7 +1,6 @@ # class { 'patterndb': manage_package => false, - base_dir => '/tmp/', } patterndb::simple::ruleset { 'dhclient': diff --git a/examples/OK_simple_empty.pp b/examples/OK_simple_empty.pp index 0d9f939..9433d61 100644 --- a/examples/OK_simple_empty.pp +++ b/examples/OK_simple_empty.pp @@ -1,7 +1,6 @@ # class { 'patterndb': manage_package => false, - base_dir => '/tmp/', } patterndb::simple::ruleset { 'empty': diff --git a/examples/OK_yum.pp b/examples/OK_yum.pp index baf9495..b0b3a35 100644 --- a/examples/OK_yum.pp +++ b/examples/OK_yum.pp @@ -1,7 +1,6 @@ # class { 'patterndb': manage_package => false, - base_dir => '/tmp', syslogng_modules => [], test_before_deploy => true, } diff --git a/manifests/init.pp b/manifests/init.pp index d439f86..3d41364 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -2,8 +2,8 @@ class patterndb ( String[1] $package_name, Stdlib::Absolutepath $config_dir, + Stdlib::Absolutepath $var_dir, Stdlib::Absolutepath $cache_dir = '/var/cache/syslog-ng', - String[1] $base_dir = '/', Boolean $manage_package = true, Array[String[1]] $syslogng_modules = [], Boolean $use_hiera = false, @@ -15,17 +15,15 @@ } ensure_resource ( 'file', $cache_dir, { ensure => directory }) ensure_resource ( - 'file', "${base_dir}/var/lib/syslog-ng", + 'file', $var_dir, { ensure => 'directory' } ) - ensure_resource ( - 'file', "${base_dir}/var/lib/syslog-ng/patterndb", - { - ensure => 'directory', - purge => true, - recurse => true - } - ) + file { "${var_dir}/patterndb": + ensure => 'directory', + purge => true, + recurse => true, + } + file { $config_dir: ensure => directory, purge => true, diff --git a/manifests/parser.pp b/manifests/parser.pp index af2261f..dde73b9 100644 --- a/manifests/parser.pp +++ b/manifests/parser.pp @@ -26,7 +26,7 @@ }) ensure_resource ('file', "patterndb::file::${name}", { 'ensure' => 'present', - 'path' => "${patterndb::base_dir}/var/lib/syslog-ng/patterndb/${name}.xml" + 'path' => "${patterndb::var_dir}/patterndb/${name}.xml" }) exec { "patterndb::merge::${name}": command => "pdbtool merge -r --glob \\*.pdb -D ${patterndb::config_dir}/${name} -p ${patterndb::cache_dir}/patterndb/${name}.xml", @@ -44,7 +44,7 @@ } exec { "patterndb::deploy::${name}": - command => "cp ${patterndb::cache_dir}/patterndb/${name}.xml ${patterndb::base_dir}/var/lib/syslog-ng/patterndb/", + command => "cp ${patterndb::cache_dir}/patterndb/${name}.xml ${patterndb::var_dir}/patterndb/", logoutput => true, path => $facts['path'], refreshonly => true, diff --git a/spec/defines/raw_ruleset_spec.rb b/spec/defines/raw_ruleset_spec.rb index f2ea1cb..0cab2b2 100644 --- a/spec/defines/raw_ruleset_spec.rb +++ b/spec/defines/raw_ruleset_spec.rb @@ -13,7 +13,7 @@ 'myrawruleset' end let :pre_condition do - 'class { "patterndb": base_dir => "BASEDIR", }' + 'class { "patterndb": }' end context 'Raw ruleset with no params' do @@ -33,9 +33,9 @@ case facts[:osfamily] when 'FreeBSD' - it { is_expected.to contain_file('BASEDIR/usr/local/etc/patterndb.d/default/myrawruleset.pdb') } + it { is_expected.to contain_file('/usr/local/etc/patterndb.d/default/myrawruleset.pdb') } else - it { is_expected.to contain_file('BASEDIR/etc/syslog-ng/patterndb.d/default/myrawruleset.pdb') } + it { is_expected.to contain_file('/etc/syslog-ng/patterndb.d/default/myrawruleset.pdb') } end end @@ -49,9 +49,9 @@ case facts[:osfamily] when 'FreeBSD' - it { is_expected.to contain_file('BASEDIR/usr/local/etc/patterndb.d/default/myrawruleset').with(ensure: 'directory') } + it { is_expected.to contain_file('/usr/local/etc/patterndb.d/default/myrawruleset').with(ensure: 'directory') } else - it { is_expected.to contain_file('BASEDIR/etc/syslog-ng/patterndb.d/default/myrawruleset').with(ensure: 'directory') } + it { is_expected.to contain_file('/etc/syslog-ng/patterndb.d/default/myrawruleset').with(ensure: 'directory') } end end end diff --git a/spec/defines/simple_action_spec.rb b/spec/defines/simple_action_spec.rb index 7a5ab10..6a65606 100644 --- a/spec/defines/simple_action_spec.rb +++ b/spec/defines/simple_action_spec.rb @@ -18,7 +18,7 @@ } end let :pre_condition do - 'class { "patterndb": base_dir => "/BASEDIR", } + 'class { "patterndb": } patterndb::simple::ruleset { "myruleset": id => "RULESET_ID", pubdate => "1970-01-01", diff --git a/spec/defines/simple_rule_spec.rb b/spec/defines/simple_rule_spec.rb index f65d0f2..ce2470b 100644 --- a/spec/defines/simple_rule_spec.rb +++ b/spec/defines/simple_rule_spec.rb @@ -18,7 +18,7 @@ } end let :pre_condition do - 'class { "patterndb": base_dir => "/BASEDIR", } + 'class { "patterndb": } patterndb::simple::ruleset { "myruleset": id => "RULESET_ID", pubdate => "1970-01-01", @@ -78,13 +78,13 @@ when 'FreeBSD' it { is_expected.to contain_concat('patterndb_simple_ruleset-myruleset').with( - path: '/BASEDIR/usr/local/etc/patterndb.d/default/myruleset.pdb' + path: '/usr/local/etc/patterndb.d/default/myruleset.pdb' ) } else it { is_expected.to contain_concat('patterndb_simple_ruleset-myruleset').with( - path: '/BASEDIR/etc/syslog-ng/patterndb.d/default/myruleset.pdb' + path: '/etc/syslog-ng/patterndb.d/default/myruleset.pdb' ) } end diff --git a/spec/defines/simple_ruleset_spec.rb b/spec/defines/simple_ruleset_spec.rb index 8be632a..76a63cc 100644 --- a/spec/defines/simple_ruleset_spec.rb +++ b/spec/defines/simple_ruleset_spec.rb @@ -20,7 +20,7 @@ } end let :pre_condition do - 'class { "patterndb": base_dir => "/BASEDIR", } + 'class { "patterndb": } Exec { path => ["/bin","/usr/bin"] }' end @@ -61,9 +61,9 @@ case facts[:osfamily] when 'FreeBSD' - it { is_expected.to contain_concat('patterndb_simple_ruleset-myruleset').with('path' => '/BASEDIR/usr/local/etc/patterndb.d/default/myruleset.pdb') } + it { is_expected.to contain_concat('patterndb_simple_ruleset-myruleset').with('path' => '/usr/local/etc/patterndb.d/default/myruleset.pdb') } else - it { is_expected.to contain_concat('patterndb_simple_ruleset-myruleset').with('path' => '/BASEDIR/etc/syslog-ng/patterndb.d/default/myruleset.pdb') } + it { is_expected.to contain_concat('patterndb_simple_ruleset-myruleset').with('path' => '/etc/syslog-ng/patterndb.d/default/myruleset.pdb') } end it { is_expected.to contain_concat__fragment('patterndb_simple_ruleset-myruleset-header').with_content( @@ -86,9 +86,9 @@ case facts[:osfamily] when 'FreeBSD' - it { is_expected.to contain_concat('patterndb_simple_ruleset-myruleset').with('path' => '/BASEDIR/usr/local/etc/patterndb.d/default/myruleset.pdb') } + it { is_expected.to contain_concat('patterndb_simple_ruleset-myruleset').with('path' => '/usr/local/etc/patterndb.d/default/myruleset.pdb') } else - it { is_expected.to contain_concat('patterndb_simple_ruleset-myruleset').with('path' => '/BASEDIR/etc/syslog-ng/patterndb.d/default/myruleset.pdb') } + it { is_expected.to contain_concat('patterndb_simple_ruleset-myruleset').with('path' => '/etc/syslog-ng/patterndb.d/default/myruleset.pdb') } end it { is_expected.to contain_concat('patterndb_simple_ruleset-myruleset').that_notifies( @@ -148,9 +148,9 @@ case facts[:osfamily] when 'FreeBSD' - it { is_expected.to contain_concat('patterndb_simple_ruleset-myruleset').with('path' => '/BASEDIR/usr/local/etc/patterndb.d/PARSER/myruleset.pdb') } + it { is_expected.to contain_concat('patterndb_simple_ruleset-myruleset').with('path' => '/usr/local/etc/patterndb.d/PARSER/myruleset.pdb') } else - it { is_expected.to contain_concat('patterndb_simple_ruleset-myruleset').with('path' => '/BASEDIR/etc/syslog-ng/patterndb.d/PARSER/myruleset.pdb') } + it { is_expected.to contain_concat('patterndb_simple_ruleset-myruleset').with('path' => '/etc/syslog-ng/patterndb.d/PARSER/myruleset.pdb') } end it { @@ -322,9 +322,9 @@ case facts[:osfamily] when 'FreeBSD' - it { is_expected.to contain_concat('patterndb_simple_ruleset-myruleset').with('path' => '/BASEDIR/usr/local/etc/patterndb.d/default/123myruleset.pdb') } + it { is_expected.to contain_concat('patterndb_simple_ruleset-myruleset').with('path' => '/usr/local/etc/patterndb.d/default/123myruleset.pdb') } else - it { is_expected.to contain_concat('patterndb_simple_ruleset-myruleset').with('path' => '/BASEDIR/etc/syslog-ng/patterndb.d/default/123myruleset.pdb') } + it { is_expected.to contain_concat('patterndb_simple_ruleset-myruleset').with('path' => '/etc/syslog-ng/patterndb.d/default/123myruleset.pdb') } end it { is_expected.to contain_concat__fragment('patterndb_simple_ruleset-myruleset-header').with_content( From d0fd56cf3617ed061adeeba65fb28d208d12db87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Romain=20Tarti=C3=A8re?= Date: Tue, 3 Sep 2024 11:40:11 -0700 Subject: [PATCH 7/9] Add FreeBSD support to metadata.json --- metadata.json | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/metadata.json b/metadata.json index 9dac84b..7ac2c4e 100644 --- a/metadata.json +++ b/metadata.json @@ -38,6 +38,13 @@ "11" ] }, + { + "operatingsystem": "FreeBSD", + "operatingsystemrelease": [ + "13", + "14" + ] + }, { "operatingsystem": "RedHat", "operatingsystemrelease": [ From 8c8b715da1c3be86320127e74541f4311d345a15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Romain=20Tarti=C3=A8re?= Date: Tue, 14 Jan 2025 08:27:52 -1000 Subject: [PATCH 8/9] Remove references to $base_dir The variable was removed, so no need for a default value and we should not see references to it in the README. --- README.md | 20 +++++++++----------- data/default.yaml | 1 - 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 78c4644..9647fbe 100644 --- a/README.md +++ b/README.md @@ -28,14 +28,14 @@ This module will manage the pattern databases of *syslog-ng* by using existing f ### What patterndb affects -Depending on the top-level configuration variables `$base_dir` and `$cache_dir`, this module will manage and execute the following elements in order: +Depending on the top-level configuration variables `$cache_dir`, this module will manage and execute the following elements in order: 0. (OPTIONAL) Manage package `syslog-ng` -1. Manage `$base_dir/etc/syslog-ng/patterndb.d` recursively +1. Manage `/etc/syslog-ng/patterndb.d` recursively 2. Manage the contents of the above directory using [existing](#defined-type-patterndbrawruleset) or [generated](#defined-type-patterndbsimpleruleset) patterndb *ruleset* files 3. Merge the contents of the latter using `pdbtool` into a temporary file `${cache_dir}/syslog-ng/patterndb/${parser}.xml` where `$parser` is the name of the *patterndb* (you can have as many as you want, *e.g.* for *staged parsing*. 4. (OPTIONAL) Test the resulting patterndbs -5. Deploy the temporary files into `${base_dir}/var/lib/syslog-ng/patterndb/${parser}.xml` +5. Deploy the temporary files into `/var/lib/syslog-ng/patterndb/${parser}.xml` Reloading of the *syslog-ng* daemon is not being taken care of, as the latter already does that on its own by polling the *patterndb* file for change. @@ -82,7 +82,6 @@ class { "patterndb": } ... or overriding paths ```puppet class { "patterndb": - $base_dir => "/", $temp_dir => "/tmp" } ``` @@ -142,12 +141,11 @@ This class will manage the following *resources*: * `Package[$package_name]` if `$manage_package` is set to `true`. * `File[$temp_dir]` as a directory. -* `File["${base_dir}/etc/syslog-ng/patterndb.d"]` recursively, purging unknown files. -* `File["${base_dir}/var/lib/syslog-ng/patterndb/${parser}.xml"]` for each `$parser` (defaults to `'default'`) +* `File["$/etc/syslog-ng/patterndb.d"]` recursively, purging unknown files. +* `File["/var/lib/syslog-ng/patterndb/${parser}.xml"]` for each `$parser` (defaults to `'default'`) #### Optional Parameters -* `$base_dir` Top level directory for storing resources. Defaults to `'/'` * `$temp_dir` Temporary directory for various components. Defaults to `'/tmp/syslog-ng'` * `$package_name` Name of the `syslog-ng` package. Defaults to the OS shipped * `$manage_package` Boolean to control the management of the package. Defaults to `true` @@ -266,11 +264,11 @@ Notice: Applied catalog in 1.33 seconds If using the defaults, and only one *pattern parser*, you probably won't need to define this resource, as it will get automatically created for you when defining a *ruleset*. This resource represents a *patterndb parser*, which is eventually materialized by a *File puppet resource*: ```puppet -File["${base_dir}/var/lib/syslog-ng/patterndb/${name}.xml"] +File["/var/lib/syslog-ng/patterndb/${name}.xml"] ``` This *File* is generated by merging all defined *ruleset resources*, which come in two forms: [raw](#defined-type-patterndbrawruleset) and [simple](#defined-type-patterndbsimpleruleset). -Merging is handled under the hood by using `pdbtool merge` which creates a new *patterndb parser* in the `${temp_dir}` directory. Testing of the merged *parser* is optionally handled using `pdbtool test`. If this is a success, the merged file is then being deployed into the definitive destination at `${base_dir}/var/lib/syslog-ng/patterndb/${name}.xml`. +Merging is handled under the hood by using `pdbtool merge` which creates a new *patterndb parser* in the `${temp_dir}` directory. Testing of the merged *parser* is optionally handled using `pdbtool test`. If this is a success, the merged file is then being deployed into the definitive destination at `/var/lib/syslog-ng/patterndb/${name}.xml`. #### Optional Parameters @@ -300,7 +298,7 @@ patterndb::parser { 'default': Describes a *resultset* using *XML* content. Use only if you have existing *pdb* files. The use of [`patterndb::simple::ruleset`](#defined-type-patterndbsimpleruleset) is highly encouraged otherwise. This type will define the following *puppet resource*: ```puppet -File["${base_dir}/etc/syslog-ng/patterndb.d/${parser}/${name}.pdb"] +File["/etc/syslog-ng/patterndb.d/${parser}/${name}.pdb"] ``` #### Parameters @@ -361,7 +359,7 @@ patterndb::raw::ruleset { 'ruleset_for_pdb_2': Describes a *ruleset* using *puppet code*. Like its sibling [`patterndb::raw::ruleset`](#defined-type-patterndbrawruleset), this type will define the following *puppet resource*: ```puppet -File["${base_dir}/etc/syslog-ng/patterndb.d/${parser}/${name}.pdb"] +File["/etc/syslog-ng/patterndb.d/${parser}/${name}.pdb"] ``` Additional internal resources can be created, depending on the parameters: diff --git a/data/default.yaml b/data/default.yaml index a72a3e9..0625fca 100644 --- a/data/default.yaml +++ b/data/default.yaml @@ -1,5 +1,4 @@ --- -patterndb::base_dir: / patterndb::package_name: false patterndb::manage_package: true patterndb::package_name: syslog-ng From 97826495e071031fd41607c3b00340bf1f9c3c58 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Romain=20Tarti=C3=A8re?= Date: Mon, 13 Jan 2025 10:01:16 -1000 Subject: [PATCH 9/9] Drop CentOS 7 and 8 support These versions or CentOS have reached end-of-life and the images used for CI are not available anymore. As we cannot ensure these legacy systems are still working with the module, remove them from metadata.json. --- metadata.json | 2 -- 1 file changed, 2 deletions(-) diff --git a/metadata.json b/metadata.json index 7ac2c4e..6bdd96e 100644 --- a/metadata.json +++ b/metadata.json @@ -27,8 +27,6 @@ { "operatingsystem": "CentOS", "operatingsystemrelease": [ - "7", - "8" ] }, {