diff --git a/lib/puppet/provider/sensu_check/json.rb b/lib/puppet/provider/sensu_check/json.rb index b6a3bac35e..d7bbc936b0 100644 --- a/lib/puppet/provider/sensu_check/json.rb +++ b/lib/puppet/provider/sensu_check/json.rb @@ -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 @@ -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 diff --git a/lib/puppet/type/sensu_check.rb b/lib/puppet/type/sensu_check.rb index 49143244df..db45d4643c 100644 --- a/lib/puppet/type/sensu_check.rb +++ b/lib/puppet/type/sensu_check.rb @@ -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 diff --git a/manifests/check.pp b/manifests/check.pp index d66603c24c..4126001bcb 100644 --- a/manifests/check.pp +++ b/manifests/check.pp @@ -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$'] ) @@ -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') @@ -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'] ], diff --git a/spec/defines/sensu_check_spec.rb b/spec/defines/sensu_check_spec.rb index 621a5e266e..9db8a6efd1 100644 --- a/spec/defines/sensu_check_spec.rb +++ b/spec/defines/sensu_check_spec.rb @@ -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( @@ -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