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 6515103..a72a3e9 100644 --- a/data/default.yaml +++ b/data/default.yaml @@ -1,11 +1,12 @@ --- 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 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/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/data/osfamily/FreeBSD.yaml b/data/osfamily/FreeBSD.yaml new file mode 100644 index 0000000..ec4f07d --- /dev/null +++ b/data/osfamily/FreeBSD.yaml @@ -0,0 +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 7848c90..3d41364 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -1,51 +1,30 @@ # class patterndb ( - String[1] $base_dir = '/', - String[1] $temp_dir = "${base_dir}/tmp/syslog-ng", - Variant[String[1],Boolean] $package_name = false, + String[1] $package_name, + Stdlib::Absolutepath $config_dir, + Stdlib::Absolutepath $var_dir, + Stdlib::Absolutepath $cache_dir = '/var/cache/syslog-ng', Boolean $manage_package = true, Array[String[1]] $syslogng_modules = [], Boolean $use_hiera = false, - Boolean $_manage_top_dirs = true, Boolean $test_before_deploy = true ) { # 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' } - default: { fail("unsupported osfamily: ${facts['os']['family']}") } - } - } - ensure_resource ( 'package', $real_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 ( 'package', $package_name, { 'ensure' => 'installed' }) } + ensure_resource ( 'file', $cache_dir, { ensure => directory }) ensure_resource ( - 'file', "${base_dir}/etc/syslog-ng", + 'file', $var_dir, { ensure => 'directory' } ) - ensure_resource ( - 'file', "${base_dir}/var/lib/syslog-ng", - { ensure => 'directory' } - ) - ensure_resource ( - 'file', "${base_dir}/var/lib/syslog-ng/patterndb", - { - ensure => 'directory', - purge => true, - recurse => true - } - ) - $pdb_dir = "${base_dir}/etc/syslog-ng/patterndb.d" - file { $pdb_dir: + file { "${var_dir}/patterndb": + ensure => 'directory', + purge => true, + recurse => true, + } + + file { $config_dir: ensure => directory, purge => true, force => true, diff --git a/manifests/parser.pp b/manifests/parser.pp index 811ddf3..dde73b9 100644 --- a/manifests/parser.pp +++ b/manifests/parser.pp @@ -15,36 +15,36 @@ $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, 'recurse' => true, }) - ensure_resource ('file', "${patterndb::temp_dir}/patterndb", { + ensure_resource ('file', "${patterndb::cache_dir}/patterndb", { 'ensure' => 'directory', }) 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::pdb_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::var_dir}/patterndb/", logoutput => true, path => $facts['path'], 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/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": [ 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 diff --git a/spec/defines/raw_ruleset_spec.rb b/spec/defines/raw_ruleset_spec.rb index 542e21d..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 @@ -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('/usr/local/etc/patterndb.d/default/myrawruleset.pdb') } + else + it { is_expected.to contain_file('/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('/usr/local/etc/patterndb.d/default/myrawruleset').with(ensure: 'directory') } + else + it { is_expected.to contain_file('/etc/syslog-ng/patterndb.d/default/myrawruleset').with(ensure: 'directory') } + end 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 1f41e53..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", @@ -74,10 +74,21 @@ ) } + case facts[:osfamily] + when 'FreeBSD' + 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: '/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..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 @@ -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' => '/usr/local/etc/patterndb.d/default/myruleset.pdb') } + else + 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').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' => '/usr/local/etc/patterndb.d/default/myruleset.pdb') } + else + 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').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' => '/usr/local/etc/patterndb.d/PARSER/myruleset.pdb') } + else + it { is_expected.to contain_concat('patterndb_simple_ruleset-myruleset').with('path' => '/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' => '/usr/local/etc/patterndb.d/default/123myruleset.pdb') } + else + 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('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 )