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 boolean variable to change behavior of multi-line actions in conf… #204

Closed
Closed
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
18 changes: 18 additions & 0 deletions REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ The following parameters are available in the `rsyslog` class:
* [`legacy_config_priority`](#-rsyslog--legacy_config_priority)
* [`template_priority`](#-rsyslog--template_priority)
* [`action_priority`](#-rsyslog--action_priority)
* [`dont_linebreak_actions`](#-rsyslog--dont_linebreak_actions)
* [`input_priority`](#-rsyslog--input_priority)
* [`custom_priority`](#-rsyslog--custom_priority)
* [`main_queue_priority`](#-rsyslog--main_queue_priority)
Expand Down Expand Up @@ -280,6 +281,14 @@ Data type: `Integer`

Set the global ordering of action configuration in rsyslog.

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

Data type: `Boolean`

Ensure that all action options are placed on a single line.

Default value: `false`

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

Data type: `Integer`
Expand Down Expand Up @@ -654,6 +663,7 @@ The following parameters are available in the `rsyslog::component::action` defin
* [`target`](#-rsyslog--component--action--target)
* [`confdir`](#-rsyslog--component--action--confdir)
* [`type`](#-rsyslog--component--action--type)
* [`dont_linebreak_actions`](#-rsyslog--component--action--dont_linebreak_actions)
* [`config`](#-rsyslog--component--action--config)
* [`facility`](#-rsyslog--component--action--facility)
* [`format`](#-rsyslog--component--action--format)
Expand Down Expand Up @@ -682,6 +692,14 @@ Data type: `String`



##### <a name="-rsyslog--component--action--dont_linebreak_actions"></a>`dont_linebreak_actions`

Data type: `Boolean`



Default value: `$rsyslog::dont_linebreak_actions`

##### <a name="-rsyslog--component--action--config"></a>`config`

Data type: `Hash`
Expand Down
10 changes: 6 additions & 4 deletions manifests/component/action.pp
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,19 @@
String $target,
String $confdir,
String $type,
Boolean $dont_linebreak_actions = $rsyslog::dont_linebreak_actions,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Considering a catalog with:

rsyslog::component::action { 'foo':
  # ...
}

this will fail because the rsyslog was not included (it is included on line 10, but the parameter default value need it before that code is run).

The following would work:

include rsyslog

rsyslog::component::action { 'foo':
  # ...
}

The test suite probably need to be adjusted to ensure the main class of the module is included before testing the rsyslog::component::action class:

https://rspec-puppet.com/documentation/defined_types/#specifying-code-to-include-before

Hash $config = {},
String[1] $facility = 'default',
String[1] $format = '<%= $content %>'
) {
include rsyslog

$content = epp('rsyslog/action.epp', {
'action_name' => $name,
'type' => $type,
'facility' => $facility,
'config' => $config,
'action_name' => $name,
'type' => $type,
'facility' => $facility,
'config' => $config,
'dont_linebreak_actions' => $dont_linebreak_actions,
})

rsyslog::generate_concat { "rsyslog::concat::action::${title}":
Expand Down
3 changes: 3 additions & 0 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@
# Set the global ordering of template configuration in rsyslog.
# @param action_priority
# Set the global ordering of action configuration in rsyslog.
# @param dont_linebreak_actions
# Ensure that all action options are placed on a single line.
# @param input_priority
# Set the global ordering of input configuration in rsyslog.
# @param custom_priority
Expand Down Expand Up @@ -118,6 +120,7 @@
Stdlib::Filemode $conf_permissions = '0644',
Stdlib::Filemode $confdir_permissions = '0755',
Stdlib::Filemode $global_conf_perms = $conf_permissions,
Boolean $dont_linebreak_actions = false,
) {
if $manage_service == true and $external_service == true {
fail('manage_service and external_service cannot be set at the same time!')
Expand Down
3 changes: 3 additions & 0 deletions spec/defines/component/action_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
type: 'omelasticsearch',
priority: 40,
target: '50_rsyslog.conf',
dont_linebreak_actions: false,
confdir: '/etc/rsyslog.d',
config: {
'queue.type' => 'linkedlist',
Expand Down Expand Up @@ -49,6 +50,7 @@
priority: 40,
target: '50_rsyslog.conf',
confdir: '/etc/rsyslog.d',
dont_linebreak_actions: false,
facility: 'kern.*',
config: {
'dynaFile' => 'remoteKern'
Expand All @@ -67,6 +69,7 @@
type: 'omelasticsearch',
priority: 40,
target: '50_rsyslog.conf',
dont_linebreak_actions: false,
confdir: '/etc/rsyslog.d',
facility: '*.*',
config: {
Expand Down
5 changes: 3 additions & 2 deletions templates/action.epp
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
$action_name,
$type,
$facility,
Boolean $dont_linebreak_actions,
$config
| -%>
# <%= $action_name %>
<% if $facility != "default" and size($config) < 3 { -%>
<%= sprintf( '%-30s %s%s%s', $facility, 'action(type="',$type,'" ' )-%>
<% if $facility != "default" and size($config) < 3 or $dont_linebreak_actions { -%>
<%= sprintf('%-30s action(type="%s" ', $facility, $type) -%>
<% if $config { -%>
<% $config.each |$k, $v| { -%> <%= $k -%>="<%= $v -%>" <% }-%>)
<%-}%>
Expand Down
4 changes: 2 additions & 2 deletions templates/tasks.epp
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ $tasks
<%}-%>
<%- } elsif $config == 'action' { -%>
<%- if ! $cfgval['facility'] or $cfgval['facility'] == '' { $facility = 'default' } else { $facility = $cfgval['facility'] } -%>
<%= epp('rsyslog/action.epp', { 'action_name' => $cfgval['name'], 'type' => $cfgval['type'], 'facility' => $facility, 'config' => $cfgval['config'],}) %>
<%= epp('rsyslog/action.epp', { 'action_name' => $cfgval['name'], 'type' => $cfgval['type'], 'facility' => $facility, 'config' => $cfgval['config'], 'dont_linebreak_actions' => $cfgval['dont_linebreak_actions'], }) %>
<%-} elsif $config == 'stop' { -%>
stop
<%} elsif $config == 'exec' { -%>
<%= epp('rsyslog/exec.epp', { 'value' => $cfgval, }) %><%-%>
<%-}-%>
<%-}-%>
<%-}-%>