Add log_filters parameters to specify if/then conditions in RSysLog configs

This commit is contained in:
Maxim Dobryakov 2016-05-19 18:55:58 +03:00
Родитель 0aca4fa5d8
Коммит dff654e2b8
7 изменённых файлов: 74 добавлений и 0 удалений

Просмотреть файл

@ -50,6 +50,7 @@ or send some bitcoins to ```1Na3YFUmdxKxJLiuRXQYJU2kiNqA3KY2j9```
ssl_permitted_peer => undef,
ssl_auth_mode => 'anon',
log_templates => false,
log_filters => undef,
actionfiletemplate => false,
high_precision_timestamps => false,
rate_limit_burst => undef,
@ -160,6 +161,7 @@ Declare the following to configure the connection:
address => '*',
high_precision_timestamps => false,
log_templates => false,
log_filters => undef,
actionfiletemplate => false,
ssl_ca => undef,
ssl_cert => undef,
@ -195,6 +197,7 @@ The following lists all the class parameters this module accepts.
address STRING The IP address to bind to. Applies to UDP listener only. Defaults to '*'.
log_templates HASH Provides a has defining custom logging templates using the `$template` configuration parameter.
log_filters HASH Provides a has defining custom logging filters using the `if/then` configurations parameter.
actionfiletemplate STRING If set this defines the `ActionFileDefaultTemplate` which sets the default logging format for remote and local logging.
high_precision_timestamps true,false Whether or not to use high precision timestamps.
ssl_ca STRING Path to SSL CA certificate
@ -220,6 +223,7 @@ The following lists all the class parameters this module accepts.
ssl_permitted_peer STRING List of permitted peers. Defaults to undef.
ssl_auth_mode STRING SSL auth mode. Defaults to anon.
log_templates HASH Provides a has defining custom logging templates using the `$template` configuration parameter.
log_filters HASH Provides a has defining custom logging filters using the `if/then` configurations parameter.
actionfiletemplate STRING If set this defines the `ActionFileDefaultTemplate` which sets the default logging format for remote and local logging.
high_precision_timestamps true,false Whether or not to use high precision timestamps.
rate_limit_burst INTEGER Specifies the number of messages in $rate_limit_interval before limiting begins. Defaults to undef.

Просмотреть файл

