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

(#148) Added a parameter that allows users to define rsyslog rules via hieradata #149

Merged
merged 4 commits into from
Mar 4, 2024
Merged
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
3 changes: 3 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
* Tue Feb 27 2024 Mike Riddle <[email protected]> - 8.7.0
- Added a parameter that allows users to define rsyslog rules via hieradata

* Mon Oct 23 2023 Steven Pritchard <[email protected]> - 8.6.0
- Add EL9 support

Expand Down
27 changes: 25 additions & 2 deletions REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,18 @@ been addressed.

See ``rsyslog::config`` for additional, detailed configuration.

#### Examples

##### Create rules via hieradata:

```puppet
rsyslog::rules:
'some_path/99_collect_kernel_errors.conf':
content: "if prifilt('kern.err') then /var/log/kernel_errors.log"
'some_path/98_discard_info.conf':
content: "if prifilt('*.info') then stop"
```

#### Parameters

The following parameters are available in the `rsyslog` class:
Expand All @@ -77,6 +89,7 @@ The following parameters are available in the `rsyslog` class:
* [`pki`](#-rsyslog--pki)
* [`app_pki_external_source`](#-rsyslog--app_pki_external_source)
* [`app_pki_dir`](#-rsyslog--app_pki_dir)
* [`rules`](#-rsyslog--rules)

##### <a name="-rsyslog--service_name"></a>`service_name`

Expand Down Expand Up @@ -288,6 +301,14 @@ and $default_net_stream_driver_key_file

Default value: `'/etc/pki/simp_apps/rsyslog/x509'`

##### <a name="-rsyslog--rules"></a>`rules`

Data type: `Hash`

A hash of rsyslog rules, this parameter will enable you to create rules via hieradata

Default value: `{}`

### <a name="rsyslog--server"></a>`rsyslog::server`

This class is designed to configure the externally facing interfaces for a
Expand Down Expand Up @@ -333,6 +354,8 @@ Default value: `simplib::lookup('simp_options::tcpwrappers', { 'default_value' =
This is used by the various ``rsyslog::rule::*`` Defined Types to apply rules
to the system.

The naming convention for the rule must be ``some_directory/rule_name.conf``

Feel free to use this Defined Type to add your own rules but remember that
**order matters**!

Expand All @@ -358,8 +381,8 @@ In general, the order will be:
##### Collect All ``kern.err`` Messages

```puppet
rsyslog::rule { '99_collect_kernel_errors.conf':
rule => "if prifilt('kern.err') then /var/log/kernel_errors.log"
rsyslog::rule { '99_simp_local/99_collect_kernel_errors.conf':
content => "if prifilt('kern.err') then /var/log/kernel_errors.log"
}
```

Expand Down
20 changes: 18 additions & 2 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,16 @@
# Basepath of $default_net_stream_driver_ca_file, default_net_stream_driver_cert_file,
# and $default_net_stream_driver_key_file
#
# @param rules
# A hash of rsyslog rules, this parameter will enable you to create rules via hieradata
#
# @example Create rules via hieradata:
# rsyslog::rules:
# 'some_path/99_collect_kernel_errors.conf':
# content: "if prifilt('kern.err') then /var/log/kernel_errors.log"
# 'some_path/98_discard_info.conf':
# content: "if prifilt('*.info') then stop"
#
# @author https://github.com/simp/pupmod-simp-rsyslog/graphs/contributors
#
class rsyslog (
Expand All @@ -135,9 +145,9 @@
Boolean $logrotate = simplib::lookup('simp_options::logrotate', {'default_value' => false}),
Variant[Boolean,Enum['simp']] $pki = simplib::lookup('simp_options::pki', {'default_value' => false}),
String $app_pki_external_source = simplib::lookup('simp_options::pki::source', {'default_value' => '/etc/pki/simp/x509'}),
Stdlib::Absolutepath $app_pki_dir = '/etc/pki/simp_apps/rsyslog/x509'
Stdlib::Absolutepath $app_pki_dir = '/etc/pki/simp_apps/rsyslog/x509',
Hash $rules = {},
) {

if $facts['rsyslogd'] and versioncmp($facts['rsyslogd']['version'], '8.24.0') < 0 {
warning("${module_name}: Rsyslog version ${facts['rsyslogd']} not supported. Use ${module_name} version 7.6.4 instead")
}
Expand All @@ -156,4 +166,10 @@
contain 'rsyslog::config::logrotate'
Class['rsyslog::service'] -> Class['rsyslog::config::logrotate']
}

$rules.each |$key, $value| {
rsyslog::rule { $key:
* => $value,
}
}
}
6 changes: 4 additions & 2 deletions manifests/rule.pp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
# This is used by the various ``rsyslog::rule::*`` Defined Types to apply rules
# to the system.
#
# The naming convention for the rule must be ``some_directory/rule_name.conf``
#
# Feel free to use this Defined Type to add your own rules but remember that
# **order matters**!
#
Expand All @@ -16,8 +18,8 @@
# * 99 - Local Rules
#
# @example Collect All ``kern.err`` Messages
# rsyslog::rule { '99_collect_kernel_errors.conf':
# rule => "if prifilt('kern.err') then /var/log/kernel_errors.log"
# rsyslog::rule { '99_simp_local/99_collect_kernel_errors.conf':
# content => "if prifilt('kern.err') then /var/log/kernel_errors.log"
# }
#
# @example Discard All ``info`` Messages
Expand Down
2 changes: 1 addition & 1 deletion metadata.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "simp-rsyslog",
"version": "8.6.0",
"version": "8.7.0",
"author": "SIMP Team",
"summary": "A puppet module to support RSyslog version 8.",
"license": "Apache-2.0",
Expand Down
12 changes: 12 additions & 0 deletions spec/classes/init_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,18 @@
it { is_expected.to contain_file(global_conf_file).with_content(global_expected) }
end

context 'with a rules hash defined' do
let(:params) {{
:rules => {
'some_path/99_collect_kernel_errors.conf' => {
:content => "if prifilt('kern.err') then /var/log/kernel_errors.log"
}
}
}}

it {is_expected.to contain_rsyslog__rule('some_path/99_collect_kernel_errors.conf').with_content("if prifilt('kern.err') then /var/log/kernel_errors.log")}
end

end # end `context "on #{os}"...`
end # end `on_supported_os.each...`
end
Loading