forked from sensu/sensu-puppet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck.pp
238 lines (232 loc) · 8.55 KB
/
check.pp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
# = Define: sensu::check
#
# Defines Sensu checks
#
# == Parameters
#
# [*command*]
# String. The check command to run
#
# [*ensure*]
# String. Whether the check should be present or not
# Default: present
# Valid values: present, absent
#
# [*type*]
# String. Type of check
# Set this to 'absent' to remove it completely.
# Default: undef
#
# [*handlers*]
# Array of Strings. Handlers to use for this check
# Set this to 'absent' to remove it completely.
# Default: undef
#
# [*standalone*]
# Boolean. When true, scheduled by the client. When false, listen for published check request
# Set this to 'absent' to remove it completely.
# Default: true
#
# [*interval*]
# Integer. How frequently (in seconds) the check will be executed
# Set this to 'absent' to remove it completely.
# Default: 60
#
# [*occurrences*]
# Integer. The number of event occurrences before the handler should take action.
# Set this to 'absent' to remove it completely.
# Default: undef
#
# [*refresh*]
# Integer. The number of seconds sensu-plugin-aware handlers should wait before taking second action.
# Set this to 'absent' to remove it completely.
# Default: undef
#
# [*source*]
# String. The check source, used to create a JIT Sensu client for an external resource (e.g. a network switch).
# Set this to 'absent' to remove it completely.
# Default: undef
#
# [*subscribers*]
# Array of Strings. Which subscriptions must execute this check
# Set this to 'absent' to remove it completely.
# Default: undef
#
# [*low_flap_threshold*]
# Integer. Flap detection - see Nagios Flap Detection: http://nagios.sourceforge.net/docs/3_0/flapping.html
# Set this to 'absent' to remove it completely.
# Default: undef
#
# [*high_flap_threshold*]
# Integer. Flap detection - see Nagios Flap Detection: http://nagios.sourceforge.net/docs/3_0/flapping.html
# Set this to 'absent' to remove it completely.
# Default: undef
#
# [*timeout*]
# Numeric. Check timeout in seconds, after it fails
# Set this to 'absent' to remove it completely.
# Default: undef
#
# [*aggregate*]
# String. Aggregates, preventing event floods. Set 'aggregate:<name> and 'handle':false, this prevents the
# server from sending to a handler, and makes the aggregated results available under /aggregates in the REST API
# Set this to 'absent' to remove it completely.
# Default: undef
#
# [*aggregates*]
# Array of Strings. An array of aggregates to add to the check. This supercedes the above aggregate parameter
# Set this to 'absent' to remove it completely.
# Defaults: undef
#
# [*handle*]
# Boolean. When false, check will not be sent to handlers
# Set this to 'absent' to remove it completely.
# Default: undef
#
# [*publish*]
# Boolean. Unpublished checks. Prevents the check from being triggered on clients. This allows for the definition
# of commands that are not actually 'checks' per say, but actually arbitrary commands for remediation
# Set this to 'absent' to remove it completely.
# Default: undef
#
# [*dependencies*]
# Array. List of checks this check depends on. Note: The validity of the other checks is not enforced by puppet
# Set this to 'absent' to remove it completely.
# Default: undef
#
# [*ttl*]
# Integer. The time to live (TTL) in seconds until check results are considered stale.
# Set this to 'absent' to remove it completely.
# Default: undef
#
# [*subdue*]
# Hash. Check subdue configuration
# Set this to 'absent' to remove it completely.
# Default: undef
#
define sensu::check(
$command,
$ensure = 'present',
$type = undef,
$handlers = undef,
$standalone = true,
$interval = 60,
$occurrences = undef,
$refresh = undef,
$source = undef,
$subscribers = undef,
$low_flap_threshold = undef,
$high_flap_threshold = undef,
$timeout = undef,
$aggregate = undef,
$aggregates = undef,
$handle = undef,
$publish = undef,
$dependencies = undef,
$custom = undef,
$ttl = undef,
$subdue = undef,
) {
validate_re($ensure, ['^present$', '^absent$'] )
if !is_bool($standalone) and $standalone != 'absent' {
fail("sensu::check{${name}}: standalone must be a boolean or 'absent' (got: ${standalone})")
}
if $handle and !is_bool($handle) and $handle != 'absent' {
fail("sensu::check{${name}}: handle must be a boolean or 'absent' (got: ${handle})")
}
if $publish and !is_bool($publish) and $publish != 'absent' {
fail("sensu::check{${name}}: publish must be a boolean or 'absent' (got: ${publish})")
}
if !is_integer($interval) and $interval != 'absent' {
fail("sensu::check{${name}}: interval must be an integer or 'absent' (got: ${interval})")
}
if $occurrences and !is_integer($occurrences) and $occurrences != 'absent' {
fail("sensu::check{${name}}: occurrences must be an integer or 'absent' (got: ${occurrences})")
}
if $refresh and !is_integer($refresh) and $refresh != 'absent' {
fail("sensu::check{${name}}: refresh must be an integer or 'absent' (got: ${refresh})")
}
if $low_flap_threshold and !is_integer($low_flap_threshold) and $low_flap_threshold != 'absent' {
fail("sensu::check{${name}}: low_flap_threshold must be an integer or 'absent' (got: ${low_flap_threshold})")
}
if $high_flap_threshold and !is_integer($high_flap_threshold) and $high_flap_threshold != 'absent' {
fail("sensu::check{${name}}: high_flap_threshold must be an integer or 'absent' (got: ${high_flap_threshold})")
}
if $timeout and !is_numeric($timeout) and $timeout != 'absent' {
fail("sensu::check{${name}}: timeout must be a numeric or 'absent' (got: ${timeout})")
}
if $ttl and !is_integer($ttl) and $ttl != 'absent' {
fail("sensu::check{${name}}: ttl must be an integer or 'absent' (got: ${ttl})")
}
if $dependencies and !is_array($dependencies) and !is_string($dependencies) {
fail("sensu::check{${name}}: dependencies must be an array or a string (got: ${dependencies})")
}
if $handlers and !is_array($handlers) and !is_string($handlers) {
fail("sensu::check{${name}}: handlers must be an array or a string (got: ${handlers})")
}
if $subscribers and !is_array($subscribers) and !is_string($subscribers) {
fail("sensu::check{${name}}: subscribers must be an array or a string (got: ${subscribers})")
}
if $subdue {
if is_hash($subdue) {
if !( has_key($subdue, 'days') and is_hash($subdue['days']) ){
fail("sensu::check{${name}}: subdue hash should have a proper format. (got: ${subdue}) See https://sensuapp.org/docs/latest/reference/checks.html#subdue-attributes")
}
} elsif !($subdue == 'absent') {
fail("sensu::check{${name}}: subdue must be a hash or 'absent' (got: ${subdue})")
}
}
if $aggregates and !is_array($aggregates) and !is_string($aggregates) {
fail("sensu::check{${name}}: aggregates must be an array or a string (got: ${aggregates})")
}
$check_name = regsubst(regsubst($name, ' ', '_', 'G'), '[\(\)]', '', 'G')
case $::osfamily {
'windows': {
$etc_dir = 'C:/opt/sensu'
$conf_dir = "${etc_dir}/conf.d"
$user = undef
$group = undef
$file_mode = undef
}
default: {
$etc_dir = '/etc/sensu'
$conf_dir = "${etc_dir}/conf.d"
$user = 'sensu'
$group = 'sensu'
$file_mode = '0440'
}
}
file { "${conf_dir}/checks/${check_name}.json":
ensure => $ensure,
owner => $user,
group => $group,
mode => $file_mode,
before => Sensu_check[$check_name],
}
sensu_check { $check_name:
ensure => $ensure,
base_path => "${conf_dir}/checks",
type => $type,
standalone => $standalone,
command => $command,
handlers => $handlers,
interval => $interval,
occurrences => $occurrences,
refresh => $refresh,
source => $source,
subscribers => $subscribers,
low_flap_threshold => $low_flap_threshold,
high_flap_threshold => $high_flap_threshold,
timeout => $timeout,
aggregate => $aggregate,
aggregates => $aggregates,
handle => $handle,
publish => $publish,
dependencies => $dependencies,
custom => $custom,
subdue => $subdue,
require => File["${conf_dir}/checks"],
notify => $::sensu::check_notify,
ttl => $ttl,
}
}