Skip to content

Commit 2c262ef

Browse files
author
Daniel Rossbach
committed
added custom variables for sensu_check
1 parent 1409d20 commit 2c262ef

File tree

5 files changed

+73
-0
lines changed

5 files changed

+73
-0
lines changed

README.md

+39
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,45 @@ A usage example is shown below.
160160
}
161161

162162

163+
## Using custom variables in check definition
164+
165+
sensu::check{ 'check_file_test':
166+
command => '/usr/local/bin/check_file_test.sh',
167+
handlers => 'notifu',
168+
sla => ['admin:2'],
169+
custom => {
170+
'foo' => 'bar',
171+
'in_array' => ['foo','zwei']
172+
},
173+
subscribers => 'sensu-test'
174+
}
175+
176+
This will create the following check definition for Sensu
177+
178+
{
179+
"checks": {
180+
"check_file_test": {
181+
"handlers": [
182+
"notifu"
183+
],
184+
"in_array": [
185+
"foo",
186+
"zwei"
187+
],
188+
"command": "/usr/local/bin/check_file_test.sh",
189+
"subscribers": [
190+
"sensu-test"
191+
],
192+
"foo": "bar",
193+
"interval": 60,
194+
"sla": [
195+
"admin:2"
196+
]
197+
}
198+
}
199+
}
200+
201+
163202
## Including Sensu monitoring in other modules
164203

165204
There are a few different patterns that can be used to include Sensu

lib/puppet/provider/sensu_check/json.rb

+26
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,32 @@ def create
4242
self.occurrences = resource[:occurrences] unless resource[:occurrences].nil?
4343
self.refresh = resource[:refresh] unless resource[:refresh].nil?
4444
self.notification = resource[:notification] unless resource[:notification].nil?
45+
self.custom = resource[:custom] unless resource[:custom].nil?
46+
end
47+
48+
def check_args
49+
['handlers','command','interval','subscribers','sla','type','config','aggregate','standalone','high_flap_threshold','low_flap_threshold','occurrences','refresh','notification']
50+
end
51+
52+
def custom
53+
tmp = {}
54+
conf['checks'][resource[:name]].each do |k,v|
55+
tmp.merge!( k => v )
56+
end
57+
check_args.each do | del_arg |
58+
tmp.delete(del_arg)
59+
end
60+
tmp
61+
end
62+
63+
def custom=(value)
64+
tmp = custom
65+
tmp.each_key do |k|
66+
conf['checks'][resource[:name]].delete(k) unless check_args.include?(k)
67+
end
68+
value.each do | k, v |
69+
conf['checks'][resource[:name]][ k ] = v
70+
end
4571
end
4672

4773
def destroy

lib/puppet/type/sensu_check.rb

+4
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ def initialize(*args)
7171
desc "custom variable for notifu"
7272
end
7373

74+
newproperty(:custom) do
75+
desc "custom variable"
76+
end
77+
7478
newproperty(:type) do
7579
desc "What type of check is this"
7680
end

manifests/check.pp

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
$interval = '60',
1515
$subscribers = [],
1616
$sla = [],
17+
$custom = undef,
1718
$notification = undef,
1819
$low_flap_threshold = undef,
1920
$high_flap_threshold = undef,
@@ -37,6 +38,7 @@
3738
interval => $interval,
3839
subscribers => $subscribers,
3940
sla => $sla,
41+
custom => $custom,
4042
notification => $notification,
4143
low_flap_threshold => $low_flap_threshold,
4244
high_flap_threshold => $high_flap_threshold,

spec/defines/sensu_check_spec.rb

+2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
:interval => '10',
2323
:subscribers => ['all'],
2424
:sla => ['admin:2'],
25+
:custom => { 'a' => 'b', 'array' => [ 'c', 'd']},
2526
:type => 'metric',
2627
:standalone => true,
2728
:notification => 'some text',
@@ -38,6 +39,7 @@
3839
'interval' => '10',
3940
'subscribers' => ['all'],
4041
'sla' => ['admin:2'],
42+
'custom' => { 'a' => 'b', 'array' => [ 'c', 'd']},
4143
'type' => 'metric',
4244
'standalone' => true,
4345
'notification' => 'some text',

0 commit comments

Comments
 (0)