Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

El7 journal #94

Merged
merged 7 commits into from
Jan 17, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .fixtures.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
fixtures:
repositories:
stdlib:
repo: 'git://github.com/puppetlabs/puppetlabs-stdlib.git'
repo: 'https://github.com/puppetlabs/puppetlabs-stdlib.git'
ref: '4.6.0'
sysklogd:
repo: 'git://github.com/ghoneycutt/puppet-module-sysklogd.git'
repo: 'https://github.com/ghoneycutt/puppet-module-sysklogd.git'
ref: 'v1.0.0'
common:
repo: 'git://github.com/ghoneycutt/puppet-module-common.git'
repo: 'https://github.com/ghoneycutt/puppet-module-common.git'
ref: 'v1.3.0'
symlinks:
rsyslog: "#{source_dir}"
16 changes: 14 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
source 'https://rubygems.org'
source ENV['GEM_SOURCE'] || 'https://rubygems.org'

if puppetversion = ENV['PUPPET_GEM_VERSION']
gem 'puppet', puppetversion, :require => false
Expand All @@ -8,9 +8,21 @@ end

gem 'metadata-json-lint'
gem 'puppetlabs_spec_helper', '>= 0.1.0'
gem 'puppet-lint', '>= 1.0.0'
gem 'facter', '>= 1.7.0'
gem 'rspec-puppet'
gem 'puppet-lint', :git => 'https://github.com/rodjek/puppet-lint.git'
gem 'puppet-lint-absolute_classname-check'
gem 'puppet-lint-alias-check'
gem 'puppet-lint-empty_string-check'
gem 'puppet-lint-file_ensure-check'
gem 'puppet-lint-file_source_rights-check'
gem 'puppet-lint-fileserver-check'
gem 'puppet-lint-leading_zero-check'
gem 'puppet-lint-spaceship_operator_without_tag-check'
gem 'puppet-lint-trailing_comma-check'
gem 'puppet-lint-undef_in_function-check'
gem 'puppet-lint-unquoted_string-check'
gem 'puppet-lint-variable_contains_upcase'

# rspec must be v2 for ruby 1.8.7
if RUBY_VERSION >= '1.8.7' and RUBY_VERSION < '1.9'
Expand Down
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,24 @@ The creation mode with which rsyslogd creates new directories.

- *Default*: '0700'

work_directory
--------------
The default location for work (spool) files.

- *Default*: '/var/lib/rsyslog'

journalstate_file
-----------------
The journal state file used by rsyslog.

- *Default*: 'imjournal.state'

mod_imjournal
-------------
Boolean for using the imjournal module. If set to 'USE_DEFAULTS', this will be chosen based on the platform.

- *Default*: 'USE_DEFAULTS'

===

