diff --git a/manifests/check.pp b/manifests/check.pp index 296e4c8884..c8e473095d 100644 --- a/manifests/check.pp +++ b/manifests/check.pp @@ -92,7 +92,7 @@ if $client { if $server { - $notify = [ Class['sensu::client::service'], Class['sensu::server::service'] ] + } else { $notify = Class['sensu::client::service'] } @@ -128,7 +128,7 @@ publish => $publish, custom => $custom, require => File['/etc/sensu/conf.d/checks'], - notify => $notify, + notify => $::sensu::check_notify, } } diff --git a/manifests/init.pp b/manifests/init.pp index a2e25ea4e9..609296d8c8 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -217,6 +217,27 @@ if !is_integer($api_port) { fail('api_port must be an integer') } if !is_integer($dashboard_port) { fail('dashboard_port must be an integer') } + # Ugly hack for notifications, better way? + # Put here to avoid computing the conditionals for every check + if $client and $server and $api { + $check_notify = [ Class['sensu::client::service'], Class['sensu::server::service'], Class['sensu::api::service'] ] + } elsif $client and $server { + $check_notify = [ Class['sensu::client::service'], Class['sensu::server::service'] ] + } elsif $client and $api { + $check_notify = [ Class['sensu::client::service'], Class['sensu::api::service'] ] + } elsif $server and $api { + $check_notify = [ Class['sensu::server::service'], Class['sensu::api::service'] ] + } elsif $server { + $check_notify = Class['sensu::server::service'] + } elsif $client { + $check_notify = Class['sensu::client::service'] + } elsif $api { + $check_notify = Class['sensu::api::service'] + } else { + $check_notify = [] + } + + # Include everything and let each module determine its state. This allows # transitioning to purged config and stopping/disabling services anchor { 'sensu::begin': } -> diff --git a/spec/defines/sensu_check_spec.rb b/spec/defines/sensu_check_spec.rb index 9db8a6efd1..7af269767d 100644 --- a/spec/defines/sensu_check_spec.rb +++ b/spec/defines/sensu_check_spec.rb @@ -90,5 +90,50 @@ end end + context 'notifications' do + let(:title) { 'mycheck' } + let(:params) { { :command => '/etc/sensu/somecommand.rb' } } + + context 'no client, sever, or api' do + let(:pre_condition) { 'class {"sensu": client => false, api => false, server => false}' } + it { should contain_sensu_check('mycheck').with(:notify => []) } + end + + context 'only client' do + let(:pre_condition) { 'class {"sensu": client => true, api => false, server => false}' } + it { should contain_sensu_check('mycheck').with(:notify => [ 'Class[Sensu::Client::Service]' ]) } + end + + context 'only server' do + let(:pre_condition) { 'class {"sensu": client => false, api => false, server => true}' } + it { should contain_sensu_check('mycheck').with(:notify => [ 'Class[Sensu::Server::Service]' ]) } + end + + context 'only api' do + let(:pre_condition) { 'class {"sensu": client => false, api => true, server => false}' } + it { should contain_sensu_check('mycheck').with(:notify => [ 'Class[Sensu::Api::Service]' ]) } + end + + context 'client and api' do + let(:pre_condition) { 'class {"sensu": client => true, api => true, server => false}' } + it { should contain_sensu_check('mycheck').with(:notify => ['Class[Sensu::Client::Service]', 'Class[Sensu::Api::Service]']) } + end + + context 'client and server' do + let(:pre_condition) { 'class {"sensu": client => true, api => false, server => true}' } + it { should contain_sensu_check('mycheck').with(:notify => ['Class[Sensu::Client::Service]', 'Class[Sensu::Server::Service]']) } + end + + context 'api and server' do + let(:pre_condition) { 'class {"sensu": client => false, api => true, server => true}' } + it { should contain_sensu_check('mycheck').with(:notify => ['Class[Sensu::Server::Service]', 'Class[Sensu::Api::Service]']) } + end + + context 'client, api, and server' do + let(:pre_condition) { 'class {"sensu": client => true, api => true, server => true}' } + it { should contain_sensu_check('mycheck').with(:notify => ['Class[Sensu::Client::Service]', 'Class[Sensu::Server::Service]', 'Class[Sensu::Api::Service]']) } + end + end + end