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

simplify $check_notify logic #403

Closed
wants to merge 1 commit into from
Closed
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
30 changes: 12 additions & 18 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -352,26 +352,20 @@
}
}

# 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 = []
if $client {
$_client_notify = Class['sensu::client::service']
}

if $api {
$_api_notify = Class['sensu::api::service']
}

if $server {
$_server_notify = Class['sensu::server::service']
}

$check_notify = delete_undef_values([ $_client_notify, $_api_notify, $_server_notify ])

# Because you can't reassign a variable in puppet and we need to set to
# false if you specify a directory, we have to use another variable.
if $plugins_dir {
Expand Down
10 changes: 5 additions & 5 deletions spec/defines/sensu_check_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,17 +101,17 @@

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]' ) }
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]' ) }
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]' ) }
it { should contain_sensu_check('mycheck').with(:notify => ['Class[Sensu::Api::Service]'] ) }
end

context 'client and api' do
Expand All @@ -126,12 +126,12 @@

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]']) }
it { should contain_sensu_check('mycheck').with(:notify => ['Class[Sensu::Api::Service]', 'Class[Sensu::Server::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]']) }
it { should contain_sensu_check('mycheck').with(:notify => ['Class[Sensu::Client::Service]', 'Class[Sensu::Api::Service]', 'Class[Sensu::Server::Service]']) }
end
end

Expand Down