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

restart client,server,api based on what the machine has provisioned #193

Merged
merged 1 commit into from
May 29, 2014
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
4 changes: 2 additions & 2 deletions manifests/check.pp
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@

if $client {
if $server {
$notify = [ Class['sensu::client::service'], Class['sensu::server::service'] ]

} else {
$notify = Class['sensu::client::service']
}
Expand Down Expand Up @@ -128,7 +128,7 @@
publish => $publish,
custom => $custom,
require => File['/etc/sensu/conf.d/checks'],
notify => $notify,
notify => $::sensu::check_notify,
}

}
21 changes: 21 additions & 0 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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': } ->
Expand Down
45 changes: 45 additions & 0 deletions spec/defines/sensu_check_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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