Skip to content

Commit

Permalink
Merge pull request #4 from tuxfight3r/legacy_options
Browse files Browse the repository at this point in the history
Added support for legacy options in the module
  • Loading branch information
crayfishx authored Jun 10, 2016
2 parents 8745458 + 6de6a54 commit 5804518
Show file tree
Hide file tree
Showing 10 changed files with 138 additions and 2 deletions.
3 changes: 2 additions & 1 deletion CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
The module is written as 2 main components one is is installing the package,
configuring the service etc.., with base install and the second is configuring
it as client/server based on the configuration data provided. The configuration
class is broken down into 7 classes
class is broken down into 8 classes

```
* rsyslog::config::modules
Expand All @@ -20,6 +20,7 @@
* rsyslog::config::actions
* rsyslog::config::inputs
* rsyslog::config::custom
* rsyslog::config::legacy
```

Each of the above classes accepts either an Array or Hash as its input. There
Expand Down
79 changes: 78 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
* [Templates](#rsyslogservertemplates)
* [Actions](#rsyslogserveractions-rsyslogclientactions)
* [Inputs](#rsyslogserverinputs-rsyslogclientinputs)
* [legacy_config](#rsyslogserverlegacy_config)
* [Positioning](#positioning)
* [Formatting](#formatting)

Expand Down Expand Up @@ -113,6 +114,7 @@ The following configuration parameters are defaults for the order of configurati
```yaml
## Default object type priorities (can be overridden)
rsyslog::module_load_priority: 10
rsyslog::legacy_config_priority: 11
rsyslog::input_priority: 15
rsyslog::global_config_priority: 20
rsyslog::main_queue_priority: 25
Expand All @@ -131,6 +133,7 @@ Configuration objects are written to the configuration file in rainerscript form
* [Templates](#rsyslogservertemplates)
* [Actions](#rsyslogserveractions-rsyslogclientactions)
* [Inputs](#rsyslogserverinputs-rsyslogclientinputs)
* [legacy_config](#rsyslogserverlegacy_config)
Configuration objects should be declared in the rsyslog::server or rsyslog::client namespaces accordingly.
Expand Down Expand Up @@ -295,8 +298,82 @@ input(type="imudp"
)
```

##### `rsyslog::server::legacy_config`

Legacy config support is provided to facilitate backwards compatibility with `sysklogd` format as this module mainly supports `rainerscript` format.

A hash of hashes, each hash name is used as the comment/reference for the setting and the hash will have the following values:
* `key`: the key/logger rule setting
* `value`: the value/target of the setting
* `type`: the type of format to use (legacy or sysklogd), if omitted sysklogd is used. If legacy type is used `key` can be skipped and one long string can be provided as value.

```yaml
rsyslog::client::legacy_config:
auth_priv_rule:
key: "auth,authpriv.*"
value: "/var/log/auth.log"
auth_none_rule:
key: "*.*;auth,authpriv.none"
value: "/var/log/syslog"
syslog_all_rule:
key: "syslog.*"
value: "/var/log/rsyslog.log"
mail_error_rule:
key: "mail.err"
value: "/var/log/mail.err"
news_critical_rule:
key: "news.crit"
value: "/var/log/news/news.crit"
```
will produce
```
# auth_priv_rule
auth,authpriv.* /var/log/auth.log

# auth_none_rule
*.*;auth,authpriv.none /var/log/syslog

# syslog_all_rule
syslog.* /var/log/rsyslog.log

# mail_error_rule
mail.err /var/log/mail.err

# news_critical_rule
news.crit /var/log/news/news.crit

```
legacy type values can be passed as one long string skipping the key parameter like below and you can also override the priority in the hash to rearrange the contents
```
emergency_rule:
key: "*.emerg"
value: ":omusrmsg:*"
testing_legacy_remotelog:
value: "*.* @@logmonster.cloudfront.net:1514"
type: "legacy"
priority: 12
testing_legacy_rule:
value: "*.* >dbhost,dbname,dbuser,dbpassword;dbtemplate"
type: "legacy"
```
will produce

```
# emergency_rule
*.emerg :omusrmsg:*
# testing_legacy_rule
*.* >dbhost,dbname,dbuser,dbpassword;dbtemplate
# testing_legacy_remotelog
*.* @@logmonster.cloudfront.net:1514
```

### Positioning
All rsyslog object types are positioned according to the default variables (see [Ordering](#ordering)). The position can be overriden for any object by adding the optional `position` parameter.
All rsyslog object types are positioned according to the default variables (see [Ordering](#ordering)). The position can be overridden for any object by adding the optional `position` parameter.

```yaml
rsyslog::server::actions:
Expand Down
1 change: 1 addition & 0 deletions data/common.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ rsyslog::feature_packages: []

## Default object type priorities (can be overridden)
rsyslog::module_load_priority: 10
rsyslog::legacy_config_priority: 11
rsyslog::input_priority: 15
rsyslog::global_config_priority: 20
rsyslog::main_queue_priority: 25
Expand Down
2 changes: 2 additions & 0 deletions manifests/client.pp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
class rsyslog::client (
Optional[Hash] $global_config = {},
Optional[Hash] $legacy_config = {},
Optional[Hash] $actions = {},
Optional[Hash] $inputs = {},
Optional[Hash] $custom_config = {},
Expand All @@ -10,6 +11,7 @@

class { 'rsyslog::config':
global_config => $global_config,
legacy_config => $legacy_config,
actions => $actions,
inputs => $inputs,
custom_config => $custom_config,
Expand Down
25 changes: 25 additions & 0 deletions manifests/component/legacy_config.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
define rsyslog::component::legacy_config (
Integer $priority,
String $target,
String $value,
Optional[String] $key = 'legacy_key',
Optional[String] $type = 'sysklogd',
Optional[String] $format = '<%= $content %>'
) {

include rsyslog

$content = epp('rsyslog/legacy_config.epp', {
'config_item' => $name,
'type' => $type,
'key' => $key,
'value' => $value,
})

concat::fragment {"rsyslog::component::legacy_config::${name}":
target => "${::rsyslog::confdir}/${target}",
content => inline_epp($format),
order => $priority,
}

}
2 changes: 2 additions & 0 deletions manifests/config.pp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
class rsyslog::config (
Optional[Hash] $global_config = {},
Optional[Hash] $legacy_config = {},
Optional[Hash] $templates = {},
Optional[Hash] $actions = {},
Optional[Hash] $inputs = {},
Expand All @@ -15,6 +16,7 @@

include rsyslog::config::modules
include rsyslog::config::global
include rsyslog::config::legacy
include rsyslog::config::main_queue
include rsyslog::config::templates
include rsyslog::config::actions
Expand Down
10 changes: 10 additions & 0 deletions manifests/config/legacy.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class rsyslog::config::legacy {
$::rsyslog::config::legacy_config.each |$name, $config| {
rsyslog::component::legacy_config { $name:
* => {
'priority' => $::rsyslog::legacy_config_priority,
'target' => $::rsyslog::target_file,
} + $config,
}
}
}
1 change: 1 addition & 0 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
Boolean $manage_confdir,
Boolean $purge_config_files,
Integer $global_config_priority,
Integer $legacy_config_priority,
Integer $template_priority,
Integer $action_priority,
Integer $input_priority,
Expand Down
2 changes: 2 additions & 0 deletions manifests/server.pp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
class rsyslog::server (
Optional[Hash] $global_config = {},
Optional[Hash] $legacy_config = {},
Optional[Hash] $templates = {},
Optional[Hash] $actions = {},
Optional[Hash] $inputs = {},
Expand All @@ -13,6 +14,7 @@

class { 'rsyslog::config':
global_config => $global_config,
legacy_config => $legacy_config,
templates => $templates,
actions => $actions,
inputs => $inputs,
Expand Down
15 changes: 15 additions & 0 deletions templates/legacy_config.epp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<%- |
String $config_item,
String $value,
Optional[String] $key,
Optional[String] $type
| -%>
<% if $type == 'sysklogd' { -%>
# <%= $config_item %>
<%= $key %> <%= $value %>

<% } else { -%>
# <%= $config_item %>
<%= $value %>

<% } -%>

0 comments on commit 5804518

Please sign in to comment.