- 
                Notifications
    You must be signed in to change notification settings 
- Fork 205
Description
Right now we have the option to write to a single or multiple remote loggers. My own situation is slightly different, I want to write logs to a primary, but in the event that is offline, logs will be written to a secondary server. This action is supported by the $ActionExecOnlyWhenPreviousIsSuspended global configuration directive.
I've extended the current module code in my own environment by adding support for
alt_remote_servers => [
  {
    host     => 'logcentral-2',
    port     => '1514',
    protocol => 'relp',
  },
],
.......
class rsyslog::client (
$log_remote                = true,
$spool_size                = '1g',
$spool_timeoutenqueue      = false,
$remote_type               = 'tcp',
$remote_forward_format     = 'RSYSLOG_ForwardFormat',
$log_local                 = false,
$log_local_custom          = undef,
$log_auth_local            = false,
$listen_localhost          = false,
$split_config              = false,
$custom_config             = undef,
$custom_params             = undef,
$server                    = 'log',
$port                      = '514',
$remote_servers            = false,
$alt_remote_servers        = false,
$ssl_ca                    = undef,
$ssl_permitted_peer        = undef,
$ssl_auth_mode             = 'anon',
$log_templates             = false,
$log_filters               = false,
$actionfiletemplate        = false,
$high_precision_timestamps = false,
$rate_limit_burst          = undef,
$rate_limit_interval       = undef,
$imfiles                   = undef
) inherits rsyslog::params {
include ::rsyslog
if $custom_config {
$content_real = template($custom_config)
} elsif !$split_config {
$content_real = template(
"${module_name}/client/config.conf.erb",
"${module_name}/client/remote.conf.erb",
"${module_name}/client/alt_remote.conf.erb",
"${module_name}/client/local.conf.erb"
...and creating an alt_remote.conf template.
<% if scope.lookupvar('rsyslog::client::alt_remote_servers') -%>
$ActionExecOnlyWhenPreviousIsSuspended on
<% scope.lookupvar('rsyslog::client::alt_remote_servers').flatten.compact.each do |server| -%>
<% pattern = '&' -%>
<% if server['protocol'] == 'TCP' or server['protocol'] == 'tcp'-%>
<% protocol = '@@' -%>
<% protocol_type = 'TCP' -%>
<% else -%>
<% if server['protocol'] == 'RELP' or server['protocol'] == 'relp'-%>
<% protocol = ':omrelp:' -%>
<% protocol_type = 'RELP' -%>
<% else -%>
<% protocol = '@' -%>
<% protocol_type = 'UDP' -%>
<% end -%>
<% end -%>
<% if server['host'] and server['host'] != ''-%>
<% host = server['host'] -%>
<% else -%>
<% host = 'localhost' -%>
<% end -%>
<% if server['port'] and server['port'] != ''-%>
<% port = server['port'] -%>
<% else -%>
<% if server['protocol'] == 'RELP' or server['protocol'] == 'relp'-%>
<% port = '20514' -%>
<% else -%>
<% port = '514' -%>
<% end -%>
<% end -%>
<% if server['format'] -%>
<% format = ";#{server['format']}" -%>
<% format_type = server['format'] -%>
<% else -%>
<% format = '' -%>
<% format_type = 'the default' -%>
<% end -%>
<% if server['thendrop'] -%>
<% dropaction = '& ~' -%>
<% else -%>
<% dropaction = '' -%>
<% end -%>
Sending logs that match <%= pattern %> to <%= host %> via <%= protocol_type %> on <%= port %> using <%=format_type %> format.
<%= pattern %> <%= protocol %><%= host %>:<%= port %><%= format %>
<%= dropaction %>
<% end -%>
$ActionExecOnlyWhenPreviousIsSuspended off
<% end -%>