Skip to content

Commit 09a0500

Browse files
committed
Added direct support for timeout,aggregate,handle and publish parameters to sensu_check
1 parent 93e8ace commit 09a0500

File tree

4 files changed

+151
-20
lines changed

4 files changed

+151
-20
lines changed

lib/puppet/provider/sensu_check/json.rb

+79-1
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,15 @@ def create
4444
self.standalone = resource[:standalone] unless resource[:standalone].nil?
4545
self.high_flap_threshold = resource[:high_flap_threshold] unless resource[:high_flap_threshold].nil?
4646
self.low_flap_threshold = resource[:low_flap_threshold] unless resource[:low_flap_threshold].nil?
47+
self.timeout = resource[:timeout] unless resource[:timeout].nil?
48+
self.aggregate = resource[:aggregate] unless resource[:aggregate].nil?
49+
self.handle = resource[:handle] unless resource[:handle].nil?
50+
self.publish = resource[:publish] unless resource[:publish].nil?
4751
self.custom = resource[:custom] unless resource[:custom].nil?
4852
end
4953

5054
def check_args
51-
['handlers','command','interval','subscribers','type','standalone','high_flap_threshold','low_flap_threshold']
55+
['handlers','command','interval','subscribers','type','standalone','high_flap_threshold','low_flap_threshold','timeout','aggregate','handle','publish','custom']
5256
end
5357

5458
def custom
@@ -124,6 +128,80 @@ def high_flap_threshold=(value)
124128
conf['checks'][resource[:name]]['high_flap_threshold'] = value.to_i
125129
end
126130

131+
def timeout
132+
conf['checks'][resource[:name]]['timeout'].to_s
133+
end
134+
135+
def timeout=(value)
136+
conf['checks'][resource[:name]]['timeout'] = value.to_f
137+
end
138+
139+
def aggregate
140+
case conf['checks'][resource[:name]]['aggregate']
141+
when true
142+
:true
143+
when false
144+
:false
145+
else
146+
conf['checks'][resource[:name]]['aggregate']
147+
end
148+
end
149+
150+
def aggregate=(value)
151+
case value
152+
when true, 'true', 'True', :true, 1
153+
conf['checks'][resource[:name]]['aggregate'] = true
154+
when false, 'false', 'False', :false, 0
155+
conf['checks'][resource[:name]]['aggregate'] = false
156+
else
157+
conf['checks'][resource[:name]]['aggregate'] = value
158+
end
159+
end
160+
161+
def handle
162+
case conf['checks'][resource[:name]]['handle']
163+
when true
164+
:true
165+
when false
166+
:false
167+
else
168+
conf['checks'][resource[:name]]['handle']
169+
end
170+
end
171+
172+
def handle=(value)
173+
case value
174+
when true, 'true', 'True', :true, 1
175+
conf['checks'][resource[:name]]['handle'] = true
176+
when false, 'false', 'False', :false, 0
177+
conf['checks'][resource[:name]]['handle'] = false
178+
else
179+
conf['checks'][resource[:name]]['handle'] = value
180+
end
181+
end
182+
183+
def publish
184+
case conf['checks'][resource[:name]]['publish']
185+
when true
186+
:true
187+
when false
188+
:false
189+
else
190+
conf['checks'][resource[:name]]['publish']
191+
end
192+
end
193+
194+
def publish=(value)
195+
case value
196+
when true, 'true', 'True', :true, 1
197+
conf['checks'][resource[:name]]['publish'] = true
198+
when false, 'false', 'False', :false, 0
199+
conf['checks'][resource[:name]]['publish'] = false
200+
else
201+
conf['checks'][resource[:name]]['publish'] = value
202+
end
203+
end
204+
127205
def standalone
128206
case conf['checks'][resource[:name]]['standalone']
129207
when true

lib/puppet/type/sensu_check.rb

+16
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,22 @@ def insync?(is)
9393
newvalues(:true, :false)
9494
end
9595

96+
newproperty(:timeout) do
97+
desc "Check timeout in seconds, after it fails"
98+
end
99+
100+
newproperty(:aggregate) do
101+
desc "Whether check is aggregate"
102+
end
103+
104+
newproperty(:handle) do
105+
desc "Whether check event send to a handler"
106+
end
107+
108+
newproperty(:publish) do
109+
desc "Whether check is unpublished"
110+
end
111+
96112
autorequire(:package) do
97113
['sensu']
98114
end

