portertech-sensu-settings 10.18.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE.txt +20 -0
- data/README.md +28 -0
- data/lib/sensu/settings/constants.rb +5 -0
- data/lib/sensu/settings/loader.rb +502 -0
- data/lib/sensu/settings/rules.rb +166 -0
- data/lib/sensu/settings/validator.rb +88 -0
- data/lib/sensu/settings/validators/api.rb +65 -0
- data/lib/sensu/settings/validators/check.rb +253 -0
- data/lib/sensu/settings/validators/client.rb +238 -0
- data/lib/sensu/settings/validators/extension.rb +18 -0
- data/lib/sensu/settings/validators/filter.rb +27 -0
- data/lib/sensu/settings/validators/handler.rb +132 -0
- data/lib/sensu/settings/validators/mutator.rb +18 -0
- data/lib/sensu/settings/validators/sensu.rb +102 -0
- data/lib/sensu/settings/validators/tessen.rb +22 -0
- data/lib/sensu/settings/validators/time_window.rb +74 -0
- data/lib/sensu/settings/validators/transport.rb +22 -0
- data/lib/sensu/settings/validators.rb +29 -0
- data/lib/sensu/settings.rb +52 -0
- data/sensu-settings.gemspec +24 -0
- metadata +133 -0
@@ -0,0 +1,238 @@
|
|
1
|
+
module Sensu
|
2
|
+
module Settings
|
3
|
+
module Validators
|
4
|
+
module Client
|
5
|
+
# Validate client subscriptions.
|
6
|
+
# Validates: subscriptions
|
7
|
+
#
|
8
|
+
# @param client [Hash] sensu client definition.
|
9
|
+
def validate_client_subscriptions(client)
|
10
|
+
if is_an_array?(client[:subscriptions])
|
11
|
+
items_must_be_strings(client[:subscriptions]) ||
|
12
|
+
invalid(client, "client subscriptions must each be a non empty string")
|
13
|
+
else
|
14
|
+
invalid(client, "client subscriptions must be an array")
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
# Validate client safe mode.
|
19
|
+
# Validates: safe_mode
|
20
|
+
#
|
21
|
+
# @param client [Hash] sensu client definition.
|
22
|
+
def validate_client_safe_mode(client)
|
23
|
+
must_be_boolean_if_set(client[:safe_mode]) ||
|
24
|
+
invalid(client, "client safe_mode must be boolean")
|
25
|
+
end
|
26
|
+
|
27
|
+
# Validate client socket.
|
28
|
+
# Validates: socket (enabled, bind, port)
|
29
|
+
#
|
30
|
+
# @param client [Hash] sensu client definition.
|
31
|
+
def validate_client_socket(client)
|
32
|
+
must_be_a_hash_if_set(client[:socket]) ||
|
33
|
+
invalid(client, "client socket must be a hash")
|
34
|
+
if is_a_hash?(client[:socket])
|
35
|
+
must_be_boolean_if_set(client[:socket][:enabled]) ||
|
36
|
+
invalid(client, "client socket enabled must be a boolean")
|
37
|
+
must_be_a_string_if_set(client[:socket][:bind]) ||
|
38
|
+
invalid(client, "client socket bind must be a string")
|
39
|
+
must_be_an_integer_if_set(client[:socket][:port]) ||
|
40
|
+
invalid(client, "client socket port must be an integer")
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
# Validate client http_socket.
|
45
|
+
# Validates: http_socket (enabled, bind, port, user, password, protect_all_endpoints)
|
46
|
+
#
|
47
|
+
# @param client [Hash] sensu client definition.
|
48
|
+
def validate_client_http_socket(client)
|
49
|
+
http_socket = client[:http_socket]
|
50
|
+
must_be_a_hash_if_set(http_socket) ||
|
51
|
+
invalid(client, "client http_socket must be a hash")
|
52
|
+
if is_a_hash?(http_socket)
|
53
|
+
must_be_boolean_if_set(http_socket[:enabled]) ||
|
54
|
+
invalid(client, "client http_socket enabled must be boolean")
|
55
|
+
must_be_a_string_if_set(http_socket[:bind]) ||
|
56
|
+
invalid(client, "client http_socket bind must be a string")
|
57
|
+
must_be_an_integer_if_set(http_socket[:port]) ||
|
58
|
+
invalid(client, "client http_socket port must be an integer")
|
59
|
+
if either_are_set?(http_socket[:user], http_socket[:password])
|
60
|
+
must_be_a_string(http_socket[:user]) ||
|
61
|
+
invalid(client, "client http_socket user must be a string")
|
62
|
+
must_be_a_string(http_socket[:password]) ||
|
63
|
+
invalid(client, "client http_socket password must be a string")
|
64
|
+
end
|
65
|
+
must_be_boolean_if_set(http_socket[:protect_all_endpoints]) ||
|
66
|
+
invalid(client, "client http_socket protect_all_endpoints must be boolean")
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
# Validate client keepalives.
|
71
|
+
# Validates: keepalives
|
72
|
+
#
|
73
|
+
# @param client [Hash] sensu client definition.
|
74
|
+
def validate_client_keepalives(client)
|
75
|
+
must_be_boolean_if_set(client[:keepalives]) ||
|
76
|
+
invalid(client, "client keepalives must be boolean")
|
77
|
+
end
|
78
|
+
|
79
|
+
# Validate client keepalive handlers.
|
80
|
+
# Validates: keepalive (handler, handlers)
|
81
|
+
#
|
82
|
+
# @param client [Hash] sensu client definition.
|
83
|
+
def validate_client_keepalive_handlers(client)
|
84
|
+
must_be_a_string_if_set(client[:keepalive][:handler]) ||
|
85
|
+
invalid(client, "client keepalive handler must be a string")
|
86
|
+
must_be_an_array_if_set(client[:keepalive][:handlers]) ||
|
87
|
+
invalid(client, "client keepalive handlers must be an array")
|
88
|
+
if is_an_array?(client[:keepalive][:handlers])
|
89
|
+
items_must_be_strings(client[:keepalive][:handlers]) ||
|
90
|
+
invalid(client, "client keepalive handlers must each be a string")
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
# Validate client keepalive thresholds.
|
95
|
+
# Validates: keepalive (thresholds)
|
96
|
+
#
|
97
|
+
# @param client [Hash] sensu client definition.
|
98
|
+
def validate_client_keepalive_thresholds(client)
|
99
|
+
thresholds = client[:keepalive][:thresholds]
|
100
|
+
must_be_a_hash_if_set(thresholds) ||
|
101
|
+
invalid(client, "client keepalive thresholds must be a hash")
|
102
|
+
if is_a_hash?(thresholds)
|
103
|
+
must_be_an_integer_if_set(thresholds[:warning]) ||
|
104
|
+
invalid(client, "client keepalive warning threshold must be an integer")
|
105
|
+
must_be_an_integer_if_set(thresholds[:critical]) ||
|
106
|
+
invalid(client, "client keepalive critical threshold must be an integer")
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
# Validate client keepalive.
|
111
|
+
# Validates: keepalive
|
112
|
+
#
|
113
|
+
# @param client [Hash] sensu client definition.
|
114
|
+
def validate_client_keepalive(client)
|
115
|
+
must_be_a_hash_if_set(client[:keepalive]) ||
|
116
|
+
invalid(client, "client keepalive must be a hash")
|
117
|
+
if is_a_hash?(client[:keepalive])
|
118
|
+
validate_client_keepalive_handlers(client)
|
119
|
+
validate_client_keepalive_thresholds(client)
|
120
|
+
# A client keepalive may include several check attributes.
|
121
|
+
# Validation is necessary, although the validation failure
|
122
|
+
# messages may be a bit confusing.
|
123
|
+
validate_check_source(client[:keepalive]) if client[:keepalive][:source]
|
124
|
+
validate_check_aggregate(client[:keepalive])
|
125
|
+
validate_check_flap_detection(client[:keepalive])
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
# Validate client redact.
|
130
|
+
# Validates: redact
|
131
|
+
#
|
132
|
+
# @param client [Hash] sensu client definition.
|
133
|
+
def validate_client_redact(client)
|
134
|
+
must_be_an_array_if_set(client[:redact]) ||
|
135
|
+
invalid(client, "client redact must be an array")
|
136
|
+
if is_an_array?(client[:redact])
|
137
|
+
items_must_be_strings(client[:redact]) ||
|
138
|
+
invalid(client, "client redact keys must each be a string")
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
# Validate client signature.
|
143
|
+
# Validates: signature
|
144
|
+
#
|
145
|
+
# @param client [Hash] sensu client definition.
|
146
|
+
def validate_client_signature(client)
|
147
|
+
must_be_a_string_if_set(client[:signature]) ||
|
148
|
+
invalid(client, "client signature must be a string")
|
149
|
+
end
|
150
|
+
|
151
|
+
# Validate client registration handlers.
|
152
|
+
# Validates: registration (handler, handlers)
|
153
|
+
#
|
154
|
+
# @param client [Hash] sensu client definition.
|
155
|
+
def validate_client_registration_handlers(client)
|
156
|
+
must_be_a_string_if_set(client[:registration][:handler]) ||
|
157
|
+
invalid(client, "client registration handler must be a string")
|
158
|
+
must_be_an_array_if_set(client[:registration][:handlers]) ||
|
159
|
+
invalid(client, "client registration handlers must be an array")
|
160
|
+
if is_an_array?(client[:registration][:handlers])
|
161
|
+
items_must_be_strings(client[:registration][:handlers]) ||
|
162
|
+
invalid(client, "client registration handlers must each be a string")
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
# Validate client registration.
|
167
|
+
# Validates: registration
|
168
|
+
#
|
169
|
+
# @param client [Hash] sensu client definition.
|
170
|
+
def validate_client_registration(client)
|
171
|
+
must_be_a_hash_if_set(client[:registration]) ||
|
172
|
+
invalid(client, "client registration must be a hash")
|
173
|
+
if is_a_hash?(client[:registration])
|
174
|
+
validate_client_registration_handlers(client)
|
175
|
+
must_be_an_integer_if_set(client[:registration][:status]) ||
|
176
|
+
invalid(client, "client registration status must be an integer")
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
180
|
+
# Validate client deregistration handlers.
|
181
|
+
# Validates: deregistration (handler, handlers)
|
182
|
+
#
|
183
|
+
# @param client [Hash] sensu client definition.
|
184
|
+
def validate_client_deregistration_handlers(client)
|
185
|
+
must_be_a_string_if_set(client[:deregistration][:handler]) ||
|
186
|
+
invalid(client, "client deregistration handler must be a string")
|
187
|
+
must_be_an_array_if_set(client[:deregistration][:handlers]) ||
|
188
|
+
invalid(client, "client deregistration handlers must be an array")
|
189
|
+
if is_an_array?(client[:deregistration][:handlers])
|
190
|
+
items_must_be_strings(client[:deregistration][:handlers]) ||
|
191
|
+
invalid(client, "client deregistration handlers must each be a string")
|
192
|
+
end
|
193
|
+
end
|
194
|
+
|
195
|
+
# Validate client deregistration.
|
196
|
+
# Validates: deregistration
|
197
|
+
#
|
198
|
+
# @param client [Hash] sensu client definition.
|
199
|
+
def validate_client_deregistration(client)
|
200
|
+
must_be_a_hash_if_set(client[:deregistration]) ||
|
201
|
+
invalid(client, "client deregistration must be a hash")
|
202
|
+
if is_a_hash?(client[:deregistration])
|
203
|
+
validate_client_deregistration_handlers(client)
|
204
|
+
must_be_an_integer_if_set(client[:deregistration][:status]) ||
|
205
|
+
invalid(client, "client deregistration status must be an integer")
|
206
|
+
end
|
207
|
+
end
|
208
|
+
|
209
|
+
# Validate a Sensu client definition.
|
210
|
+
# Validates: name, address, safe_mode
|
211
|
+
#
|
212
|
+
# @param client [Hash] sensu client definition.
|
213
|
+
def validate_client(client)
|
214
|
+
must_be_a_hash(client) ||
|
215
|
+
invalid(client, "client must be a hash")
|
216
|
+
if is_a_hash?(client)
|
217
|
+
must_be_a_string(client[:name]) ||
|
218
|
+
invalid(client, "client name must be a string")
|
219
|
+
must_match_regex(/\A[\w\.-]+\z/, client[:name]) ||
|
220
|
+
invalid(client, "client name cannot contain spaces or special characters")
|
221
|
+
must_be_a_string(client[:address]) ||
|
222
|
+
invalid(client, "client address must be a string")
|
223
|
+
validate_client_safe_mode(client)
|
224
|
+
validate_client_subscriptions(client)
|
225
|
+
validate_client_socket(client)
|
226
|
+
validate_client_http_socket(client)
|
227
|
+
validate_client_keepalives(client)
|
228
|
+
validate_client_keepalive(client)
|
229
|
+
validate_client_redact(client)
|
230
|
+
validate_client_signature(client)
|
231
|
+
validate_client_registration(client)
|
232
|
+
validate_client_deregistration(client)
|
233
|
+
end
|
234
|
+
end
|
235
|
+
end
|
236
|
+
end
|
237
|
+
end
|
238
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Sensu
|
2
|
+
module Settings
|
3
|
+
module Validators
|
4
|
+
module Extension
|
5
|
+
# Validate a Sensu extension definition.
|
6
|
+
# Validates: gem, version
|
7
|
+
#
|
8
|
+
# @param filter [Hash] sensu extension definition.
|
9
|
+
def validate_extension(extension)
|
10
|
+
must_be_a_string_if_set(extension[:gem]) ||
|
11
|
+
invalid(extension, "extension gem must be a string")
|
12
|
+
must_be_a_string_if_set(extension[:version]) ||
|
13
|
+
invalid(extension, "extension version must be a string")
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Sensu
|
2
|
+
module Settings
|
3
|
+
module Validators
|
4
|
+
module Filter
|
5
|
+
# Validate filter when.
|
6
|
+
# Validates: when
|
7
|
+
#
|
8
|
+
# @param filter [Hash] sensu filter definition.
|
9
|
+
def validate_filter_when(filter)
|
10
|
+
validate_time_windows(filter, "filter", :when)
|
11
|
+
end
|
12
|
+
|
13
|
+
# Validate a Sensu filter definition.
|
14
|
+
# Validates: attributes, negate
|
15
|
+
#
|
16
|
+
# @param filter [Hash] sensu filter definition.
|
17
|
+
def validate_filter(filter)
|
18
|
+
must_be_boolean_if_set(filter[:negate]) ||
|
19
|
+
invalid(filter, "filter negate must be boolean")
|
20
|
+
must_be_a_hash(filter[:attributes]) ||
|
21
|
+
invalid(filter, "filter attributes must be a hash")
|
22
|
+
validate_filter_when(filter) if filter[:when]
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,132 @@
|
|
1
|
+
module Sensu
|
2
|
+
module Settings
|
3
|
+
module Validators
|
4
|
+
module Handler
|
5
|
+
# Validate pipe handler.
|
6
|
+
# Validates: command
|
7
|
+
#
|
8
|
+
# @param handler [Hash] sensu handler definition.
|
9
|
+
def validate_pipe_handler(handler)
|
10
|
+
must_be_a_string(handler[:command]) ||
|
11
|
+
invalid(handler, "handler command must be a string")
|
12
|
+
end
|
13
|
+
|
14
|
+
# Validate socket (tcp/udp) handler.
|
15
|
+
# Validates: socket (host, port)
|
16
|
+
#
|
17
|
+
# @param handler [Hash] sensu handler definition.
|
18
|
+
def validate_socket_handler(handler)
|
19
|
+
socket = handler[:socket]
|
20
|
+
if is_a_hash?(socket)
|
21
|
+
must_be_a_string(socket[:host]) ||
|
22
|
+
invalid(handler, "handler host must be a string")
|
23
|
+
must_be_an_integer(socket[:port]) ||
|
24
|
+
invalid(handler, "handler port must be an integer")
|
25
|
+
else
|
26
|
+
invalid(handler, "handler socket must be a hash")
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
# Validate transport handler.
|
31
|
+
# Validates: pipe (type, name, options)
|
32
|
+
#
|
33
|
+
# @param handler [Hash] sensu handler definition.
|
34
|
+
def validate_transport_handler(handler)
|
35
|
+
pipe = handler[:pipe]
|
36
|
+
if is_a_hash?(pipe)
|
37
|
+
must_be_a_string(pipe[:type]) ||
|
38
|
+
invalid(handler, "handler transport pipe type must be a string")
|
39
|
+
must_be_either(%w[direct fanout topic], pipe[:type]) ||
|
40
|
+
invalid(handler, "handler transport pipe type is invalid")
|
41
|
+
must_be_a_string(pipe[:name]) ||
|
42
|
+
invalid(handler, "handler transport pipe name must be a string")
|
43
|
+
must_be_a_hash_if_set(pipe[:options]) ||
|
44
|
+
invalid(handler, "handler transport pipe options must be a hash")
|
45
|
+
else
|
46
|
+
invalid(handler, "handler transport pipe must be a hash")
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
# Validate set handler.
|
51
|
+
# Validates: handlers
|
52
|
+
#
|
53
|
+
# @param handler [Hash] sensu handler definition.
|
54
|
+
def validate_set_handler(handler)
|
55
|
+
if is_an_array?(handler[:handlers])
|
56
|
+
items_must_be_strings(handler[:handlers]) ||
|
57
|
+
invalid(handler, "handler set handlers must each be a string")
|
58
|
+
else
|
59
|
+
invalid(handler, "handler set handlers must be an array")
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
# Validate handler type.
|
64
|
+
# Validates: type
|
65
|
+
#
|
66
|
+
# @param handler [Hash] sensu handler definition.
|
67
|
+
def validate_handler_type(handler)
|
68
|
+
must_be_a_string(handler[:type]) ||
|
69
|
+
invalid(handler, "handler type must be a string")
|
70
|
+
case handler[:type]
|
71
|
+
when "pipe"
|
72
|
+
validate_pipe_handler(handler)
|
73
|
+
when "tcp", "udp"
|
74
|
+
validate_socket_handler(handler)
|
75
|
+
when "transport"
|
76
|
+
validate_transport_handler(handler)
|
77
|
+
when "set"
|
78
|
+
validate_set_handler(handler)
|
79
|
+
else
|
80
|
+
invalid(handler, "unknown handler type")
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
# Validate handler filtering.
|
85
|
+
# Validates: filter, filters
|
86
|
+
#
|
87
|
+
# @param handler [Hash] sensu handler definition.
|
88
|
+
def validate_handler_filtering(handler)
|
89
|
+
must_be_an_array_if_set(handler[:filters]) ||
|
90
|
+
invalid(handler, "handler filters must be an array")
|
91
|
+
if is_an_array?(handler[:filters])
|
92
|
+
items_must_be_strings(handler[:filters]) ||
|
93
|
+
invalid(handler, "handler filters items must be strings")
|
94
|
+
end
|
95
|
+
must_be_a_string_if_set(handler[:filter]) ||
|
96
|
+
invalid(handler, "handler filter must be a string")
|
97
|
+
end
|
98
|
+
|
99
|
+
# Validate handler severities.
|
100
|
+
# Validates: severities
|
101
|
+
#
|
102
|
+
# @param handler [Hash] sensu handler definition.
|
103
|
+
def validate_handler_severities(handler)
|
104
|
+
must_be_an_array_if_set(handler[:severities]) ||
|
105
|
+
invalid(handler, "handler severities must be an array")
|
106
|
+
if is_an_array?(handler[:severities])
|
107
|
+
must_be_either(%w[ok warning critical unknown], handler[:severities]) ||
|
108
|
+
invalid(handler, "handler severities are invalid")
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
# Validate a Sensu handler definition.
|
113
|
+
# Validates: timeout, mutator, handle_flapping, handle_silenced
|
114
|
+
#
|
115
|
+
# @param handler [Hash] sensu handler definition.
|
116
|
+
def validate_handler(handler)
|
117
|
+
validate_handler_type(handler)
|
118
|
+
validate_handler_filtering(handler)
|
119
|
+
validate_handler_severities(handler)
|
120
|
+
must_be_a_numeric_if_set(handler[:timeout]) ||
|
121
|
+
invalid(handler, "handler timeout must be numeric")
|
122
|
+
must_be_a_string_if_set(handler[:mutator]) ||
|
123
|
+
invalid(handler, "handler mutator must be a string")
|
124
|
+
must_be_boolean_if_set(handler[:handle_flapping]) ||
|
125
|
+
invalid(handler, "handler handle_flapping must be boolean")
|
126
|
+
must_be_boolean_if_set(handler[:handle_silenced]) ||
|
127
|
+
invalid(handler, "handler handle_silenced must be boolean")
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Sensu
|
2
|
+
module Settings
|
3
|
+
module Validators
|
4
|
+
module Mutator
|
5
|
+
# Validate a Sensu mutator definition.
|
6
|
+
# Validates: command, timeout
|
7
|
+
#
|
8
|
+
# @param mutator [Hash] sensu mutator definition.
|
9
|
+
def validate_mutator(mutator)
|
10
|
+
must_be_a_string(mutator[:command]) ||
|
11
|
+
invalid(mutator, "mutator command must be a string")
|
12
|
+
must_be_a_numeric_if_set(mutator[:timeout]) ||
|
13
|
+
invalid(mutator, "mutator timeout must be numeric")
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,102 @@
|
|
1
|
+
module Sensu
|
2
|
+
module Settings
|
3
|
+
module Validators
|
4
|
+
module Sensu
|
5
|
+
# Validate Sensu spawn.
|
6
|
+
# Validates: limit
|
7
|
+
#
|
8
|
+
# @param sensu [Hash] sensu definition.
|
9
|
+
def validate_sensu_spawn(sensu)
|
10
|
+
spawn = sensu[:spawn]
|
11
|
+
if is_a_hash?(spawn)
|
12
|
+
if is_an_integer?(spawn[:limit])
|
13
|
+
spawn[:limit] > 0 ||
|
14
|
+
invalid(sensu, "sensu spawn limit must be greater than 0")
|
15
|
+
else
|
16
|
+
invalid(sensu, "sensu spawn limit must be an integer")
|
17
|
+
end
|
18
|
+
else
|
19
|
+
invalid(sensu, "sensu spawn must be a hash")
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
# Validate Sensu keepalives thresholds.
|
24
|
+
# Validates: warning, critical
|
25
|
+
#
|
26
|
+
# @param sensu [Hash] sensu definition.
|
27
|
+
def validate_sensu_keepalives_thresholds(sensu)
|
28
|
+
thresholds = sensu[:keepalives][:thresholds]
|
29
|
+
must_be_a_hash_if_set(thresholds) ||
|
30
|
+
invalid(sensu, "sensu keepalives thresholds must be a hash")
|
31
|
+
if is_a_hash?(thresholds)
|
32
|
+
must_be_an_integer_if_set(thresholds[:warning]) ||
|
33
|
+
invalid(sensu, "sensu keepalives warning threshold must be an integer")
|
34
|
+
must_be_an_integer_if_set(thresholds[:critical]) ||
|
35
|
+
invalid(sensu, "sensu keepalives critical threshold must be an integer")
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
# Validate Sensu keepalives handlers.
|
40
|
+
# Validates: handler, handlers
|
41
|
+
#
|
42
|
+
# @param sensu [Hash] sensu definition.
|
43
|
+
def validate_sensu_keepalives_handlers(sensu)
|
44
|
+
must_be_a_string_if_set(sensu[:keepalives][:handler]) ||
|
45
|
+
invalid(sensu, "sensu keepalives handler must be a string")
|
46
|
+
must_be_an_array_if_set(sensu[:keepalives][:handlers]) ||
|
47
|
+
invalid(sensu, "sensu keepalives handlers must be an array")
|
48
|
+
if is_an_array?(sensu[:keepalives][:handlers])
|
49
|
+
items_must_be_strings(sensu[:keepalives][:handlers]) ||
|
50
|
+
invalid(sensu, "sensu keepalives handlers must each be a string")
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
# Validate Sensu keepalives.
|
55
|
+
# Validates: thresholds (warning, critical), handler, handlers
|
56
|
+
#
|
57
|
+
# @param sensu [Hash] sensu definition.
|
58
|
+
def validate_sensu_keepalives(sensu)
|
59
|
+
if is_a_hash?(sensu[:keepalives])
|
60
|
+
validate_sensu_keepalives_thresholds(sensu)
|
61
|
+
validate_sensu_keepalives_handlers(sensu)
|
62
|
+
else
|
63
|
+
invalid(sensu, "sensu keepalives must be a hash")
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
# Validate Sensu server.
|
68
|
+
# Validates: server results_pipe, keepalives_pipe
|
69
|
+
#
|
70
|
+
# @param sensu [Hash] sensu definition.
|
71
|
+
def validate_sensu_server(sensu)
|
72
|
+
if is_a_hash?(sensu[:server])
|
73
|
+
must_be_a_string_if_set(sensu[:server][:results_pipe]) ||
|
74
|
+
invalid(sensu, "sensu server results_pipe must be a string")
|
75
|
+
must_be_a_string_if_set(sensu[:server][:keepalives_pipe]) ||
|
76
|
+
invalid(sensu, "sensu server keepalives_pipe must be a string")
|
77
|
+
must_be_an_integer_if_set(sensu[:server][:max_message_size]) ||
|
78
|
+
invalid(sensu, "sensu server max_message_size must be an integer")
|
79
|
+
else
|
80
|
+
invalid(sensu, "sensu server must be a hash")
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
# Validate a Sensu definition.
|
85
|
+
# Validates: spawn, keepalives
|
86
|
+
#
|
87
|
+
# @param sensu [Hash] sensu definition.
|
88
|
+
def validate_sensu(sensu)
|
89
|
+
if is_a_hash?(sensu)
|
90
|
+
validate_sensu_spawn(sensu)
|
91
|
+
validate_sensu_keepalives(sensu)
|
92
|
+
validate_sensu_server(sensu) if sensu[:server]
|
93
|
+
must_be_boolean_if_set(sensu[:global_error_handler]) ||
|
94
|
+
invalid(sensu, "sensu global_error_handler must be boolean")
|
95
|
+
else
|
96
|
+
invalid(sensu, "sensu must be a hash")
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Sensu
|
2
|
+
module Settings
|
3
|
+
module Validators
|
4
|
+
module Tessen
|
5
|
+
# Validate a Tessen definition.
|
6
|
+
# Validates: enabled, identity_key
|
7
|
+
#
|
8
|
+
# @param tessen [Hash] tessen definition.
|
9
|
+
def validate_tessen(tessen)
|
10
|
+
must_be_a_hash_if_set(tessen) ||
|
11
|
+
invalid(tessen, "tessen must be a hash")
|
12
|
+
if is_a_hash?(tessen)
|
13
|
+
must_be_boolean_if_set(tessen[:enabled]) ||
|
14
|
+
invalid(tessen, "tessen enabled must be boolean")
|
15
|
+
must_be_a_string_if_set(tessen[:identity_key]) ||
|
16
|
+
invalid(tessen, "tessen identity_key must be a string")
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
module Sensu
|
2
|
+
module Settings
|
3
|
+
module Validators
|
4
|
+
module TimeWindow
|
5
|
+
# Validate time window condition
|
6
|
+
# Validates: begin, end
|
7
|
+
#
|
8
|
+
# @param definition [Hash] sensu definition.
|
9
|
+
# @param scope [String] definition scope to validate.
|
10
|
+
# @param attribute [String] definition attribute to validate.
|
11
|
+
# @param condition [Hash] to have begin and end validated.
|
12
|
+
def validate_time_window_condition(definition, scope, attribute, condition)
|
13
|
+
if is_a_hash?(condition)
|
14
|
+
must_be_time(condition[:begin], condition[:end]) ||
|
15
|
+
invalid(definition, "#{scope} #{attribute} day time window begin and end times must be valid")
|
16
|
+
else
|
17
|
+
invalid(definition, "#{scope} #{attribute} day time window must be a hash")
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
# Validate time windows days
|
22
|
+
# Validates: days
|
23
|
+
#
|
24
|
+
# @param definition [Hash] sensu definition.
|
25
|
+
# @param scope [String] definition scope to validate.
|
26
|
+
# @param attribute [String] definition attribute to validate.
|
27
|
+
# @param days [String] time window days to validate.
|
28
|
+
def validate_time_windows_days(definition, scope, attribute, days)
|
29
|
+
valid_days = [:all, :sunday, :monday, :tuesday, :wednesday, :thursday, :friday, :saturday]
|
30
|
+
if must_be_either(valid_days, days.keys)
|
31
|
+
days.each do |day, conditions|
|
32
|
+
if is_an_array?(conditions)
|
33
|
+
if !conditions.empty?
|
34
|
+
conditions.each do |condition|
|
35
|
+
validate_time_window_condition(definition, scope, attribute, condition)
|
36
|
+
end
|
37
|
+
else
|
38
|
+
invalid(definition, "#{scope} #{attribute} days #{day} must include at least one time window")
|
39
|
+
end
|
40
|
+
else
|
41
|
+
invalid(definition, "#{scope} #{attribute} days #{day} must be in an array")
|
42
|
+
end
|
43
|
+
end
|
44
|
+
else
|
45
|
+
invalid(definition, "#{scope} #{attribute} days must be valid days of the week or 'all'")
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
# Validate time windows
|
50
|
+
# Validates: days
|
51
|
+
#
|
52
|
+
# @param definition [Hash] sensu definition.
|
53
|
+
# @param scope [String] definition scope to validate.
|
54
|
+
# @param attribute [String] definition attribute to validate.
|
55
|
+
def validate_time_windows(definition, scope, attribute)
|
56
|
+
if is_a_hash?(definition[attribute])
|
57
|
+
days = definition[attribute][:days]
|
58
|
+
if is_a_hash?(days)
|
59
|
+
if !days.empty?
|
60
|
+
validate_time_windows_days(definition, scope, attribute, days)
|
61
|
+
else
|
62
|
+
invalid(definition, "#{scope} #{attribute} days must include at least one day of the week or 'all'")
|
63
|
+
end
|
64
|
+
else
|
65
|
+
invalid(definition, "#{scope} #{attribute} days must be a hash")
|
66
|
+
end
|
67
|
+
else
|
68
|
+
invalid(definition, "#{scope} #{attribute} must be a hash")
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Sensu
|
2
|
+
module Settings
|
3
|
+
module Validators
|
4
|
+
module Transport
|
5
|
+
# Validate a Sensu transport definition.
|
6
|
+
# Validates: name
|
7
|
+
#
|
8
|
+
# @param transport [Hash] sensu transport definition.
|
9
|
+
def validate_transport(transport)
|
10
|
+
if is_a_hash?(transport)
|
11
|
+
must_be_a_string(transport[:name]) ||
|
12
|
+
invalid(transport, "transport name must be a string")
|
13
|
+
must_be_boolean_if_set(transport[:reconnect_on_error]) ||
|
14
|
+
invalid(transport, "transport reconnect_on_error must be boolean")
|
15
|
+
else
|
16
|
+
invalid(transport, "transport must be a hash")
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|