Skip to content

Commit

Permalink
Merge pull request #142 from cloudevelops/sensu_check_addons
Browse files Browse the repository at this point in the history
Support for timeout,aggregate,handle and publish parameters to sensu_check
  • Loading branch information
jlambert121 committed Jan 20, 2014
2 parents 93e8ace + 09a0500 commit acd423b
Show file tree
Hide file tree
Showing 4 changed files with 151 additions and 20 deletions.
80 changes: 79 additions & 1 deletion lib/puppet/provider/sensu_check/json.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,15 @@ def create
self.standalone = resource[:standalone] unless resource[:standalone].nil?
self.high_flap_threshold = resource[:high_flap_threshold] unless resource[:high_flap_threshold].nil?
self.low_flap_threshold = resource[:low_flap_threshold] unless resource[:low_flap_threshold].nil?
self.timeout = resource[:timeout] unless resource[:timeout].nil?
self.aggregate = resource[:aggregate] unless resource[:aggregate].nil?
self.handle = resource[:handle] unless resource[:handle].nil?
self.publish = resource[:publish] unless resource[:publish].nil?
self.custom = resource[:custom] unless resource[:custom].nil?
end

def check_args
['handlers','command','interval','subscribers','type','standalone','high_flap_threshold','low_flap_threshold']
['handlers','command','interval','subscribers','type','standalone','high_flap_threshold','low_flap_threshold','timeout','aggregate','handle','publish','custom']
end

def custom
Expand Down Expand Up @@ -124,6 +128,80 @@ def high_flap_threshold=(value)
conf['checks'][resource[:name]]['high_flap_threshold'] = value.to_i
end

def timeout
conf['checks'][resource[:name]]['timeout'].to_s
end

def timeout=(value)
conf['checks'][resource[:name]]['timeout'] = value.to_f
end

def aggregate
case conf['checks'][resource[:name]]['aggregate']
when true
:true
when false
:false
else
conf['checks'][resource[:name]]['aggregate']
end
end

def aggregate=(value)
case value
when true, 'true', 'True', :true, 1
conf['checks'][resource[:name]]['aggregate'] = true
when false, 'false', 'False', :false, 0
conf['checks'][resource[:name]]['aggregate'] = false
else
conf['checks'][resource[:name]]['aggregate'] = value
end
end

def handle
case conf['checks'][resource[:name]]['handle']
when true
:true
when false
:false
else
conf['checks'][resource[:name]]['handle']
end
end

def handle=(value)
case value
when true, 'true', 'True', :true, 1
conf['checks'][resource[:name]]['handle'] = true
when false, 'false', 'False', :false, 0
conf['checks'][resource[:name]]['handle'] = false
else
conf['checks'][resource[:name]]['handle'] = value
end
end

def publish
case conf['checks'][resource[:name]]['publish']
when true
:true
when false
:false
else
conf['checks'][resource[:name]]['publish']
end
end

def publish=(value)
case value
when true, 'true', 'True', :true, 1
conf['checks'][resource[:name]]['publish'] = true
when false, 'false', 'False', :false, 0
conf['checks'][resource[:name]]['publish'] = false
else
conf['checks'][resource[:name]]['publish'] = value
end
end

def standalone
case conf['checks'][resource[:name]]['standalone']
when true
Expand Down
16 changes: 16 additions & 0 deletions lib/puppet/type/sensu_check.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,22 @@ def insync?(is)
newvalues(:true, :false)
end

newproperty(:timeout) do
desc "Check timeout in seconds, after it fails"
end

newproperty(:aggregate) do
desc "Whether check is aggregate"
end

newproperty(:handle) do
desc "Whether check event send to a handler"
end

newproperty(:publish) do
desc "Whether check is unpublished"
end

autorequire(:package) do
['sensu']
end
Expand Down
47 changes: 38 additions & 9 deletions manifests/check.pp
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,39 @@
# Integer. Flap detection - see Nagios Flap Detection: http://nagios.sourceforge.net/docs/3_0/flapping.html
# Default: undef
#
# [*timeout*]
# Integer. Check timeout in seconds, after it fails
# Default: undef
#
# [*aggregate*]
# Boolean. Aggregates, preventing event floods. Set 'aggregate:true and 'handle':false, this prevents the
# server from sending to a handler, and makes the aggregated results available under /aggregates in the REST API
# Default: undef
#
# [*handle*]
# Boolean. When true, check will not be sent to handlers
# Default: undef
#
# [*publish*]
# Boolean. Unpublished checks. Prevents the check from being triggered on clients. This allows for the definition
# of commands that are not actually 'checks' per say, but actually arbitrary commands for remediation
# Default: undef
#
define sensu::check(
$command,
$ensure = 'present',
$type = undef,
$handlers = undef,
$standalone = true,
$interval = 60,
$subscribers = [],
$low_flap_threshold = undef,
$high_flap_threshold = undef,
$custom = undef,
$ensure = 'present',
$type = undef,
$handlers = undef,
$standalone = true,
$interval = 60,
$subscribers = [],
$low_flap_threshold = undef,
$high_flap_threshold = undef,
$timeout = undef,
$aggregate = undef,
$handle = undef,
$publish = undef,
$custom = undef,
) {

validate_re($ensure, ['^present$', '^absent$'] )
Expand All @@ -64,6 +86,9 @@
if $high_flap_threshold and !is_integer($high_flap_threshold) {
fail("sensu::check{${name}}: high_flap_threshold must be an integer (got: ${high_flap_threshold})")
}
if $timeout and !is_float($timeout) {
fail("sensu::check{${name}}: timeout must be an float (got: ${timeout})")
}

$check_name = regsubst(regsubst($name, ' ', '_', 'G'), '[\(\)]', '', 'G')

Expand All @@ -85,6 +110,10 @@
subscribers => $subscribers,
low_flap_threshold => $low_flap_threshold,
high_flap_threshold => $high_flap_threshold,
timeout => $timeout,
aggregate => $aggregate,
handle => $handle,
publish => $publish,
custom => $custom,
require => File['/etc/sensu/conf.d/checks'],
notify => [ Class['sensu::client::service'], Class['sensu::server::service'] ],
Expand Down
28 changes: 18 additions & 10 deletions spec/defines/sensu_check_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,19 @@

context 'setting params' do
let(:params) { {
:command => '/etc/sensu/command2.rb',
:handlers => ['/handler1', '/handler2'],
:interval => 10,
:subscribers => ['all'],
:custom => { 'a' => 'b', 'array' => [ 'c', 'd']},
:type => 'metric',
:standalone => true,
:low_flap_threshold => 10,
:high_flap_threshold => 15
:command => '/etc/sensu/command2.rb',
:handlers => ['/handler1', '/handler2'],
:interval => 10,
:subscribers => ['all'],
:custom => { 'a' => 'b', 'array' => [ 'c', 'd']},
:type => 'metric',
:standalone => true,
:low_flap_threshold => 10,
:high_flap_threshold => 15,
:timeout => 0.5,
:aggregate => true,
:handle => true,
:publish => true
} }

it { should contain_sensu_check('mycheck').with(
Expand All @@ -38,7 +42,11 @@
:type => 'metric',
:standalone => true,
:low_flap_threshold => 10,
:high_flap_threshold => 15
:high_flap_threshold => 15,
:timeout => 0.5,
:aggregate => true,
:handle => true,
:publish => true
) }
end

Expand Down

0 comments on commit acd423b

Please sign in to comment.