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

Add handle_silenced parameter to handler defined type #753

Merged
merged 7 commits into from Jul 25, 2017
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions lib/puppet/provider/sensu_handler/json.rb
Expand Up @@ -143,4 +143,12 @@ def handle_flapping=(value)
conf['handlers'][resource[:name]]['handle_flapping'] = value
end

def handle_silenced
conf['handlers'][resource[:name]]['handle_silenced']
end

def handle_silenced=(value)
conf['handlers'][resource[:name]]['handle_silenced'] = value
end

end
4 changes: 4 additions & 0 deletions lib/puppet/type/sensu_handler.rb
Expand Up @@ -107,6 +107,10 @@ def insync?(is)
desc "If events in the flapping state should be handled"
end

newproperty(:handle_silenced, :parent => PuppetX::Sensu::BooleanProperty) do
desc "If events in the silenced state should be handled"
end

autorequire(:package) do
['sensu']
end
Expand Down
7 changes: 7 additions & 0 deletions manifests/handler.pp
Expand Up @@ -67,6 +67,11 @@
# Default: false.
# Valid values: true, false
#
# [*handle_silenced*]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add an example to https://github.com/sensu/sensu-puppet/blob/master/tests/sensu-server.pp and document which file should be modified what json should be expected. That way we can functionally test this behaves as expected.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added that in d05b1c7, wasn't quite sure how to go about it

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

# Boolean. If events in the silenced state should be handled.
# Default: false.
# Valid values: true, false
#
define sensu::handler(
Enum['present','absent'] $ensure = 'present',
Enum['pipe','tcp','udp','amqp','set','transport'] $type = 'pipe',
Expand All @@ -86,6 +91,7 @@
Any $subdue = undef,
Optional[Integer] $timeout = undef,
Boolean $handle_flapping = false,
Boolean $handle_silenced = false,
) {

if $subdue{ fail('Subdue at handler is deprecated since sensu 0.26. See https://sensuapp.org/docs/0.26/overview/changelog.html#core-v0-26-0')}
Expand Down Expand Up @@ -163,6 +169,7 @@
config => $config,
timeout => $timeout,
handle_flapping => $handle_flapping,
handle_silenced => $handle_silenced,
notify => $notify_services,
require => File['/etc/sensu/conf.d/handlers'],
}
Expand Down
15 changes: 15 additions & 0 deletions spec/defines/sensu_handler_spec.rb
Expand Up @@ -177,4 +177,19 @@
it { should contain_sensu_handler('myhandler').with_handle_flapping( true ) }
end

context 'handle_silenced' do
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we also need a test for when this is false

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added another spec to confirm that handle_silenced when it's left as the default of false

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've now also added a spec to check when handle_silenced is explicitly set to false

let(:params) { { :command => 'mycommand.rb', :type => 'pipe', :handle_silenced => true } }
it { should contain_sensu_handler('myhandler').with_handle_silenced( true ) }
end

context 'handle_silenced set to false' do
let(:params) { { :command => 'mycommand.rb', :type => 'pipe', :handle_silenced => false } }
it { should contain_sensu_handler('myhandler').with_handle_silenced( false ) }
end

context 'handle_silenced set to default' do
let(:params) { { :command => 'mycommand.rb', :type => 'pipe' } }
it { should contain_sensu_handler('myhandler').with_handle_silenced( false ) }
end

end
28 changes: 28 additions & 0 deletions tests/sensu-server.pp
Expand Up @@ -22,6 +22,34 @@
command => 'mail -s \'sensu alert\' ops@example.com',
}

# Example handler which operates in silenced checks
#
# This should create a file in /etc/sensu/conf.d/handlers/handle_silenced.json, containing the following:
#
# {
# "handlers": {
# "mail_handle_silenced": {
# "command": "mail -s 'sensu alert' ops@example.com",
# "type": "pipe",
# "filters": [
#
# ],
# "severities": [
# "ok",
# "warning",
# "critical",
# "unknown"
# ],
# "handle_flapping": false,
# "handle_silenced": true
# }
# }
# }
sensu::handler { 'mail_handle_silenced':
command => 'mail -s \'sensu alert\' ops@example.com',
handle_silenced => true,
}

sensu::check { 'check_ntp':
command => 'PATH=$PATH:/usr/lib64/nagios/plugins check_ntp_time -H pool.ntp.org -w 30 -c 60',
handlers => 'default',
Expand Down