Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for FreeBSD #48

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`

Expand Down
5 changes: 3 additions & 2 deletions data/default.yaml
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions data/osfamily/Debian.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
patterndb::package_name: syslog-ng-core
3 changes: 3 additions & 0 deletions data/osfamily/FreeBSD.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
patterndb::config_dir: /usr/local/etc/patterndb.d
patterndb::var_dir: /var/syslog-ng
1 change: 0 additions & 1 deletion examples/NOK_mismatching_action.pp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#
class { 'patterndb':
manage_package => false,
base_dir => '/tmp/',
}

Exec {
Expand Down
1 change: 0 additions & 1 deletion examples/OK_getent.pp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#
class { 'patterndb':
manage_package => false,
base_dir => '/tmp/',
syslogng_modules => ['tfgetent'],
}

Expand Down
1 change: 0 additions & 1 deletion examples/OK_hiera.pp
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#
class { 'patterndb':
base_dir => '/tmp/',
manage_package => false,
syslogng_modules => [],
use_hiera => true,
Expand Down
1 change: 0 additions & 1 deletion examples/OK_hiera_puppet5.pp
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#
class { 'patterndb':
base_dir => '/tmp/',
manage_package => false,
syslogng_modules => [],
use_hiera => true,
Expand Down
1 change: 0 additions & 1 deletion examples/OK_hybrid.pp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#
class { 'patterndb':
manage_package => false,
base_dir => '/tmp/',
}

patterndb::raw::ruleset { 'raw':
Expand Down
1 change: 0 additions & 1 deletion examples/OK_ltgt.pp
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#
class { 'patterndb':
base_dir => '/tmp/',
manage_package => false,
syslogng_modules => [],
}
Expand Down
1 change: 0 additions & 1 deletion examples/OK_modules.pp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
}
class { 'patterndb':
manage_package => false,
base_dir => '/tmp/',
syslogng_modules => ['basicfuncs'],
}

Expand Down
1 change: 0 additions & 1 deletion examples/OK_multiple_pdb.pp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#
class { 'patterndb':
manage_package => false,
base_dir => '/tmp/',
}

patterndb::simple::ruleset { 'dhclient':
Expand Down
1 change: 0 additions & 1 deletion examples/OK_notest.pp
Original file line number Diff line number Diff line change
@@ -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,
}
Expand Down
1 change: 0 additions & 1 deletion examples/OK_raw.pp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#
class { 'patterndb':
manage_package => false,
base_dir => '/tmp/',
syslogng_modules => [],
}

Expand Down
1 change: 0 additions & 1 deletion examples/OK_s.pp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#
class { 'patterndb':
manage_package => false,
base_dir => '/tmp/',
}

Patterndb::Simple::Rule {
Expand Down
1 change: 0 additions & 1 deletion examples/OK_separate_action.pp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#
class { 'patterndb':
manage_package => false,
base_dir => '/tmp/',
}

Exec {
Expand Down
1 change: 0 additions & 1 deletion examples/OK_separate_rules.pp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#
class { 'patterndb':
manage_package => false,
base_dir => '/tmp/',
}

patterndb::simple::ruleset { 'empty_ruleset':
Expand Down
1 change: 0 additions & 1 deletion examples/OK_separate_rules_and_actions.pp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#
class { 'patterndb':
manage_package => false,
base_dir => '/tmp/',
}

Exec {
Expand Down
1 change: 0 additions & 1 deletion examples/OK_simple.pp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#
class { 'patterndb':
manage_package => false,
base_dir => '/tmp/',
}

patterndb::simple::ruleset { 'dhclient':
Expand Down
1 change: 0 additions & 1 deletion examples/OK_simple_action.pp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#
class { 'patterndb':
manage_package => false,
base_dir => '/tmp/',
}

patterndb::simple::ruleset { 'dhclient':
Expand Down
1 change: 0 additions & 1 deletion examples/OK_simple_coerce.pp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#
class { 'patterndb':
manage_package => false,
base_dir => '/tmp/',
}

patterndb::simple::ruleset { 'plop':
Expand Down
1 change: 0 additions & 1 deletion examples/OK_simple_context.pp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#
class { 'patterndb':
manage_package => false,
base_dir => '/tmp/',
}

patterndb::simple::ruleset { 'dhclient':
Expand Down
1 change: 0 additions & 1 deletion examples/OK_simple_empty.pp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#
class { 'patterndb':
manage_package => false,
base_dir => '/tmp/',
}

patterndb::simple::ruleset { 'empty':
Expand Down
1 change: 0 additions & 1 deletion examples/OK_yum.pp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#
class { 'patterndb':
manage_package => false,
base_dir => '/tmp',
syslogng_modules => [],
test_before_deploy => true,
}
Expand Down
49 changes: 14 additions & 35 deletions manifests/init.pp
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
14 changes: 7 additions & 7 deletions manifests/parser.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions manifests/raw/ruleset.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion manifests/simple/ruleset.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
7 changes: 7 additions & 0 deletions metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@
"11"
]
},
{
"operatingsystem": "FreeBSD",
"operatingsystemrelease": [
"13",
"14"
]
},
{
"operatingsystem": "RedHat",
"operatingsystemrelease": [
Expand Down
7 changes: 0 additions & 7 deletions spec/classes/patterndb_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading
Loading