# rsyslog::fragment define #
Expand Down
2 changes: 1 addition & 1 deletion manifests/fragment.pp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
$content = undef,
) {

include rsyslog
include ::rsyslog

validate_re($ensure, ['file','absent'])
validate_string($content)
Expand Down
46 changes: 33 additions & 13 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@
$umask = undef,
$file_create_mode = '0644',
$dir_create_mode = '0700',
$work_directory = '/var/lib/rsyslog',
$journalstate_file = 'imjournal.state',
$mod_imjournal = 'USE_DEFAULTS',
) {

# validation
Expand Down Expand Up @@ -168,6 +171,8 @@
validate_absolute_path($rsyslog_d_dir)
validate_re($daemon_ensure, '^(running|stopped)$', "daemon_ensure may be either 'running' or 'stopped' and is set to <${daemon_ensure}>.")
validate_absolute_path($kernel_target)
validate_absolute_path($work_directory)
validate_string($journalstate_file)

case $::osfamily {
'RedHat': {
Expand All @@ -179,16 +184,19 @@
$default_pid_file = '/var/run/rsyslogd.pid'
$sysconfig_erb = 'sysconfig.rhel5.erb'
$default_syslogd_options = '-m 0'
$default_mod_imjournal = false
}
/^6\.*/: {
$default_pid_file = '/var/run/syslogd.pid'
$sysconfig_erb = 'sysconfig.rhel6.erb'
$default_syslogd_options = ''
$default_syslogd_options = undef
$default_mod_imjournal = false
}
/^7\.*/: {
$default_pid_file = '/var/run/syslogd.pid'
$sysconfig_erb = 'sysconfig.rhel7.erb'
$default_syslogd_options = '-c 4'
$default_mod_imjournal = true
}
default: {
fail("rsyslog supports RedHat like systems with major release of 5, 6 and 7 and you have ${::operatingsystemrelease}")
Expand All @@ -198,19 +206,21 @@
require 'sysklogd'
}
'Debian': {
$default_logrotate_present = true
$default_service_name = 'rsyslog'
$default_sysconfig_path = '/etc/default/rsyslog'
$default_pid_file = '/var/run/rsyslogd.pid'
$sysconfig_erb = 'sysconfig.debian.erb'
$default_syslogd_options = '-c5'
$default_logrotate_present = true
$default_service_name = 'rsyslog'
$default_sysconfig_path = '/etc/default/rsyslog'
$default_pid_file = '/var/run/rsyslogd.pid'
$sysconfig_erb = 'sysconfig.debian.erb'
$default_syslogd_options = '-c5'
$default_mod_imjournal = false
}
'Suse' : {
$default_logrotate_present = true
$default_service_name = 'syslog'
$default_sysconfig_path = '/etc/sysconfig/syslog'
$default_syslogd_options = ''
$default_pid_file = '/var/run/rsyslogd.pid'
$default_logrotate_present = true
$default_service_name = 'syslog'
$default_sysconfig_path = '/etc/sysconfig/syslog'
$default_syslogd_options = undef
$default_pid_file = '/var/run/rsyslogd.pid'
$default_mod_imjournal = false
case $::operatingsystemrelease {
/^10\.*/ : {
$sysconfig_erb = 'sysconfig.suse10.erb'
Expand All @@ -228,6 +238,7 @@
}
'Solaris': {
$default_logrotate_present = false
$default_mod_imjournal = false
case $::kernelrelease {
'5.10', '5.11' : {
$default_service_name = 'network/cswrsyslog'
Expand Down Expand Up @@ -264,6 +275,15 @@
}
validate_absolute_path($pid_file_real)

if is_bool($mod_imjournal) == true {
$mod_imjournal_real = $mod_imjournal
} else {
$mod_imjournal_real = $mod_imjournal ? {
'USE_DEFAULTS' => $default_mod_imjournal,
default => str2bool($mod_imjournal)
}
}

$default_log_entries = [
'# Log all kernel messages to the console.',
'# Logging much else clutters up the screen.',
Expand Down Expand Up @@ -448,7 +468,7 @@
# logging servers do not log elsewhere
$remote_logging_real = false

include common
include ::common

common::mkdir_p { $log_dir: }

Expand Down
92 changes: 92 additions & 0 deletions spec/classes/init_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,40 @@
end
end

describe 'on a platform with mod_imjournal set to true' do
let :facts do
{
:osfamily => 'RedHat',
:operatingsystemrelease => '7.0',
:kernel => 'Linux',
:domain => 'defaultdomain',
:rsyslog_version => '5.8.10',
}
end

context 'work_directory specified' do
let :params do
{
:work_directory => '/tmp/foo',
:mod_imjournal => true,
}
end

it { should contain_file('rsyslog_config').with_content(/^\$WorkDirectory \/tmp\/foo$/) }
end

context 'journalstate_file specified' do
let :params do
{
:journalstate_file => 'my.journal',
:mod_imjournal => true,
}
end

it { should contain_file('rsyslog_config').with_content(/^\$IMJournalStateFile my.journal$/) }
end
end

describe 'rsyslog_package' do
context 'with default params' do
it {
Expand Down Expand Up @@ -1345,7 +1379,47 @@
end
end
end
end

describe 'module platform support' do
platforms = {
'redhat5' => { :kernel => 'Linux', :osfamily => 'RedHat', :release => '5', :mod_imjournal => false, },
'redhat6' => { :kernel => 'Linux', :osfamily => 'RedHat', :release => '6', :mod_imjournal => false, },
'redhat7' => { :kernel => 'Linux', :osfamily => 'RedHat', :release => '7', :mod_imjournal => true, },
'debian7' => { :kernel => 'Linux', :osfamily => 'Debian', :release => '7', :mod_imjournal => false, },
'suse10' => { :kernel => 'Linux', :osfamily => 'Suse', :release => '10', :mod_imjournal => false, },
'suse11' => { :kernel => 'Linux', :osfamily => 'Suse', :release => '11', :mod_imjournal => false, },
'suse12' => { :kernel => 'Linux', :osfamily => 'Suse', :release => '12', :mod_imjournal => false, },
'solaris10' => { :kernel => 'Solaris', :osfamily => 'Solaris', :release => '5.10', :mod_imjournal => false, },
'solaris11' => { :kernel => 'Solaris', :osfamily => 'Solaris', :release => '5.11', :mod_imjournal => false, },
}

platforms.sort.each do |k,v|
context "on osfamily #{v[:osfamily]} with major release #{v[:release]} support for mod_imjournal is #{v[:mod_imjournal]}" do
let :facts do
{
:kernel => v[:kernel],
:osfamily => v[:osfamily],
:operatingsystemrelease => v[:release],
:kernelrelease => v[:release],
:domain => 'defaultdomain',
:rsyslog_version => '5.8.10',
}
end

if v[:mod_imjournal] == true
it { should contain_file('rsyslog_config').with_content(/^\$ModLoad imjournal/) }
it { should contain_file('rsyslog_config').with_content(/^\$WorkDirectory \/var\/lib\/rsyslog$/) }
it { should contain_file('rsyslog_config').with_content(/^\$OmitLocalLogging on$/) }
it { should contain_file('rsyslog_config').with_content(/^\$IMJournalStateFile imjournal.state$/) }
else
it { should contain_file('rsyslog_config').without_content(/^\s*\$ModLoad\s+imjournal/) }
it { should contain_file('rsyslog_config').without_content(/^\s*\$WorkDirectory/) }
it { should contain_file('rsyslog_config').without_content(/^\s*\$OmitLocalLogging/) }
it { should contain_file('rsyslog_config').without_content(/^\s*\$IMJournalStateFile/) }
end
end
end
end

describe 'variable type and content validations' do
Expand All @@ -1366,12 +1440,30 @@
end

validations = {
'absolute_path' => {
:name => ['work_directory'],
:valid => ['/absolute/filepath','/absolute/directory/'],
:invalid => ['invalid',3,2.42,['array'],a={'ha'=>'sh'}],
:message => 'is not an absolute path',
},
'array/string' => {
:name => %w(log_server),
:valid => [%w(ar ray), 'string'],
:invalid => [{ 'ha' => 'sh' }, 3, 2.42, true, false],
:message => 'must be an array or string',
},
'boolean' => {
:name => ['mod_imjournal'],
:valid => [true,false,'true','false'],
:invalid => ['string',['array'],a={'ha'=>'sh'},3,2.42,nil],
:message => 'str2bool()',
},
'string' => {
:name => ['journalstate_file'],
:valid => ['valid'],
:invalid => [['array'],a={'ha'=>'sh'},true],
:message => 'is not a string',
},
}

validations.sort.each do |type, var|
Expand Down
18 changes: 18 additions & 0 deletions templates/rsyslog.conf.erb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@

$ModLoad imuxsock.so # provides support for local system logging (e.g. via logger command)
$ModLoad imklog.so # provides kernel logging support (previously done by rklogd)
<% if @mod_imjournal_real.to_s == 'true' -%>
$ModLoad imjournal # provides access to the systemd journal
<% end -%>
#$ModLoad immark.so # provides --MARK-- message capability

<% if @is_log_server_real.to_s == 'true' -%>
Expand All @@ -29,6 +32,11 @@ $template RemoteHost, "<%= @log_dir %>/<%= @remote_template %>"
<% end -%>
#### GLOBAL DIRECTIVES ####

<% if @mod_imjournal_real.to_s == 'true' -%>
# Where to place auxilliary files
$WorkDirectory <%= @work_directory %>
<% end -%>

# Use default timestamp format
<% if @rsyslog_conf_version_real == 2 -%>
$template TraditionalFormat,"%timegenerated% %HOSTNAME% %syslogtag%%msg:::drop-last-lf%0"
Expand All @@ -39,6 +47,16 @@ $ActionFileDefaultTemplate RSYSLOG_TraditionalFileFormat
# not useful and an extreme performance hit
#$ActionFileEnableSync on
<% end -%>

<% if @mod_imjournal_real.to_s == 'true' -%>
# Turn off message reception via local log socket;
# local messages are retrieved through imjournal now.
$OmitLocalLogging on

# File to store the position in the journal
$IMJournalStateFile <%= @journalstate_file %>
<% end -%>

<% if @use_tls_real.to_s == 'true' -%>

$DefaultNetstreamDriverCAFile <%= @ca_file %> # trust these CAs
Expand Down
2 changes: 1 addition & 1 deletion tests/init.pp
Original file line number Diff line number Diff line change
@@ -1 +1 @@
include rsyslog
include ::rsyslog