Skip to content

Commit

Permalink
added custom variables for sensu_check
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Rossbach committed May 18, 2013
1 parent 1409d20 commit 2c262ef
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 0 deletions.
39 changes: 39 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,45 @@ A usage example is shown below.
}


## Using custom variables in check definition

sensu::check{ 'check_file_test':
command => '/usr/local/bin/check_file_test.sh',
handlers => 'notifu',
sla => ['admin:2'],
custom => {
'foo' => 'bar',
'in_array' => ['foo','zwei']
},
subscribers => 'sensu-test'
}

This will create the following check definition for Sensu

{
"checks": {
"check_file_test": {
"handlers": [
"notifu"
],
"in_array": [
"foo",
"zwei"
],
"command": "/usr/local/bin/check_file_test.sh",
"subscribers": [
"sensu-test"
],
"foo": "bar",
"interval": 60,
"sla": [
"admin:2"
]
}
}
}


## Including Sensu monitoring in other modules

There are a few different patterns that can be used to include Sensu
Expand Down
26 changes: 26 additions & 0 deletions lib/puppet/provider/sensu_check/json.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,32 @@ def create
self.occurrences = resource[:occurrences] unless resource[:occurrences].nil?
self.refresh = resource[:refresh] unless resource[:refresh].nil?
self.notification = resource[:notification] unless resource[:notification].nil?
self.custom = resource[:custom] unless resource[:custom].nil?
end

def check_args
['handlers','command','interval','subscribers','sla','type','config','aggregate','standalone','high_flap_threshold','low_flap_threshold','occurrences','refresh','notification']
end

def custom
tmp = {}
conf['checks'][resource[:name]].each do |k,v|
tmp.merge!( k => v )
end
check_args.each do | del_arg |
tmp.delete(del_arg)
end
tmp
end

def custom=(value)
tmp = custom
tmp.each_key do |k|
conf['checks'][resource[:name]].delete(k) unless check_args.include?(k)
end
value.each do | k, v |
conf['checks'][resource[:name]][ k ] = v
end
end

def destroy
Expand Down
4 changes: 4 additions & 0 deletions lib/puppet/type/sensu_check.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ def initialize(*args)
desc "custom variable for notifu"
end

newproperty(:custom) do
desc "custom variable"
end

newproperty(:type) do
desc "What type of check is this"
end
Expand Down
2 changes: 2 additions & 0 deletions manifests/check.pp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
$interval = '60',
$subscribers = [],
$sla = [],
$custom = undef,
$notification = undef,
$low_flap_threshold = undef,
$high_flap_threshold = undef,
Expand All @@ -37,6 +38,7 @@
interval => $interval,
subscribers => $subscribers,
sla => $sla,
custom => $custom,
notification => $notification,
low_flap_threshold => $low_flap_threshold,
high_flap_threshold => $high_flap_threshold,
Expand Down
2 changes: 2 additions & 0 deletions spec/defines/sensu_check_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
:interval => '10',
:subscribers => ['all'],
:sla => ['admin:2'],
:custom => { 'a' => 'b', 'array' => [ 'c', 'd']},
:type => 'metric',
:standalone => true,
:notification => 'some text',
Expand All @@ -38,6 +39,7 @@
'interval' => '10',
'subscribers' => ['all'],
'sla' => ['admin:2'],
'custom' => { 'a' => 'b', 'array' => [ 'c', 'd']},
'type' => 'metric',
'standalone' => true,
'notification' => 'some text',
Expand Down

0 comments on commit 2c262ef

Please sign in to comment.