From a71dac3ab06d182d7fcd7557ba36825302b7e5f3 Mon Sep 17 00:00:00 2001 From: Brian Schonecker Date: Mon, 18 Sep 2023 10:04:01 -0400 Subject: [PATCH 1/2] Add boolean variable to change behavior of multi-line actions in conf files. --- REFERENCE.md | 18 ++++++++++++++++++ manifests/component/action.pp | 10 ++++++---- manifests/init.pp | 3 +++ spec/defines/component/action_spec.rb | 3 +++ templates/action.epp | 5 +++-- templates/tasks.epp | 4 ++-- 6 files changed, 35 insertions(+), 8 deletions(-) diff --git a/REFERENCE.md b/REFERENCE.md index 04ed01e7..878463ce 100644 --- a/REFERENCE.md +++ b/REFERENCE.md @@ -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) @@ -280,6 +281,14 @@ Data type: `Integer` Set the global ordering of action configuration in rsyslog. +##### `dont_linebreak_actions` + +Data type: `Boolean` + +Ensure that all action options are placed on a single line. + +Default value: `false` + ##### `input_priority` Data type: `Integer` @@ -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) @@ -682,6 +692,14 @@ Data type: `String` +##### `dont_linebreak_actions` + +Data type: `Boolean` + + + +Default value: `$rsyslog::dont_linebreak_actions` + ##### `config` Data type: `Hash` diff --git a/manifests/component/action.pp b/manifests/component/action.pp index 9eda3277..41c20d75 100644 --- a/manifests/component/action.pp +++ b/manifests/component/action.pp @@ -3,6 +3,7 @@ String $target, String $confdir, String $type, + Boolean $dont_linebreak_actions = $rsyslog::dont_linebreak_actions, Hash $config = {}, String[1] $facility = 'default', String[1] $format = '<%= $content %>' @@ -10,10 +11,11 @@ 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}": diff --git a/manifests/init.pp b/manifests/init.pp index cef1ccc4..b06aba18 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -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 @@ -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!') diff --git a/spec/defines/component/action_spec.rb b/spec/defines/component/action_spec.rb index 5f8cfb23..54cbef3b 100644 --- a/spec/defines/component/action_spec.rb +++ b/spec/defines/component/action_spec.rb @@ -18,6 +18,7 @@ type: 'omelasticsearch', priority: 40, target: '50_rsyslog.conf', + dont_linebreak_actions: false, confdir: '/etc/rsyslog.d', config: { 'queue.type' => 'linkedlist', @@ -49,6 +50,7 @@ priority: 40, target: '50_rsyslog.conf', confdir: '/etc/rsyslog.d', + dont_linebreak_actions: false, facility: 'kern.*', config: { 'dynaFile' => 'remoteKern' @@ -67,6 +69,7 @@ type: 'omelasticsearch', priority: 40, target: '50_rsyslog.conf', + dont_linebreak_actions: false, confdir: '/etc/rsyslog.d', facility: '*.*', config: { diff --git a/templates/action.epp b/templates/action.epp index 4d61e9b7..cd5ae026 100644 --- a/templates/action.epp +++ b/templates/action.epp @@ -2,11 +2,12 @@ $action_name, $type, $facility, +Boolean $dont_linebreak_actions = false, $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 -%>" <% }-%>) <%-}%> diff --git a/templates/tasks.epp b/templates/tasks.epp index 12dc6bd2..66d1d3f8 100644 --- a/templates/tasks.epp +++ b/templates/tasks.epp @@ -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, }) %><%-%> <%-}-%> -<%-}-%> \ No newline at end of file +<%-}-%> From 6c22e43a6fe43a8bb1c6f5c16822c1798c498495 Mon Sep 17 00:00:00 2001 From: Brian Schonecker Date: Mon, 18 Sep 2023 10:46:17 -0400 Subject: [PATCH 2/2] foo --- templates/action.epp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/action.epp b/templates/action.epp index cd5ae026..83143c56 100644 --- a/templates/action.epp +++ b/templates/action.epp @@ -2,7 +2,7 @@ $action_name, $type, $facility, -Boolean $dont_linebreak_actions = false, +Boolean $dont_linebreak_actions, $config | -%> # <%= $action_name %>