diff --git a/README.md b/README.md index 40021bf..975fbc9 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,10 @@ It is tested on the following platforms. * Solaris 10 * Solaris 11 * Ubuntu 12 +* Ubuntu 14.04 +* Ubuntu 16.04 +* Ubuntu 18.04 +* Ubuntu 20.04 === diff --git a/manifests/init.pp b/manifests/init.pp index 8162566..38fbd5c 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -116,7 +116,10 @@ $default_nrpe_package = 'nagios-nrpe-server' $default_nrpe_package_adminfile = undef $default_nrpe_package_source = undef - $default_nagios_plugins_package = 'nagios-plugins-basic' + $default_nagios_plugins_package = (versioncmp($facts[os][release][full], '20.04') < 0) ? { + true => 'nagios-plugins-basic', + default => 'monitoring-plugins-basic', + } $default_nagios_plugins_package_adminfile = undef $default_nagios_plugins_package_source = undef $default_nrpe_config = '/etc/nagios/nrpe.cfg' diff --git a/metadata.json b/metadata.json index 1d45dc0..66d8c59 100644 --- a/metadata.json +++ b/metadata.json @@ -62,7 +62,11 @@ { "operatingsystem": "Ubuntu", "operatingsystemrelease": [ - "12.04" + "12.04", + "14.04", + "16.04", + "18.04", + "20.04" ] } ] diff --git a/spec/classes/init_spec.rb b/spec/classes/init_spec.rb index 22ab533..ddb5461 100644 --- a/spec/classes/init_spec.rb +++ b/spec/classes/init_spec.rb @@ -333,7 +333,7 @@ } end - context 'with default options on Ubuntu' do + context 'with default options on Ubuntu 12' do let(:facts) do { :osfamily => 'Debian', :lsbdistid => 'Ubuntu', @@ -412,29 +412,11 @@ } end - context 'with nrpe_config set to a non absolute path' do - let(:params) { { :nrpe_config => 'invalid/path' } } - - it 'should fail' do - expect { - should contain_class('nrpe') - }.to raise_error(Puppet::Error) - end - end - - context 'with nrpe_config_mode set to an invalid value' do - let(:params) { { :nrpe_config_mode => '666' } } - - it 'should fail' do - expect { - should contain_class('nrpe') - }.to raise_error(Puppet::Error,/nrpe::nrpe_config_mode must be a four digit octal mode\. Detected value is <666>\./) - end - end - - context 'with default options on Solaris' do + context 'with default options on Ubuntu 14.04' do let(:facts) do - { :osfamily => 'Solaris', + { :osfamily => 'Debian', + :lsbdistid => 'Ubuntu', + :lsbmajdistrelease => '14.04', } end @@ -443,7 +425,7 @@ it { should contain_class('nrpe') } it { - should contain_package('nrpe').with({ + should contain_package('nagios-nrpe-server').with({ 'ensure' => 'present', 'adminfile' => nil, 'source' => nil, @@ -451,7 +433,7 @@ } it { - should contain_package('nagios-plugins').with({ + should contain_package('nagios-plugins-basic').with({ 'ensure' => 'present', 'adminfile' => nil, 'source' => nil, @@ -462,11 +444,11 @@ it { should contain_file('nrpe_config').with({ 'ensure' => 'file', - 'path' => '/usr/local/nagios/etc/nrpe.cfg', + 'path' => '/etc/nagios/nrpe.cfg', 'owner' => 'root', 'group' => 'root', 'mode' => '0644', - 'require' => 'Package[nrpe]', + 'require' => 'Package[nagios-nrpe-server]', }) } @@ -484,17 +466,17 @@ it { should contain_file('nrpe_config').with_content(/^command_timeout=60$/) } it { should contain_file('nrpe_config').with_content(/^connection_timeout=300$/) } it { should contain_file('nrpe_config').with_content(/^allow_weak_random_seed=0$/) } - it { should contain_file('nrpe_config').with_content(/^include_dir=\/usr\/local\/nagios\/etc\/nrpe.d$/) } + it { should contain_file('nrpe_config').with_content(/^include_dir=\/etc\/nagios\/nrpe.d$/) } it { should_not contain_file('nrpe_config').with_content(/^command\[$/) } it { should contain_file('nrpe_config_dot_d').with({ 'ensure' => 'directory', - 'path' => '/usr/local/nagios/etc/nrpe.d', + 'path' => '/etc/nagios/nrpe.d', 'owner' => 'root', 'group' => 'root', 'mode' => '0644', - 'require' => 'Package[nrpe]', + 'require' => 'Package[nagios-nrpe-server]', 'notify' => 'Service[nrpe_service]', }) } @@ -502,210 +484,847 @@ it { should contain_service('nrpe_service').with({ 'ensure' => 'running', - 'name' => 'nrpe', + 'name' => 'nagios-nrpe-server', 'enable' => true, 'subscribe' => 'File[nrpe_config]', }) } end - context 'with libexecdir set to a non absolute path' do - let(:params) { { :libexecdir => 'invalid/path' } } - - it 'should fail' do - expect { - should contain_class('nrpe') - }.to raise_error(Puppet::Error) + context 'with default options on Ubuntu 16.04' do + let(:facts) do + { :osfamily => 'Debian', + :lsbdistid => 'Ubuntu', + :lsbmajdistrelease => '16.04', + } end - end - context 'with server_port set to an invalid setting (non-digit)' do - let(:params) { { :server_port => 'not_a_port' } } + it { should compile.with_all_deps } - it 'should fail' do - expect { - should contain_class('nrpe') - }.to raise_error(Puppet::Error,/nrpe::server_port must be a valid port number between 0 and 65535, inclusive\. Detected value is \./) - end - end + it { should contain_class('nrpe') } - context 'with server_port set to a valid digit, but invalid port number (above 65535)' do - let(:params) { { :server_port => 1000000 } } + it { + should contain_package('nagios-nrpe-server').with({ + 'ensure' => 'present', + 'adminfile' => nil, + 'source' => nil, + }) + } - it 'should fail' do - expect { - should contain_class('nrpe') - }.to raise_error(Puppet::Error,/nrpe::server_port must be a valid port number between 0 and 65535, inclusive\. Detected value is <1000000>\./) - end - end + it { + should contain_package('nagios-plugins-basic').with({ + 'ensure' => 'present', + 'adminfile' => nil, + 'source' => nil, + 'before' => 'Service[nrpe_service]', + }) + } - context 'with server_port set to a valid digit, but invalid port number (negative)' do - let(:params) { { :server_port => -23 } } + it { + should contain_file('nrpe_config').with({ + 'ensure' => 'file', + 'path' => '/etc/nagios/nrpe.cfg', + 'owner' => 'root', + 'group' => 'root', + 'mode' => '0644', + 'require' => 'Package[nagios-nrpe-server]', + }) + } - it 'should fail' do - expect { - should contain_class('nrpe') - }.to raise_error(Puppet::Error,/nrpe::server_port must be a valid port number between 0 and 65535, inclusive\. Detected value is <-23>\./) - end - end + it { should contain_file('nrpe_config').with_content(/^log_facility=daemon$/) } + it { should contain_file('nrpe_config').with_content(/^pid_file=\/var\/run\/nagios\/nrpe.pid$/) } + it { should contain_file('nrpe_config').with_content(/^server_port=5666$/) } + it { should_not contain_file('nrpe_config').with_content(/^server_address=127.0.0.1$/) } + it { should contain_file('nrpe_config').with_content(/^nrpe_user=nagios$/) } + it { should contain_file('nrpe_config').with_content(/^nrpe_group=nagios$/) } + it { should contain_file('nrpe_config').with_content(/^allowed_hosts=127.0.0.1$/) } + it { should contain_file('nrpe_config').with_content(/^dont_blame_nrpe=0$/) } + it { should contain_file('nrpe_config').with_content(/^allow_bash_command_substitution=0$/) } + it { should_not contain_file('nrpe_config').with_content(/^command_prefix=\/usr\/bin\/sudo$/) } + it { should contain_file('nrpe_config').with_content(/^debug=0$/) } + it { should contain_file('nrpe_config').with_content(/^command_timeout=60$/) } + it { should contain_file('nrpe_config').with_content(/^connection_timeout=300$/) } + it { should contain_file('nrpe_config').with_content(/^allow_weak_random_seed=0$/) } + it { should contain_file('nrpe_config').with_content(/^include_dir=\/etc\/nagios\/nrpe.d$/) } + it { should_not contain_file('nrpe_config').with_content(/^command\[$/) } - context 'with server_port set to a valid port, but stringified' do - let(:params) { { :server_port => '1234' } } + it { + should contain_file('nrpe_config_dot_d').with({ + 'ensure' => 'directory', + 'path' => '/etc/nagios/nrpe.d', + 'owner' => 'root', + 'group' => 'root', + 'mode' => '0644', + 'require' => 'Package[nagios-nrpe-server]', + 'notify' => 'Service[nrpe_service]', + }) + } - it { should contain_file('nrpe_config').with_content(/^server_port=1234$/) } + it { + should contain_service('nrpe_service').with({ + 'ensure' => 'running', + 'name' => 'nagios-nrpe-server', + 'enable' => true, + 'subscribe' => 'File[nrpe_config]', + }) + } end - context 'with server_address_enable set to true' do - let(:params) { { :server_address_enable => true } } + context 'with default options on Ubuntu 18.04' do + let(:facts) do + { :osfamily => 'Debian', + :lsbdistid => 'Ubuntu', + :lsbmajdistrelease => '18.04', + } + end it { should compile.with_all_deps } - it { should contain_file('nrpe_config').with_content(/^server_address=127.0.0.1$/) } - end + it { should contain_class('nrpe') } - context 'with server_address_enable set to to stringified \'true\'' do - let(:params) { { :server_address_enable => 'true' } } + it { + should contain_package('nagios-nrpe-server').with({ + 'ensure' => 'present', + 'adminfile' => nil, + 'source' => nil, + }) + } - it { should compile.with_all_deps } + it { + should contain_package('nagios-plugins-basic').with({ + 'ensure' => 'present', + 'adminfile' => nil, + 'source' => nil, + 'before' => 'Service[nrpe_service]', + }) + } - it { should contain_file('nrpe_config').with_content(/^server_address=127.0.0.1$/) } - end + it { + should contain_file('nrpe_config').with({ + 'ensure' => 'file', + 'path' => '/etc/nagios/nrpe.cfg', + 'owner' => 'root', + 'group' => 'root', + 'mode' => '0644', + 'require' => 'Package[nagios-nrpe-server]', + }) + } - context 'with multiple entries for allowed_hosts' do - let(:params) { { :allowed_hosts => ['127.0.0.1', 'poller.example.com'] } } + it { should contain_file('nrpe_config').with_content(/^log_facility=daemon$/) } + it { should contain_file('nrpe_config').with_content(/^pid_file=\/var\/run\/nagios\/nrpe.pid$/) } + it { should contain_file('nrpe_config').with_content(/^server_port=5666$/) } + it { should_not contain_file('nrpe_config').with_content(/^server_address=127.0.0.1$/) } + it { should contain_file('nrpe_config').with_content(/^nrpe_user=nagios$/) } + it { should contain_file('nrpe_config').with_content(/^nrpe_group=nagios$/) } + it { should contain_file('nrpe_config').with_content(/^allowed_hosts=127.0.0.1$/) } + it { should contain_file('nrpe_config').with_content(/^dont_blame_nrpe=0$/) } + it { should contain_file('nrpe_config').with_content(/^allow_bash_command_substitution=0$/) } + it { should_not contain_file('nrpe_config').with_content(/^command_prefix=\/usr\/bin\/sudo$/) } + it { should contain_file('nrpe_config').with_content(/^debug=0$/) } + it { should contain_file('nrpe_config').with_content(/^command_timeout=60$/) } + it { should contain_file('nrpe_config').with_content(/^connection_timeout=300$/) } + it { should contain_file('nrpe_config').with_content(/^allow_weak_random_seed=0$/) } + it { should contain_file('nrpe_config').with_content(/^include_dir=\/etc\/nagios\/nrpe.d$/) } + it { should_not contain_file('nrpe_config').with_content(/^command\[$/) } - it { should compile.with_all_deps } + it { + should contain_file('nrpe_config_dot_d').with({ + 'ensure' => 'directory', + 'path' => '/etc/nagios/nrpe.d', + 'owner' => 'root', + 'group' => 'root', + 'mode' => '0644', + 'require' => 'Package[nagios-nrpe-server]', + 'notify' => 'Service[nrpe_service]', + }) + } - it { should contain_file('nrpe_config').with_content(/^allowed_hosts=127.0.0.1,poller.example.com$/) } + it { + should contain_service('nrpe_service').with({ + 'ensure' => 'running', + 'name' => 'nagios-nrpe-server', + 'enable' => true, + 'subscribe' => 'File[nrpe_config]', + }) + } end - context 'with allowed_hosts set to an invalid type (non-array)' do - let(:params) { { :allowed_hosts => 'not_an_array' } } - - it 'should fail' do - expect { - should contain_class('nrpe') - }.to raise_error(Puppet::Error) + context 'with default options on Ubuntu 20.04' do + let(:facts) do + { :osfamily => 'Debian', + :lsbdistid => 'Ubuntu', + :lsbmajdistrelease => '20.04', + } end - end - context 'with dont_blame_nrpe set to invalid value' do - let(:params) { { :dont_blame_nrpe => '2' } } + it { should compile.with_all_deps } - it 'should fail' do - expect { - should contain_class('nrpe') - }.to raise_error(Puppet::Error,/nrpe::dont_blame_nrpe must be 0 or 1\. Detected value is <2>\./) - end - end + it { should contain_class('nrpe') } - context 'with allow_bash_command_substitution set to invalid value' do - let(:params) { { :allow_bash_command_substitution => '2' } } + it { + should contain_package('nagios-nrpe-server').with({ + 'ensure' => 'present', + 'adminfile' => nil, + 'source' => nil, + }) + } - it 'should fail' do - expect { - should contain_class('nrpe') - }.to raise_error(Puppet::Error,/nrpe::allow_bash_command_substitution must be 0 or 1\. Detected value is <2>\./) + it { + should contain_package('monitoring-plugins-basic').with({ + 'ensure' => 'present', + 'adminfile' => nil, + 'source' => nil, + 'before' => 'Service[nrpe_service]', + }) + } + + it { + should contain_file('nrpe_config').with({ + 'ensure' => 'file', + 'path' => '/etc/nagios/nrpe.cfg', + 'owner' => 'root', + 'group' => 'root', + 'mode' => '0644', + 'require' => 'Package[nagios-nrpe-server]', + }) + } + + it { should contain_file('nrpe_config').with_content(/^log_facility=daemon$/) } + it { should contain_file('nrpe_config').with_content(/^pid_file=\/var\/run\/nagios\/nrpe.pid$/) } + it { should contain_file('nrpe_config').with_content(/^server_port=5666$/) } + it { should_not contain_file('nrpe_config').with_content(/^server_address=127.0.0.1$/) } + it { should contain_file('nrpe_config').with_content(/^nrpe_user=nagios$/) } + it { should contain_file('nrpe_config').with_content(/^nrpe_group=nagios$/) } + it { should contain_file('nrpe_config').with_content(/^allowed_hosts=127.0.0.1$/) } + it { should contain_file('nrpe_config').with_content(/^dont_blame_nrpe=0$/) } + it { should contain_file('nrpe_config').with_content(/^allow_bash_command_substitution=0$/) } + it { should_not contain_file('nrpe_config').with_content(/^command_prefix=\/usr\/bin\/sudo$/) } + it { should contain_file('nrpe_config').with_content(/^debug=0$/) } + it { should contain_file('nrpe_config').with_content(/^command_timeout=60$/) } + it { should contain_file('nrpe_config').with_content(/^connection_timeout=300$/) } + it { should contain_file('nrpe_config').with_content(/^allow_weak_random_seed=0$/) } + it { should contain_file('nrpe_config').with_content(/^include_dir=\/etc\/nagios\/nrpe.d$/) } + it { should_not contain_file('nrpe_config').with_content(/^command\[$/) } + + it { + should contain_file('nrpe_config_dot_d').with({ + 'ensure' => 'directory', + 'path' => '/etc/nagios/nrpe.d', + 'owner' => 'root', + 'group' => 'root', + 'mode' => '0644', + 'require' => 'Package[nagios-nrpe-server]', + 'notify' => 'Service[nrpe_service]', + }) + } + + it { + should contain_service('nrpe_service').with({ + 'ensure' => 'running', + 'name' => 'nagios-nrpe-server', + 'enable' => true, + 'subscribe' => 'File[nrpe_config]', + }) + } + end + + context 'with nrpe_config set to a non absolute path' do + let(:params) { { :nrpe_config => 'invalid/path' } } + + it 'should fail' do + expect { + should contain_class('nrpe') + }.to raise_error(Puppet::Error) + end + end + + context 'with nrpe_config_mode set to an invalid value' do + let(:params) { { :nrpe_config_mode => '666' } } + + it 'should fail' do + expect { + should contain_class('nrpe') + }.to raise_error(Puppet::Error,/nrpe::nrpe_config_mode must be a four digit octal mode\. Detected value is <666>\./) + end + end + + context 'with default options on Solaris' do + let(:facts) do + { :osfamily => 'Solaris', + } + end + + it { should compile.with_all_deps } + + it { should contain_class('nrpe') } + + it { + should contain_package('nrpe').with({ + 'ensure' => 'present', + 'adminfile' => nil, + 'source' => nil, + }) + } + + it { + should contain_package('nagios-plugins').with({ + 'ensure' => 'present', + 'adminfile' => nil, + 'source' => nil, + 'before' => 'Service[nrpe_service]', + }) + } + + it { + should contain_file('nrpe_config').with({ + 'ensure' => 'file', + 'path' => '/usr/local/nagios/etc/nrpe.cfg', + 'owner' => 'root', + 'group' => 'root', + 'mode' => '0644', + 'require' => 'Package[nrpe]', + }) + } + + it { should contain_file('nrpe_config').with_content(/^log_facility=daemon$/) } + it { should contain_file('nrpe_config').with_content(/^pid_file=\/var\/run\/nagios\/nrpe.pid$/) } + it { should contain_file('nrpe_config').with_content(/^server_port=5666$/) } + it { should_not contain_file('nrpe_config').with_content(/^server_address=127.0.0.1$/) } + it { should contain_file('nrpe_config').with_content(/^nrpe_user=nagios$/) } + it { should contain_file('nrpe_config').with_content(/^nrpe_group=nagios$/) } + it { should contain_file('nrpe_config').with_content(/^allowed_hosts=127.0.0.1$/) } + it { should contain_file('nrpe_config').with_content(/^dont_blame_nrpe=0$/) } + it { should contain_file('nrpe_config').with_content(/^allow_bash_command_substitution=0$/) } + it { should_not contain_file('nrpe_config').with_content(/^command_prefix=\/usr\/bin\/sudo$/) } + it { should contain_file('nrpe_config').with_content(/^debug=0$/) } + it { should contain_file('nrpe_config').with_content(/^command_timeout=60$/) } + it { should contain_file('nrpe_config').with_content(/^connection_timeout=300$/) } + it { should contain_file('nrpe_config').with_content(/^allow_weak_random_seed=0$/) } + it { should contain_file('nrpe_config').with_content(/^include_dir=\/usr\/local\/nagios\/etc\/nrpe.d$/) } + it { should_not contain_file('nrpe_config').with_content(/^command\[$/) } + + it { + should contain_file('nrpe_config_dot_d').with({ + 'ensure' => 'directory', + 'path' => '/usr/local/nagios/etc/nrpe.d', + 'owner' => 'root', + 'group' => 'root', + 'mode' => '0644', + 'require' => 'Package[nrpe]', + 'notify' => 'Service[nrpe_service]', + }) + } + + it { + should contain_service('nrpe_service').with({ + 'ensure' => 'running', + 'name' => 'nrpe', + 'enable' => true, + 'subscribe' => 'File[nrpe_config]', + }) + } + end + + context 'with libexecdir set to a non absolute path' do + let(:params) { { :libexecdir => 'invalid/path' } } + + it 'should fail' do + expect { + should contain_class('nrpe') + }.to raise_error(Puppet::Error) + end + end + + context 'with server_port set to an invalid setting (non-digit)' do + let(:params) { { :server_port => 'not_a_port' } } + + it 'should fail' do + expect { + should contain_class('nrpe') + }.to raise_error(Puppet::Error,/nrpe::server_port must be a valid port number between 0 and 65535, inclusive\. Detected value is \./) + end + end + + context 'with server_port set to a valid digit, but invalid port number (above 65535)' do + let(:params) { { :server_port => 1000000 } } + + it 'should fail' do + expect { + should contain_class('nrpe') + }.to raise_error(Puppet::Error,/nrpe::server_port must be a valid port number between 0 and 65535, inclusive\. Detected value is <1000000>\./) + end + end + + context 'with server_port set to a valid digit, but invalid port number (negative)' do + let(:params) { { :server_port => -23 } } + + it 'should fail' do + expect { + should contain_class('nrpe') + }.to raise_error(Puppet::Error,/nrpe::server_port must be a valid port number between 0 and 65535, inclusive\. Detected value is <-23>\./) + end + end + + context 'with server_port set to a valid port, but stringified' do + let(:params) { { :server_port => '1234' } } + + it { should contain_file('nrpe_config').with_content(/^server_port=1234$/) } + end + + context 'with server_address_enable set to true' do + let(:params) { { :server_address_enable => true } } + + it { should compile.with_all_deps } + + it { should contain_file('nrpe_config').with_content(/^server_address=127.0.0.1$/) } + end + + context 'with server_address_enable set to to stringified \'true\'' do + let(:params) { { :server_address_enable => 'true' } } + + it { should compile.with_all_deps } + + it { should contain_file('nrpe_config').with_content(/^server_address=127.0.0.1$/) } + end + + context 'with multiple entries for allowed_hosts' do + let(:params) { { :allowed_hosts => ['127.0.0.1', 'poller.example.com'] } } + + it { should compile.with_all_deps } + + it { should contain_file('nrpe_config').with_content(/^allowed_hosts=127.0.0.1,poller.example.com$/) } + end + + context 'with allowed_hosts set to an invalid type (non-array)' do + let(:params) { { :allowed_hosts => 'not_an_array' } } + + it 'should fail' do + expect { + should contain_class('nrpe') + }.to raise_error(Puppet::Error) + end + end + + context 'with dont_blame_nrpe set to invalid value' do + let(:params) { { :dont_blame_nrpe => '2' } } + + it 'should fail' do + expect { + should contain_class('nrpe') + }.to raise_error(Puppet::Error,/nrpe::dont_blame_nrpe must be 0 or 1\. Detected value is <2>\./) + end + end + + context 'with allow_bash_command_substitution set to invalid value' do + let(:params) { { :allow_bash_command_substitution => '2' } } + + it 'should fail' do + expect { + should contain_class('nrpe') + }.to raise_error(Puppet::Error,/nrpe::allow_bash_command_substitution must be 0 or 1\. Detected value is <2>\./) + end + end + + context 'with command_prefix_enable set to true' do + let(:params) { { :command_prefix_enable => true } } + + it { should compile.with_all_deps } + + it { should contain_file('nrpe_config').with_content(/^command_prefix=\/usr\/bin\/sudo$/) } + end + + context 'with command_prefix_enable set to to stringified \'true\'' do + let(:params) { { :command_prefix_enable => 'true' } } + + it { should compile.with_all_deps } + + it { should contain_file('nrpe_config').with_content(/^command_prefix=\/usr\/bin\/sudo$/) } + end + + context 'with command_prefix set to a non absolute path' do + let(:params) { { :command_prefix => 'invalid/path' } } + + it 'should fail' do + expect { + should contain_class('nrpe') + }.to raise_error(Puppet::Error) + end + end + + context 'with debug set to invalid value' do + let(:params) { { :debug => '2' } } + + it 'should fail' do + expect { + should contain_class('nrpe') + }.to raise_error(Puppet::Error,/nrpe::debug must be 0 or 1\. Detected value is <2>\./) + end + end + + context 'with command_timeout set to an invalid setting' do + let(:params) { { :command_timeout => '-1' } } + + it 'should fail' do + expect { + should contain_class('nrpe') + }.to raise_error(Puppet::Error,/nrpe::command_timeout must be a postive integer\. Detected value is <-1>\./) + end + end + + context 'with connection_timeout set to an invalid setting' do + let(:params) { { :connection_timeout => '-1' } } + + it 'should fail' do + expect { + should contain_class('nrpe') + }.to raise_error(Puppet::Error,/nrpe::connection_timeout must be a postive integer\. Detected value is <-1>\./) + end + end + + context 'with allow_weak_random_seed set to invalid value' do + let(:params) { { :allow_weak_random_seed => '2' } } + + it 'should fail' do + expect { + should contain_class('nrpe') + }.to raise_error(Puppet::Error,/nrpe::allow_weak_random_seed must be 0 or 1\. Detected value is <2>\./) + end + end + + context 'with include_dir set to invalid value' do + let(:params) { { :include_dir => 'invalid/path' } } + + it 'should fail' do + expect { + should contain_class('nrpe') + }.to raise_error(Puppet::Error) + end + end + + context 'with service_ensure set to invalid value' do + let(:params) { { :service_ensure => 'present' } } + + it 'should fail' do + expect { + should contain_class('nrpe') + }.to raise_error(Puppet::Error,/nrpe::service_ensure must be \'running\' or \'stopped\'\. Detected value is \./) + end + end + + context 'with service_enable set to invalid value' do + let(:params) { { :service_enable => 'invalid' } } + + it 'should fail' do + expect { + should contain_class('nrpe') + }.to raise_error(Puppet::Error) + end + end + + context 'with plugins specified as a hash on 32 bit EL 6' do + let(:params) { + { + :plugins => { + 'check_root_partition' => { + 'plugin' => 'check_disk', + 'libexecdir' => '/usr/lib/nagios/plugins', + 'args' => '-w 20% -c 10% -p /', + }, + 'check_load' => { + 'args' => '-w 10,8,8 -c 12,10,9', + }, + 'check_me_out' => { + 'ensure' => 'absent', + }, + } + } + } + let(:facts) do + { :architecture => 'i386', + :osfamily => 'RedHat', + :lsbmajdistrelease => '6', + } + end + + it { should compile.with_all_deps } + + it { should contain_class('nrpe') } + + it { + should contain_file('nrpe_plugin_check_root_partition').with({ + 'ensure' => 'file', + 'path' => '/etc/nrpe.d/check_root_partition.cfg', + 'owner' => 'root', + 'group' => 'root', + 'mode' => '0644', + 'require' => 'File[nrpe_config_dot_d]', + 'notify' => 'Service[nrpe_service]', + }) + } + + it { + should contain_file('nrpe_plugin_check_root_partition') \ + .with_content(/^command\[check_root_partition\]=\/usr\/lib\/nagios\/plugins\/check_disk -w 20% -c 10% -p \/$/) + } + + it { + should contain_file('nrpe_plugin_check_load').with({ + 'ensure' => 'file', + 'path' => '/etc/nrpe.d/check_load.cfg', + 'owner' => 'root', + 'group' => 'root', + 'mode' => '0644', + 'require' => 'File[nrpe_config_dot_d]', + 'notify' => 'Service[nrpe_service]', + }) + } + + it { + should contain_file('nrpe_plugin_check_load') \ + .with_content(/^command\[check_load\]=\/usr\/lib\/nagios\/plugins\/check_load -w 10,8,8 -c 12,10,9$/) + } + + it { + should contain_file('nrpe_plugin_check_me_out').with({ + 'ensure' => 'absent', + 'path' => '/etc/nrpe.d/check_me_out.cfg', + 'owner' => 'root', + 'group' => 'root', + 'mode' => '0644', + 'require' => 'File[nrpe_config_dot_d]', + 'notify' => 'Service[nrpe_service]', + }) + } + end + + context 'with plugins specified as a hash on 64 bit EL 6' do + let(:params) { + { + :plugins => { + 'check_root_partition' => { + 'plugin' => 'check_disk', + 'libexecdir' => '/usr/lib64/nagios/plugins', + 'args' => '-w 20% -c 10% -p /', + }, + 'check_load' => { + 'args' => '-w 10,8,8 -c 12,10,9', + }, + 'check_me_out' => { + 'ensure' => 'absent', + }, + } + } + } + let(:facts) do + { :architecture => 'x86_64', + :osfamily => 'RedHat', + :lsbmajdistrelease => '6', + } + end + + it { should compile.with_all_deps } + + it { should contain_class('nrpe') } + + it { + should contain_file('nrpe_plugin_check_root_partition').with({ + 'ensure' => 'file', + 'path' => '/etc/nrpe.d/check_root_partition.cfg', + 'owner' => 'root', + 'group' => 'root', + 'mode' => '0644', + 'require' => 'File[nrpe_config_dot_d]', + 'notify' => 'Service[nrpe_service]', + }) + } + + it { + should contain_file('nrpe_plugin_check_root_partition') \ + .with_content(/^command\[check_root_partition\]=\/usr\/lib64\/nagios\/plugins\/check_disk -w 20% -c 10% -p \/$/) + } + + it { + should contain_file('nrpe_plugin_check_load').with({ + 'ensure' => 'file', + 'path' => '/etc/nrpe.d/check_load.cfg', + 'owner' => 'root', + 'group' => 'root', + 'mode' => '0644', + 'require' => 'File[nrpe_config_dot_d]', + 'notify' => 'Service[nrpe_service]', + }) + } + + it { + should contain_file('nrpe_plugin_check_load') \ + .with_content(/^command\[check_load\]=\/usr\/lib64\/nagios\/plugins\/check_load -w 10,8,8 -c 12,10,9$/) + } + + it { + should contain_file('nrpe_plugin_check_me_out').with({ + 'ensure' => 'absent', + 'path' => '/etc/nrpe.d/check_me_out.cfg', + 'owner' => 'root', + 'group' => 'root', + 'mode' => '0644', + 'require' => 'File[nrpe_config_dot_d]', + 'notify' => 'Service[nrpe_service]', + }) + } + end + + context 'with plugins specified as a hash on Suse 11' do + let(:params) { + { + :plugins => { + 'check_root_partition' => { + 'plugin' => 'check_disk', + 'libexecdir' => '/usr/lib/nagios/plugins', + 'args' => '-w 20% -c 10% -p /', + }, + 'check_load' => { + 'args' => '-w 10,8,8 -c 12,10,9', + }, + 'check_me_out' => { + 'ensure' => 'absent', + }, + } + } + } + let(:facts) do + { :osfamily => 'Suse', + :lsbmajdistrelease => '11', + } end - end - - context 'with command_prefix_enable set to true' do - let(:params) { { :command_prefix_enable => true } } - - it { should compile.with_all_deps } - - it { should contain_file('nrpe_config').with_content(/^command_prefix=\/usr\/bin\/sudo$/) } - end - - context 'with command_prefix_enable set to to stringified \'true\'' do - let(:params) { { :command_prefix_enable => 'true' } } it { should compile.with_all_deps } - it { should contain_file('nrpe_config').with_content(/^command_prefix=\/usr\/bin\/sudo$/) } - end - - context 'with command_prefix set to a non absolute path' do - let(:params) { { :command_prefix => 'invalid/path' } } + it { should contain_class('nrpe') } - it 'should fail' do - expect { - should contain_class('nrpe') - }.to raise_error(Puppet::Error) - end - end + it { + should contain_file('nrpe_plugin_check_root_partition').with({ + 'ensure' => 'file', + 'path' => '/etc/nrpe.d/check_root_partition.cfg', + 'owner' => 'root', + 'group' => 'root', + 'mode' => '0644', + 'require' => 'File[nrpe_config_dot_d]', + 'notify' => 'Service[nrpe_service]', + }) + } - context 'with debug set to invalid value' do - let(:params) { { :debug => '2' } } + it { + should contain_file('nrpe_plugin_check_root_partition') \ + .with_content(/^command\[check_root_partition\]=\/usr\/lib\/nagios\/plugins\/check_disk -w 20% -c 10% -p \/$/) + } - it 'should fail' do - expect { - should contain_class('nrpe') - }.to raise_error(Puppet::Error,/nrpe::debug must be 0 or 1\. Detected value is <2>\./) - end - end + it { + should contain_file('nrpe_plugin_check_load').with({ + 'ensure' => 'file', + 'path' => '/etc/nrpe.d/check_load.cfg', + 'owner' => 'root', + 'group' => 'root', + 'mode' => '0644', + 'require' => 'File[nrpe_config_dot_d]', + 'notify' => 'Service[nrpe_service]', + }) + } - context 'with command_timeout set to an invalid setting' do - let(:params) { { :command_timeout => '-1' } } + it { + should contain_file('nrpe_plugin_check_load') \ + .with_content(/^command\[check_load\]=\/usr\/lib\/nagios\/plugins\/check_load -w 10,8,8 -c 12,10,9$/) + } - it 'should fail' do - expect { - should contain_class('nrpe') - }.to raise_error(Puppet::Error,/nrpe::command_timeout must be a postive integer\. Detected value is <-1>\./) - end + it { + should contain_file('nrpe_plugin_check_me_out').with({ + 'ensure' => 'absent', + 'path' => '/etc/nrpe.d/check_me_out.cfg', + 'owner' => 'root', + 'group' => 'root', + 'mode' => '0644', + 'require' => 'File[nrpe_config_dot_d]', + 'notify' => 'Service[nrpe_service]', + }) + } end - - context 'with connection_timeout set to an invalid setting' do - let(:params) { { :connection_timeout => '-1' } } - - it 'should fail' do - expect { - should contain_class('nrpe') - }.to raise_error(Puppet::Error,/nrpe::connection_timeout must be a postive integer\. Detected value is <-1>\./) + + context 'with plugins specified as a hash on Debian 6' do + let(:params) { + { + :plugins => { + 'check_root_partition' => { + 'plugin' => 'check_disk', + 'libexecdir' => '/usr/lib/nagios/plugins', + 'args' => '-w 20% -c 10% -p /', + }, + 'check_load' => { + 'args' => '-w 10,8,8 -c 12,10,9', + }, + 'check_me_out' => { + 'ensure' => 'absent', + }, + } + } + } + let(:facts) do + { :osfamily => 'Debian', + :lsbdistid => 'Debian', + :lsbmajdistrelease => '6', + } end - end - context 'with allow_weak_random_seed set to invalid value' do - let(:params) { { :allow_weak_random_seed => '2' } } - - it 'should fail' do - expect { - should contain_class('nrpe') - }.to raise_error(Puppet::Error,/nrpe::allow_weak_random_seed must be 0 or 1\. Detected value is <2>\./) - end - end + it { should compile.with_all_deps } - context 'with include_dir set to invalid value' do - let(:params) { { :include_dir => 'invalid/path' } } + it { should contain_class('nrpe') } - it 'should fail' do - expect { - should contain_class('nrpe') - }.to raise_error(Puppet::Error) - end - end + it { + should contain_file('nrpe_plugin_check_root_partition').with({ + 'ensure' => 'file', + 'path' => '/etc/nagios/nrpe.d/check_root_partition.cfg', + 'owner' => 'root', + 'group' => 'root', + 'mode' => '0644', + 'require' => 'File[nrpe_config_dot_d]', + 'notify' => 'Service[nrpe_service]', + }) + } - context 'with service_ensure set to invalid value' do - let(:params) { { :service_ensure => 'present' } } + it { + should contain_file('nrpe_plugin_check_root_partition') \ + .with_content(/^command\[check_root_partition\]=\/usr\/lib\/nagios\/plugins\/check_disk -w 20% -c 10% -p \/$/) + } - it 'should fail' do - expect { - should contain_class('nrpe') - }.to raise_error(Puppet::Error,/nrpe::service_ensure must be \'running\' or \'stopped\'\. Detected value is \./) - end - end + it { + should contain_file('nrpe_plugin_check_load').with({ + 'ensure' => 'file', + 'path' => '/etc/nagios/nrpe.d/check_load.cfg', + 'owner' => 'root', + 'group' => 'root', + 'mode' => '0644', + 'require' => 'File[nrpe_config_dot_d]', + 'notify' => 'Service[nrpe_service]', + }) + } - context 'with service_enable set to invalid value' do - let(:params) { { :service_enable => 'invalid' } } + it { + should contain_file('nrpe_plugin_check_load') \ + .with_content(/^command\[check_load\]=\/usr\/lib\/nagios\/plugins\/check_load -w 10,8,8 -c 12,10,9$/) + } - it 'should fail' do - expect { - should contain_class('nrpe') - }.to raise_error(Puppet::Error) - end + it { + should contain_file('nrpe_plugin_check_me_out').with({ + 'ensure' => 'absent', + 'path' => '/etc/nagios/nrpe.d/check_me_out.cfg', + 'owner' => 'root', + 'group' => 'root', + 'mode' => '0644', + 'require' => 'File[nrpe_config_dot_d]', + 'notify' => 'Service[nrpe_service]', + }) + } end - context 'with plugins specified as a hash on 32 bit EL 6' do + context 'with plugins specified as a hash on Ubuntu 12' do let(:params) { { :plugins => { @@ -715,7 +1334,7 @@ 'args' => '-w 20% -c 10% -p /', }, 'check_load' => { - 'args' => '-w 10,8,8 -c 12,10,9', + 'args' => '-w 10,8,8 -c 12,10,9', }, 'check_me_out' => { 'ensure' => 'absent', @@ -724,9 +1343,9 @@ } } let(:facts) do - { :architecture => 'i386', - :osfamily => 'RedHat', - :lsbmajdistrelease => '6', + { :osfamily => 'Debian', + :lsbdistid => 'Ubuntu', + :lsbmajdistrelease => '12', } end @@ -737,7 +1356,7 @@ it { should contain_file('nrpe_plugin_check_root_partition').with({ 'ensure' => 'file', - 'path' => '/etc/nrpe.d/check_root_partition.cfg', + 'path' => '/etc/nagios/nrpe.d/check_root_partition.cfg', 'owner' => 'root', 'group' => 'root', 'mode' => '0644', @@ -754,7 +1373,7 @@ it { should contain_file('nrpe_plugin_check_load').with({ 'ensure' => 'file', - 'path' => '/etc/nrpe.d/check_load.cfg', + 'path' => '/etc/nagios/nrpe.d/check_load.cfg', 'owner' => 'root', 'group' => 'root', 'mode' => '0644', @@ -771,7 +1390,7 @@ it { should contain_file('nrpe_plugin_check_me_out').with({ 'ensure' => 'absent', - 'path' => '/etc/nrpe.d/check_me_out.cfg', + 'path' => '/etc/nagios/nrpe.d/check_me_out.cfg', 'owner' => 'root', 'group' => 'root', 'mode' => '0644', @@ -781,17 +1400,17 @@ } end - context 'with plugins specified as a hash on 64 bit EL 6' do + context 'with plugins specified as a hash on Ubuntu 14.04' do let(:params) { { :plugins => { 'check_root_partition' => { 'plugin' => 'check_disk', - 'libexecdir' => '/usr/lib64/nagios/plugins', + 'libexecdir' => '/usr/lib/nagios/plugins', 'args' => '-w 20% -c 10% -p /', }, 'check_load' => { - 'args' => '-w 10,8,8 -c 12,10,9', + 'args' => '-w 10,8,8 -c 12,10,9', }, 'check_me_out' => { 'ensure' => 'absent', @@ -800,9 +1419,9 @@ } } let(:facts) do - { :architecture => 'x86_64', - :osfamily => 'RedHat', - :lsbmajdistrelease => '6', + { :osfamily => 'Debian', + :lsbdistid => 'Ubuntu', + :lsbmajdistrelease => '14.04', } end @@ -813,7 +1432,7 @@ it { should contain_file('nrpe_plugin_check_root_partition').with({ 'ensure' => 'file', - 'path' => '/etc/nrpe.d/check_root_partition.cfg', + 'path' => '/etc/nagios/nrpe.d/check_root_partition.cfg', 'owner' => 'root', 'group' => 'root', 'mode' => '0644', @@ -824,13 +1443,13 @@ it { should contain_file('nrpe_plugin_check_root_partition') \ - .with_content(/^command\[check_root_partition\]=\/usr\/lib64\/nagios\/plugins\/check_disk -w 20% -c 10% -p \/$/) + .with_content(/^command\[check_root_partition\]=\/usr\/lib\/nagios\/plugins\/check_disk -w 20% -c 10% -p \/$/) } it { should contain_file('nrpe_plugin_check_load').with({ 'ensure' => 'file', - 'path' => '/etc/nrpe.d/check_load.cfg', + 'path' => '/etc/nagios/nrpe.d/check_load.cfg', 'owner' => 'root', 'group' => 'root', 'mode' => '0644', @@ -841,13 +1460,13 @@ it { should contain_file('nrpe_plugin_check_load') \ - .with_content(/^command\[check_load\]=\/usr\/lib64\/nagios\/plugins\/check_load -w 10,8,8 -c 12,10,9$/) + .with_content(/^command\[check_load\]=\/usr\/lib\/nagios\/plugins\/check_load -w 10,8,8 -c 12,10,9$/) } it { should contain_file('nrpe_plugin_check_me_out').with({ 'ensure' => 'absent', - 'path' => '/etc/nrpe.d/check_me_out.cfg', + 'path' => '/etc/nagios/nrpe.d/check_me_out.cfg', 'owner' => 'root', 'group' => 'root', 'mode' => '0644', @@ -857,7 +1476,7 @@ } end - context 'with plugins specified as a hash on Suse 11' do + context 'with plugins specified as a hash on Ubuntu 16.04' do let(:params) { { :plugins => { @@ -867,7 +1486,7 @@ 'args' => '-w 20% -c 10% -p /', }, 'check_load' => { - 'args' => '-w 10,8,8 -c 12,10,9', + 'args' => '-w 10,8,8 -c 12,10,9', }, 'check_me_out' => { 'ensure' => 'absent', @@ -876,8 +1495,9 @@ } } let(:facts) do - { :osfamily => 'Suse', - :lsbmajdistrelease => '11', + { :osfamily => 'Debian', + :lsbdistid => 'Ubuntu', + :lsbmajdistrelease => '16.04', } end @@ -888,7 +1508,7 @@ it { should contain_file('nrpe_plugin_check_root_partition').with({ 'ensure' => 'file', - 'path' => '/etc/nrpe.d/check_root_partition.cfg', + 'path' => '/etc/nagios/nrpe.d/check_root_partition.cfg', 'owner' => 'root', 'group' => 'root', 'mode' => '0644', @@ -905,7 +1525,7 @@ it { should contain_file('nrpe_plugin_check_load').with({ 'ensure' => 'file', - 'path' => '/etc/nrpe.d/check_load.cfg', + 'path' => '/etc/nagios/nrpe.d/check_load.cfg', 'owner' => 'root', 'group' => 'root', 'mode' => '0644', @@ -922,7 +1542,7 @@ it { should contain_file('nrpe_plugin_check_me_out').with({ 'ensure' => 'absent', - 'path' => '/etc/nrpe.d/check_me_out.cfg', + 'path' => '/etc/nagios/nrpe.d/check_me_out.cfg', 'owner' => 'root', 'group' => 'root', 'mode' => '0644', @@ -931,8 +1551,8 @@ }) } end - - context 'with plugins specified as a hash on Debian 6' do + + context 'with plugins specified as a hash on Ubuntu 18.04' do let(:params) { { :plugins => { @@ -952,8 +1572,8 @@ } let(:facts) do { :osfamily => 'Debian', - :lsbdistid => 'Debian', - :lsbmajdistrelease => '6', + :lsbdistid => 'Ubuntu', + :lsbmajdistrelease => '18.04', } end @@ -1008,7 +1628,7 @@ } end - context 'with plugins specified as a hash on Ubuntu 12' do + context 'with plugins specified as a hash on Ubuntu 20.04' do let(:params) { { :plugins => { @@ -1029,7 +1649,7 @@ let(:facts) do { :osfamily => 'Debian', :lsbdistid => 'Ubuntu', - :lsbmajdistrelease => '12', + :lsbmajdistrelease => '20.04', } end