manifests/check.pp

+38-9
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,39 @@
4040
# Integer. Flap detection - see Nagios Flap Detection: http://nagios.sourceforge.net/docs/3_0/flapping.html
4141
# Default: undef
4242
#
43+
# [*timeout*]
44+
# Integer. Check timeout in seconds, after it fails
45+
# Default: undef
46+
#
47+
# [*aggregate*]
48+
# Boolean. Aggregates, preventing event floods. Set 'aggregate:true and 'handle':false, this prevents the
49+
# server from sending to a handler, and makes the aggregated results available under /aggregates in the REST API
50+
# Default: undef
51+
#
52+
# [*handle*]
53+
# Boolean. When true, check will not be sent to handlers
54+
# Default: undef
55+
#
56+
# [*publish*]
57+
# Boolean. Unpublished checks. Prevents the check from being triggered on clients. This allows for the definition
58+
# of commands that are not actually 'checks' per say, but actually arbitrary commands for remediation
59+
# Default: undef
60+
#
4361
define sensu::check(
4462
$command,
45-
$ensure = 'present',
46-
$type = undef,
47-
$handlers = undef,
48-
$standalone = true,
49-
$interval = 60,
50-
$subscribers = [],
51-
$low_flap_threshold = undef,
52-
$high_flap_threshold = undef,
53-
$custom = undef,
63+
$ensure = 'present',
64+
$type = undef,
65+
$handlers = undef,
66+
$standalone = true,
67+
$interval = 60,
68+
$subscribers = [],
69+
$low_flap_threshold = undef,
70+
$high_flap_threshold = undef,
71+
$timeout = undef,
72+
$aggregate = undef,
73+
$handle = undef,
74+
$publish = undef,
75+
$custom = undef,
5476
) {
5577

5678
validate_re($ensure, ['^present$', '^absent$'] )
@@ -64,6 +86,9 @@
6486
if $high_flap_threshold and !is_integer($high_flap_threshold) {
6587
fail("sensu::check{${name}}: high_flap_threshold must be an integer (got: ${high_flap_threshold})")
6688
}
89+
if $timeout and !is_float($timeout) {
90+
fail("sensu::check{${name}}: timeout must be an float (got: ${timeout})")
91+
}
6792

6893
$check_name = regsubst(regsubst($name, ' ', '_', 'G'), '[\(\)]', '', 'G')
6994

@@ -85,6 +110,10 @@
85110
subscribers => $subscribers,
86111
low_flap_threshold => $low_flap_threshold,
87112
high_flap_threshold => $high_flap_threshold,
113+
timeout => $timeout,
114+
aggregate => $aggregate,
115+
handle => $handle,
116+
publish => $publish,
88117
custom => $custom,
89118
require => File['/etc/sensu/conf.d/checks'],
90119
notify => [ Class['sensu::client::service'], Class['sensu::server::service'] ],

spec/defines/sensu_check_spec.rb

+18-10
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,19 @@
1818

1919
context 'setting params' do
2020
let(:params) { {
21-
:command => '/etc/sensu/command2.rb',
22-
:handlers => ['/handler1', '/handler2'],
23-
:interval => 10,
24-
:subscribers => ['all'],
25-
:custom => { 'a' => 'b', 'array' => [ 'c', 'd']},
26-
:type => 'metric',
27-
:standalone => true,
28-
:low_flap_threshold => 10,
29-
:high_flap_threshold => 15
21+
:command => '/etc/sensu/command2.rb',
22+
:handlers => ['/handler1', '/handler2'],
23+
:interval => 10,
24+
:subscribers => ['all'],
25+
:custom => { 'a' => 'b', 'array' => [ 'c', 'd']},
26+
:type => 'metric',
27+
:standalone => true,
28+
:low_flap_threshold => 10,
29+
:high_flap_threshold => 15,
30+
:timeout => 0.5,
31+
:aggregate => true,
32+
:handle => true,
33+
:publish => true
3034
} }
3135

3236
it { should contain_sensu_check('mycheck').with(
@@ -38,7 +42,11 @@
3842
:type => 'metric',
3943
:standalone => true,
4044
:low_flap_threshold => 10,
41-
:high_flap_threshold => 15
45+
:high_flap_threshold => 15,
46+
:timeout => 0.5,
47+
:aggregate => true,
48+
:handle => true,
49+
:publish => true
4250
) }
4351
end
4452

0 commit comments

Comments
 (0)