Skip to content

Commit

Permalink
configuring mulitple remote servers from the remote_servers parameter…
Browse files Browse the repository at this point in the history
… using a hash.
  • Loading branch information
Aaron Hicks committed Feb 6, 2014
1 parent 3707f44 commit 8804f3f
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 13 deletions.
40 changes: 40 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,45 @@ for read from file
```

#### Logging to multiple remote servers

The `remote_servers` parameter can be used to set up logging to multiple remote servers which are supplied as a list of key value pairs for each remote. There is an example configuration provided in `./test/multiple_hosts.pp`

Using the `remote_servers` parameter over-rides the other remote sever parameters, and they will not be used in the client configuration file:
* `log_remote`
* `remote_type`
* `server`
* `port`

The following example sets up three remote logging hosts for the client:

```puppet
class{'rsyslog::client':
remote_servers => [
{
host => 'logs.example.org',
},
{
port => '55514',
},
{
host => 'logs.somewhere.com',
port => '555',
pattern => '*.log',
protocol => 'tcp',
format => 'RFC3164fmt',
},
]
}
```

Each host has the following parameters:
* *host*: Sets the address or hostname of the remote logging server. Defaults to `localhost`
* *port*: Sets the port the host is listening on. Defaults to `514`
* *pattern*: Sets the pattern to match logs. Defaults to `*.*`
* *protocol*: Sets the protocol. Only recognises TCP and UDP. Defaults to UDP
* *format*: Sets the log format. Defaults to not specifying log format, which defaults to the format set by `ActionFileDefaultTemplate` in the client configuration.

#### Logging to a MySQL or PostgreSQL database

Events can also be logged to a MySQL or PostgreSQL database. The database needs to be deployed separately, either locally or remotely. Schema are available from the `rsyslog` source:
Expand Down Expand Up @@ -91,6 +130,7 @@ The following lists all the class parameters this module accepts.
high_precision_timestamps true,false Whether or not to use high precision timestamps.
preserve_fqdn true,false Whether or not to preserve the fully qualified domain name when logging.
actionfiletemplate STRING If set this defines the `ActionFileDefaultTemplate` which sets the default logging format for remote and local logging..
remote_servers HASH Provides a hash of multiple remote logging servers. Check documentation.

RSYSLOG::CLIENT CLASS PARAMETERS VALUES DESCRIPTION
-------------------------------------------------------------------
Expand Down
10 changes: 6 additions & 4 deletions manifests/client.pp
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@
# === Parameters
#
# [*sample_parameter*]
# [*log_remote*]
# [*spool_size*]
# [*remote_type*]
# [*log_local*]
# [*log_auth_local*]
# [*custom_config*]
# [*custom_params*]
# [*log_remote*]
# [*server*]
# [*remote_type*]
# [*port*]
# [*remote_servers*]
# [*ssl_ca*]
# [*actionfiletemplate*]
#
Expand All @@ -33,9 +34,10 @@
$custom_params = undef,
$server = 'log',
$port = '514',
$remote_servers = false,
$ssl_ca = undef,
$actionfiletemplate = undef,
$preserve_fqdn = undef
$actionfiletemplate = false,
$preserve_fqdn = false
) inherits rsyslog {

$content_real = $custom_config ? {
Expand Down
51 changes: 42 additions & 9 deletions templates/client.conf.erb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,48 @@ $ActionFileDefaultTemplate <%= scope.lookupvar('rsyslog::client::actionfiletempl
#Using default format for default logging fromat:
$ActionFileDefaultTemplate RSYSLOG_TraditionalFileFormat
<% end -%>
<% if scope.lookupvar('rsyslog::client::remote_servers') and ! scope.lookupvar('rsyslog::client::remote_servers').empty? -%>
<% scope.lookupvar('rsyslog::client::remote_servers').flatten.compact.each do |server| -%>

This comment has been minimized.

Copy link
@cjeanneret

cjeanneret Feb 19, 2014

Hello,
It seems this prevent rsyslog to connect: declaring the remote server before the connection options 68 and previous ($ActionSendStreamDriverMode and $ActionSendStreamDriverAuthMode) disable the connection…
Tested on our infra (all rsyslog server were disconnected after this change), moving the remote_server to line 70 corrects the problem.

<% if server['pattern'] and server['pattern'] != ''-%>
<% pattern = server['pattern'] -%>
<% else -%>
<% pattern = '*.*' -%>
<% end -%>
<% if server['protocol'] == 'TCP' or server['protocol'] == 'tcp'-%>
<% protocol = '@@' -%>
<% protocol_type = 'TCP' -%>
<% else -%>
<% protocol = '@' -%>
<% protocol_type = 'UDP' -%>
<% end -%>
<% if server['host'] and server['host'] != ''-%>
<% host = server['host'] -%>
<% else -%>
<% host = 'localhost' -%>
<% end -%>
<% if server['port'] and server['port'] != ''-%>
<% port = server['port'] -%>
<% else -%>
<% port = '514' -%>
<% end -%>
<% if server['format'] -%>
<% format = ";#{server['format']}" -%>
<% format_type = server['format'] -%>
<% else -%>
<% format = '' -%>
<% format_type = 'the default' -%>
<% end -%>
# Sending logs that match <%= pattern %> to <%= host %> via <%= protocol_type %> on <%= port %> using <%=format_type %> format.
<%= pattern %> <%= protocol %><%= host %>:<%= port %><%= format %>
<% end -%>
<% elsif scope.lookupvar('rsyslog::client::log_remote') -%>
# Log to remote syslog server using <%= scope.lookupvar('rsyslog::client::remote_type') %>
<% if scope.lookupvar('rsyslog::client::remote_type') == 'tcp' -%>
*.* @@<%= scope.lookupvar('rsyslog::client::server') -%>:<%= scope.lookupvar('rsyslog::client::port') -%>;RSYSLOG_ForwardFormat
<% else -%>
*.* @<%= scope.lookupvar('rsyslog::client::server') -%>:<%= scope.lookupvar('rsyslog::client::port') -%>;RSYSLOG_ForwardFormat
<% end -%>
<% end -%>
<% if scope.lookupvar('rsyslog::client::log_auth_local') or scope.lookupvar('rsyslog::client::log_local') -%>
<% if scope.lookupvar('rsyslog::client::ssl') -%>
# Setup SSL connection.
Expand All @@ -26,15 +68,6 @@ $ActionSendStreamDriverMode 1
$ActionSendStreamDriverAuthMode anon
<% end -%>

<% if scope.lookupvar('rsyslog::client::log_remote') -%>
# Log to remote syslog server using <%= scope.lookupvar('rsyslog::client::remote_type') %>
<% if scope.lookupvar('rsyslog::client::remote_type') == 'tcp' -%>
*.* @@<%= scope.lookupvar('rsyslog::client::server') -%>:<%= scope.lookupvar('rsyslog::client::port') -%>;RSYSLOG_ForwardFormat
<% else -%>
*.* @<%= scope.lookupvar('rsyslog::client::server') -%>:<%= scope.lookupvar('rsyslog::client::port') -%>;RSYSLOG_ForwardFormat
<% end -%>
<% end -%>

# Logging locally.

<% if scope.lookupvar('rsyslog::log_style') == 'debian' -%>
Expand Down
17 changes: 17 additions & 0 deletions tests/multiple_hosts.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
class{'rsyslog::client':
remote_servers => [
{
host => 'logs.example.org',
},
{
port => '55514',
},
{
host => 'logs.somewhere.com',
port => '555',
pattern => '*.log',
protocol => 'tcp',
format => 'RFC3164fmt',
},
]
}

0 comments on commit 8804f3f

Please sign in to comment.