@ -22,6 +22,7 @@
# [*ssl_permitted_peer*]
# [*ssl_
# [*log_templates*]
# [*log_filters*]
# [*actionfiletemplate*]
# [*rate_limit_burst*]
# [*rate_limit_interval*]
@ -52,6 +53,7 @@ class rsyslog::client (
$ssl_permitted_peer = undef,
$ssl_auth_mode = 'anon',
$log_templates = false,
$log_filters = undef,
$actionfiletemplate = false,
$high_precision_timestamps = false,
$rate_limit_burst = undef,

Просмотреть файл

@ -18,6 +18,7 @@
# [*ssl_cert*]
# [*ssl_key*]
# [*log_templates*]
# [*log_filters*]
# [*actionfiletemplate*]
# [*rotate*]
#
@ -51,6 +52,7 @@ class rsyslog::server (
$ssl_cert = undef,
$ssl_key = undef,
$log_templates = false,
$log_filters = undef,
$actionfiletemplate = false,
$rotate = undef
) inherits rsyslog {

Просмотреть файл

@ -46,6 +46,15 @@ describe 'rsyslog::client', :type => :class do
should contain_file('/etc/rsyslog.d/99_client_local.conf').with_ensure('absent')
end
end
context 'log_filters (osfamily = RedHat)' do
let(:title) { 'log_filters_check' }
let(:params) { {'log_filters' => [{'expession' => '$msg contains \'error0\'', 'action' => '/var/log/err.log'}] } }
it 'should compile' do
should contain_file('/etc/rsyslog.d/client.conf').with_content(%r{if \$msg contains 'error0' then /var/log/err.log})
end
end
end
context "osfamily = Debian" do
@ -85,6 +94,15 @@ describe 'rsyslog::client', :type => :class do
end
end
context 'log_filters (osfamily = RedHat)' do
let(:title) { 'log_filters_check' }
let(:params) { {'log_filters' => [{'expession' => '$msg contains \'error0\'', 'action' => '/var/log/err.log'}] } }
it 'should compile' do
should contain_file('/etc/rsyslog.d/client.conf').with_content(%r{if \$msg contains 'error0' then /var/log/err.log})
end
end
context "auth_mode (osfamily = Debian)" do
let(:title) { 'rsyslog-client-auth_mode' }
@ -234,6 +252,15 @@ describe 'rsyslog::client', :type => :class do
should contain_file('/etc/rsyslog.d/99_client_local.conf').with_ensure('absent')
end
end
context 'log_filters (osfamily = RedHat)' do
let(:title) { 'log_filters_check' }
let(:params) { {'log_filters' => [{'expession' => '$msg contains \'error0\'', 'action' => '/var/log/err.log'}] } }
it 'should compile' do
should contain_file('/etc/rsyslog.d/client.conf').with_content(%r{if \$msg contains 'error0' then /var/log/err.log})
end
end
end
context "osfamily = Debian" do
@ -272,6 +299,15 @@ describe 'rsyslog::client', :type => :class do
should contain_file('/etc/rsyslog.d/99_client_local.conf').with_ensure('absent')
end
end
context 'log_filters (osfamily = RedHat)' do
let(:title) { 'log_filters_check' }
let(:params) { {'log_filters' => [{'expession' => '$msg contains \'error0\'', 'action' => '/var/log/err.log'}] } }
it 'should compile' do
should contain_file('/etc/rsyslog.d/client.conf').with_content(%r{if \$msg contains 'error0' then /var/log/err.log})
end
end
end
context "osfamily = FreeBSD" do

Просмотреть файл

@ -48,6 +48,14 @@ describe 'rsyslog::server', :type => :class do
end
end
context "log_filters (osfamily = #{osfamily})" do
let(:title) { 'log_filters_check' }
let(:params) { {'log_filters' => [{'expession' => '$msg contains \'error0\'', 'action' => '/var/log/err.log'}] } }
it 'should compile' do
should contain_file('/etc/rsyslog.d/server.conf').with_content(%r{if \$msg contains 'error0' then /var/log/err.log})
end
end
end
end
@ -138,6 +146,14 @@ describe 'rsyslog::server', :type => :class do
end
end
context "log_filters (osfamily = #{osfamily})" do
let(:title) { 'log_filters_check' }
let(:params) { {'log_filters' => [{'expession' => '$msg contains \'error0\'', 'action' => '/var/log/err.log'}] } }
it 'should compile' do
should contain_file('/etc/rsyslog.d/server.conf').with_content(%r{if \$msg contains 'error0' then /var/log/err.log})
end
end
end
end

Просмотреть файл

@ -15,6 +15,13 @@ $ActionResumeRetryCount -1 # infinety retries if host is down
$template <%= log_template['name'] %>,"<%= log_template['template'] %>"
<% end -%>
<% end -%>
<% if scope.lookupvar('rsyslog::client::log_filters') -%>
# Define custom if/then log conditions
<% scope.lookupvar('rsyslog::client::log_filters').each do |log_filter| -%>
if <%= log_filter['expession'] %> then <%= log_filter['action'] %>
<% end -%>
<% end -%>
<% if scope.lookupvar('rsyslog::client::actionfiletemplate') -%>
# Using specified format for default logging format:

Просмотреть файл

@ -22,6 +22,13 @@ $ModLoad imrelp
$template <%= log_template['name'] %>,"<%= log_template['template'] %>"
<% end -%>
<% end -%>
<% if scope.lookupvar('rsyslog::server::log_filters') -%>
# Define custom if/then log conditions
<% scope.lookupvar('rsyslog::server::log_filters').each do |log_filter| -%>
if <%= log_filter['expession'] %> then <%= log_filter['action'] %>
<% end -%>
<% end -%>
<% if scope.lookupvar('rsyslog::server::actionfiletemplate') -%>
# Using specified format for default logging format: