diff --git a/lib/puppet/provider/sensu_check/json.rb b/lib/puppet/provider/sensu_check/json.rb index e3c65df958..185f023f56 100644 --- a/lib/puppet/provider/sensu_check/json.rb +++ b/lib/puppet/provider/sensu_check/json.rb @@ -39,6 +39,8 @@ def create self.interval = resource[:interval] # Optional arguments self.handlers = resource[:handlers] unless resource[:handlers].nil? + self.occurrences = resource[:occurrences] unless resource[:occurrences].nil? + self.refresh = resource[:interval] unless resource[:interval].nil? self.subscribers = resource[:subscribers] unless resource[:subscribers].nil? self.type = resource[:type] unless resource[:type].nil? self.standalone = resource[:standalone] unless resource[:standalone].nil? @@ -52,7 +54,7 @@ def create end def check_args - ['handlers','command','interval','subscribers','type','standalone','high_flap_threshold','low_flap_threshold','timeout','aggregate','handle','publish','custom'] + ['handlers','command','interval','occurrences','refresh','subscribers','type','standalone','high_flap_threshold','low_flap_threshold','timeout','aggregate','handle','publish','custom'] end def custom @@ -91,6 +93,21 @@ def handlers def handlers=(value) conf['checks'][resource[:name]]['handlers'] = value end + def occurrences + conf['checks'][resource[:name]]['occurrences'] + end + + def occurrences=(value) + conf['checks'][resource[:name]]['occurrences'] = value + end + + def refresh + conf['checks'][resource[:name]]['refresh'] + end + + def refresh=(value) + conf['checks'][resource[:name]]['refresh'] = value + end def command conf['checks'][resource[:name]]['command'] diff --git a/lib/puppet/type/sensu_check.rb b/lib/puppet/type/sensu_check.rb index b01cf03463..35cdce5c06 100644 --- a/lib/puppet/type/sensu_check.rb +++ b/lib/puppet/type/sensu_check.rb @@ -52,6 +52,14 @@ def initialize(*args) desc "How frequently the check runs in seconds" end + newproperty(:occurrences) do + desc "The number of event occurrences before the handler should take action." + end + + newproperty(:refresh) do + desc "The number of seconds sensu-plugin-aware handlers should wait before taking second action." + end + newparam(:base_path) do desc "The base path to the client config file" defaultto '/etc/sensu/conf.d/checks' diff --git a/manifests/check.pp b/manifests/check.pp index 7d3f2444af..587e3c582e 100644 --- a/manifests/check.pp +++ b/manifests/check.pp @@ -28,6 +28,12 @@ # Integer. How frequently (in seconds) the check will be executed # Default: 60 # +# [*occurrences*] +# Integer. The number of event occurrences before the handler should take action. +# +# [*refresh*] +# Integer. The number of seconds sensu-plugin-aware handlers should wait before taking second action. +# # [*subscribers*] # Array of Strings. Which subscriptions must execute this check # Default: [] @@ -69,6 +75,8 @@ $handlers = undef, $standalone = true, $interval = 60, + $occurrences = undef, + $refresh = undef, $subscribers = [], $low_flap_threshold = undef, $high_flap_threshold = undef, @@ -85,6 +93,12 @@ if !is_integer($interval) { fail("sensu::check{${name}}: interval must be an integer (got: ${interval})") } + if $occurrences and !is_integer($occurrences) { + fail("sensu::check{${name}}: occurrences must be an integer (got: ${occurrences})") + } + if $refresh and !is_integer($refresh) { + fail("sensu::check{${name}}: refresh must be an integer (got: ${refresh})") + } if $low_flap_threshold and !is_integer($low_flap_threshold) { fail("sensu::check{${name}}: low_flap_threshold must be an integer (got: ${low_flap_threshold})") } @@ -124,6 +138,8 @@ command => $command, handlers => $handlers, interval => $interval, + occurrences => $occurrences, + refresh => $refresh, subscribers => $subscribers, low_flap_threshold => $low_flap_threshold, high_flap_threshold => $high_flap_threshold, diff --git a/spec/defines/sensu_check_spec.rb b/spec/defines/sensu_check_spec.rb index 7af269767d..d19d9c482a 100644 --- a/spec/defines/sensu_check_spec.rb +++ b/spec/defines/sensu_check_spec.rb @@ -21,6 +21,8 @@ :command => '/etc/sensu/command2.rb', :handlers => ['/handler1', '/handler2'], :interval => 10, + :occurrences => 5, + :refresh => 3600, :subscribers => ['all'], :custom => { 'a' => 'b', 'array' => [ 'c', 'd']}, :type => 'metric', @@ -37,6 +39,8 @@ :command => '/etc/sensu/command2.rb', :handlers => ['/handler1', '/handler2'], :interval => 10, + :occurrences => 5, + :refresh => 3600, :subscribers => ['all'], :custom => { 'a' => 'b', 'array' => [ 'c', 'd']}, :type => 'metric',