diff --git a/.fixtures.yml b/.fixtures.yml index e82d582..c116304 100644 --- a/.fixtures.yml +++ b/.fixtures.yml @@ -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}" diff --git a/Gemfile b/Gemfile index 706913c..001e824 100644 --- a/Gemfile +++ b/Gemfile @@ -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 @@ -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' diff --git a/README.md b/README.md index 9f11d77..a5d9d47 100644 --- a/README.md +++ b/README.md @@ -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 # diff --git a/manifests/fragment.pp b/manifests/fragment.pp index a71977d..489e26c 100644 --- a/manifests/fragment.pp +++ b/manifests/fragment.pp @@ -7,7 +7,7 @@ $content = undef, ) { - include rsyslog + include ::rsyslog validate_re($ensure, ['file','absent']) validate_string($content) diff --git a/manifests/init.pp b/manifests/init.pp index 84f10c4..3e98bf7 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -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 @@ -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': { @@ -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}") @@ -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' @@ -228,6 +238,7 @@ } 'Solaris': { $default_logrotate_present = false + $default_mod_imjournal = false case $::kernelrelease { '5.10', '5.11' : { $default_service_name = 'network/cswrsyslog' @@ -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.', @@ -448,7 +468,7 @@ # logging servers do not log elsewhere $remote_logging_real = false - include common + include ::common common::mkdir_p { $log_dir: } diff --git a/spec/classes/init_spec.rb b/spec/classes/init_spec.rb index 658d361..93af025 100644 --- a/spec/classes/init_spec.rb +++ b/spec/classes/init_spec.rb @@ -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 { @@ -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 @@ -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| diff --git a/templates/rsyslog.conf.erb b/templates/rsyslog.conf.erb index b6f2a36..02edd6e 100644 --- a/templates/rsyslog.conf.erb +++ b/templates/rsyslog.conf.erb @@ -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' -%> @@ -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" @@ -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 diff --git a/tests/init.pp b/tests/init.pp index 7fc50c8..f99a9ee 100644 --- a/tests/init.pp +++ b/tests/init.pp @@ -1 +1 @@ -include rsyslog +include ::rsyslog