Skip to content

Commit

Permalink
restart client,server,api based on what the machine has provisioned
Browse files Browse the repository at this point in the history
  • Loading branch information
jlambert121 committed May 29, 2014
1 parent 938e344 commit a296283
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 2 deletions.
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

0 comments on commit a296283

Please sign in to comment.