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

adding occurrences and refresh parameters to sensu_check type and sensu:... #200

Merged
merged 1 commit into from
Aug 5, 2014
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion lib/puppet/provider/sensu_check/json.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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?

Choose a reason for hiding this comment

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

did you mean resource[:interval] unless resource[:interval].nil? or resource[:refresh] unless resource[:refresh].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?
Expand All @@ -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
Expand Down Expand Up @@ -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

Choose a reason for hiding this comment

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

shouldn't this assign value.to_i?

end

def refresh
conf['checks'][resource[:name]]['refresh']
end

def refresh=(value)
conf['checks'][resource[:name]]['refresh'] = value

Choose a reason for hiding this comment

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

shouldn't this assign value.to_i, as well?

end

def command
conf['checks'][resource[:name]]['command']
Expand Down
8 changes: 8 additions & 0 deletions lib/puppet/type/sensu_check.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
16 changes: 16 additions & 0 deletions manifests/check.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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: []
Expand Down Expand Up @@ -69,6 +75,8 @@
$handlers = undef,
$standalone = true,
$interval = 60,
$occurrences = undef,
$refresh = undef,
$subscribers = [],
$low_flap_threshold = undef,
$high_flap_threshold = undef,
Expand All @@ -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})")
}
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 4 additions & 0 deletions spec/defines/sensu_check_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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',
Expand Down