sensu-settings 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +22 -0
- data/.travis.yml +14 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +20 -0
- data/README.md +28 -0
- data/Rakefile +6 -0
- data/lib/sensu/settings.rb +15 -0
- data/lib/sensu/settings/constants.rb +5 -0
- data/lib/sensu/settings/loader.rb +255 -0
- data/lib/sensu/settings/rules.rb +154 -0
- data/lib/sensu/settings/validator.rb +76 -0
- data/lib/sensu/settings/validators.rb +23 -0
- data/lib/sensu/settings/validators/api.rb +36 -0
- data/lib/sensu/settings/validators/check.rb +78 -0
- data/lib/sensu/settings/validators/client.rb +113 -0
- data/lib/sensu/settings/validators/filter.rb +18 -0
- data/lib/sensu/settings/validators/handler.rb +133 -0
- data/lib/sensu/settings/validators/mutator.rb +18 -0
- data/lib/sensu/settings/validators/subdue.rb +68 -0
- data/lib/sensu/settings/validators/transport.rb +20 -0
- data/sensu-settings.gemspec +24 -0
- data/spec/assets/conf.d/merger.json +11 -0
- data/spec/assets/conf.d/nested/file.json +11 -0
- data/spec/assets/config.json +126 -0
- data/spec/assets/invalid.json +2 -0
- data/spec/helpers.rb +8 -0
- data/spec/loader_spec.rb +171 -0
- data/spec/rules_spec.rb +65 -0
- data/spec/settings_spec.rb +13 -0
- data/spec/validator_spec.rb +619 -0
- metadata +153 -0
data/spec/rules_spec.rb
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "helpers")
|
2
|
+
require "sensu/settings/rules"
|
3
|
+
|
4
|
+
describe "Sensu::Settings::Rules" do
|
5
|
+
include Helpers
|
6
|
+
include Sensu::Settings::Rules
|
7
|
+
|
8
|
+
it "can provide validation rules" do
|
9
|
+
must_be_a_hash({}).should be_true
|
10
|
+
must_be_a_hash("").should be_false
|
11
|
+
must_be_a_hash_if_set({}).should be_true
|
12
|
+
must_be_a_hash_if_set(nil).should be_true
|
13
|
+
must_be_a_hash_if_set("").should be_false
|
14
|
+
must_be_an_array([]).should be_true
|
15
|
+
must_be_an_array("").should be_false
|
16
|
+
must_be_an_array_if_set([]).should be_true
|
17
|
+
must_be_an_array_if_set(nil).should be_true
|
18
|
+
must_be_an_array_if_set("").should be_false
|
19
|
+
must_be_a_string("").should be_true
|
20
|
+
must_be_a_string(1).should be_false
|
21
|
+
must_be_a_string_if_set("").should be_true
|
22
|
+
must_be_a_string_if_set(nil).should be_true
|
23
|
+
must_be_a_string_if_set(1).should be_false
|
24
|
+
must_be_an_integer(1).should be_true
|
25
|
+
must_be_an_integer("").should be_false
|
26
|
+
must_be_a_numeric(1.5).should be_true
|
27
|
+
must_be_a_numeric("").should be_false
|
28
|
+
must_match_regex(/^foo$/, "foo").should be_true
|
29
|
+
must_match_regex(/^foo$/, "bar").should be_false
|
30
|
+
must_be_boolean_if_set(true).should be_true
|
31
|
+
must_be_boolean_if_set(false).should be_true
|
32
|
+
must_be_boolean_if_set(nil).should be_true
|
33
|
+
must_be_boolean_if_set("").should be_false
|
34
|
+
items_must_be_strings([]).should be_true
|
35
|
+
items_must_be_strings(["test"]).should be_true
|
36
|
+
items_must_be_strings([1]).should be_false
|
37
|
+
items_must_be_strings([""]).should be_false
|
38
|
+
either_are_set?(1).should be_true
|
39
|
+
either_are_set?(1, nil).should be_true
|
40
|
+
either_are_set?(nil, nil, 1).should be_true
|
41
|
+
either_are_set?(1, 1).should be_true
|
42
|
+
either_are_set?.should be_false
|
43
|
+
either_are_set?(nil).should be_false
|
44
|
+
either_are_set?(nil, nil).should be_false
|
45
|
+
must_be_time("16:30").should be_true
|
46
|
+
must_be_time("16:30", "21:00").should be_true
|
47
|
+
must_be_time(false).should be_false
|
48
|
+
must_be_time(false, "21:00").should be_false
|
49
|
+
unless RUBY_VERSION < "1.9"
|
50
|
+
must_be_time("false").should be_false
|
51
|
+
must_be_time("false", "21:00").should be_false
|
52
|
+
end
|
53
|
+
must_be_time(1).should be_false
|
54
|
+
must_be_either(%w[foo bar], "foo").should be_true
|
55
|
+
must_be_either(%w[foo bar], "bar").should be_true
|
56
|
+
must_be_either(%w[foo bar], ["foo", "bar"]).should be_true
|
57
|
+
must_be_either(%w[foo bar], "baz").should be_false
|
58
|
+
must_be_either(%w[foo bar], 1).should be_false
|
59
|
+
must_be_either(%w[foo bar], nil).should be_false
|
60
|
+
must_be_either(%w[foo bar], ["foo", nil]).should be_false
|
61
|
+
must_be_either_if_set(%w[foo bar], "foo").should be_true
|
62
|
+
must_be_either_if_set(%w[foo bar], nil).should be_true
|
63
|
+
must_be_either_if_set(%w[foo bar], "baz").should be_false
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "helpers")
|
2
|
+
require "sensu/settings"
|
3
|
+
|
4
|
+
describe "Sensu::Settings" do
|
5
|
+
include Helpers
|
6
|
+
|
7
|
+
it "can provide a loader" do
|
8
|
+
Sensu::Settings.should respond_to(:load)
|
9
|
+
Sensu::Settings.load.should be_an_instance_of(Sensu::Settings::Loader)
|
10
|
+
settings = Sensu::Settings.load
|
11
|
+
settings.should respond_to(:validate!)
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,619 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "helpers")
|
2
|
+
require "sensu/settings/validator"
|
3
|
+
|
4
|
+
describe "Sensu::Settings::Validator" do
|
5
|
+
include Helpers
|
6
|
+
|
7
|
+
before do
|
8
|
+
@validator = Sensu::Settings::Validator.new
|
9
|
+
end
|
10
|
+
|
11
|
+
it "can run, validating setting categories" do
|
12
|
+
failures = @validator.run({})
|
13
|
+
failures.should be_kind_of(Array)
|
14
|
+
failures.each do |failure|
|
15
|
+
failure[:object].should be_nil
|
16
|
+
end
|
17
|
+
reasons = failures.map do |failure|
|
18
|
+
failure[:message]
|
19
|
+
end
|
20
|
+
reasons.should include("checks must be a hash")
|
21
|
+
reasons.should include("filters must be a hash")
|
22
|
+
reasons.should include("mutators must be a hash")
|
23
|
+
reasons.should include("handlers must be a hash")
|
24
|
+
reasons.size.should eq(4)
|
25
|
+
end
|
26
|
+
|
27
|
+
it "can validate a transport definition" do
|
28
|
+
transport = nil
|
29
|
+
@validator.validate_transport(transport)
|
30
|
+
@validator.reset.should eq(0)
|
31
|
+
transport = {}
|
32
|
+
@validator.validate_transport(transport)
|
33
|
+
@validator.reset.should eq(0)
|
34
|
+
transport[:name] = 1
|
35
|
+
@validator.validate_transport(transport)
|
36
|
+
@validator.reset.should eq(1)
|
37
|
+
transport[:name] = "rabbitmq"
|
38
|
+
@validator.validate_transport(transport)
|
39
|
+
@validator.reset.should eq(0)
|
40
|
+
end
|
41
|
+
|
42
|
+
it "can run, validating transport" do
|
43
|
+
settings = {
|
44
|
+
:transport => {
|
45
|
+
:name => 1
|
46
|
+
}
|
47
|
+
}
|
48
|
+
@validator.run(settings)
|
49
|
+
@validator.reset.should eq(5)
|
50
|
+
settings[:transport][:name] = "rabbitmq"
|
51
|
+
@validator.run(settings)
|
52
|
+
@validator.reset.should eq(4)
|
53
|
+
end
|
54
|
+
|
55
|
+
it "can validate an empty check definition" do
|
56
|
+
@validator.validate_check({})
|
57
|
+
reasons = @validator.failures.map do |failure|
|
58
|
+
failure[:message]
|
59
|
+
end
|
60
|
+
reasons.should include("check name must be a string")
|
61
|
+
reasons.should include("check name cannot contain spaces or special characters")
|
62
|
+
reasons.should include("check command must be a string")
|
63
|
+
reasons.should include("check interval must be an integer")
|
64
|
+
reasons.should include("check subscribers must be an array")
|
65
|
+
reasons.size.should eq(5)
|
66
|
+
end
|
67
|
+
|
68
|
+
it "can validate a check definition" do
|
69
|
+
check = {:name => "foo bar"}
|
70
|
+
@validator.validate_check(check)
|
71
|
+
@validator.reset.should eq(4)
|
72
|
+
check[:name] = "foo"
|
73
|
+
@validator.validate_check(check)
|
74
|
+
@validator.reset.should eq(3)
|
75
|
+
check[:command] = 1
|
76
|
+
@validator.validate_check(check)
|
77
|
+
@validator.reset.should eq(3)
|
78
|
+
check[:command] = "true"
|
79
|
+
@validator.validate_check(check)
|
80
|
+
@validator.reset.should eq(2)
|
81
|
+
check[:timeout] = "foo"
|
82
|
+
@validator.validate_check(check)
|
83
|
+
@validator.reset.should eq(3)
|
84
|
+
check[:timeout] = 1.5
|
85
|
+
@validator.validate_check(check)
|
86
|
+
@validator.reset.should eq(2)
|
87
|
+
check[:timeout] = 1
|
88
|
+
@validator.validate_check(check)
|
89
|
+
@validator.reset.should eq(2)
|
90
|
+
check[:publish] = "false"
|
91
|
+
@validator.validate_check(check)
|
92
|
+
@validator.reset.should eq(3)
|
93
|
+
check[:publish] = false
|
94
|
+
@validator.validate_check(check)
|
95
|
+
@validator.reset.should eq(1)
|
96
|
+
check[:publish] = true
|
97
|
+
@validator.validate_check(check)
|
98
|
+
@validator.reset.should eq(2)
|
99
|
+
check[:interval] = "1"
|
100
|
+
@validator.validate_check(check)
|
101
|
+
@validator.reset.should eq(2)
|
102
|
+
check[:interval] = 1
|
103
|
+
@validator.validate_check(check)
|
104
|
+
@validator.reset.should eq(1)
|
105
|
+
check[:subscribers] = 1
|
106
|
+
@validator.validate_check(check)
|
107
|
+
@validator.reset.should eq(1)
|
108
|
+
check[:subscribers] = [1]
|
109
|
+
@validator.validate_check(check)
|
110
|
+
@validator.reset.should eq(1)
|
111
|
+
check[:subscribers] = []
|
112
|
+
@validator.validate_check(check)
|
113
|
+
@validator.reset.should eq(0)
|
114
|
+
check[:standalone] = "true"
|
115
|
+
@validator.validate_check(check)
|
116
|
+
@validator.reset.should eq(1)
|
117
|
+
check[:standalone] = true
|
118
|
+
@validator.validate_check(check)
|
119
|
+
@validator.reset.should eq(0)
|
120
|
+
check[:handler] = 1
|
121
|
+
@validator.validate_check(check)
|
122
|
+
@validator.reset.should eq(1)
|
123
|
+
check[:handler] = "cat"
|
124
|
+
@validator.validate_check(check)
|
125
|
+
@validator.reset.should eq(0)
|
126
|
+
check[:handlers] = "cat"
|
127
|
+
@validator.validate_check(check)
|
128
|
+
@validator.reset.should eq(1)
|
129
|
+
check[:handlers] = ["cat"]
|
130
|
+
@validator.validate_check(check)
|
131
|
+
@validator.reset.should eq(0)
|
132
|
+
check[:low_flap_threshold] = "25"
|
133
|
+
@validator.validate_check(check)
|
134
|
+
@validator.reset.should eq(2)
|
135
|
+
check[:low_flap_threshold] = 25
|
136
|
+
@validator.validate_check(check)
|
137
|
+
@validator.reset.should eq(1)
|
138
|
+
check[:high_flap_threshold] = "55"
|
139
|
+
@validator.validate_check(check)
|
140
|
+
@validator.reset.should eq(1)
|
141
|
+
check[:high_flap_threshold] = 55
|
142
|
+
@validator.validate_check(check)
|
143
|
+
@validator.reset.should eq(0)
|
144
|
+
end
|
145
|
+
|
146
|
+
it "can validate check subdue" do
|
147
|
+
check = {
|
148
|
+
:name => "foo",
|
149
|
+
:command => "true",
|
150
|
+
:interval => 1,
|
151
|
+
:standalone => true
|
152
|
+
}
|
153
|
+
@validator.validate_check(check)
|
154
|
+
@validator.reset.should eq(0)
|
155
|
+
check[:subdue] = true
|
156
|
+
@validator.validate_check(check)
|
157
|
+
@validator.reset.should eq(1)
|
158
|
+
check[:subdue] = {
|
159
|
+
:at => "unknown"
|
160
|
+
}
|
161
|
+
@validator.validate_check(check)
|
162
|
+
@validator.reset.should eq(1)
|
163
|
+
check[:subdue][:at] = "publisher"
|
164
|
+
@validator.validate_check(check)
|
165
|
+
@validator.reset.should eq(0)
|
166
|
+
check[:subdue][:at] = "handler"
|
167
|
+
@validator.validate_check(check)
|
168
|
+
@validator.reset.should eq(0)
|
169
|
+
check[:subdue][:begin] = "14:30"
|
170
|
+
check[:subdue][:end] = 1
|
171
|
+
@validator.validate_check(check)
|
172
|
+
@validator.reset.should eq(1)
|
173
|
+
check[:subdue][:begin] = 1
|
174
|
+
check[:subdue][:end] = "14:30"
|
175
|
+
@validator.validate_check(check)
|
176
|
+
@validator.reset.should eq(1)
|
177
|
+
check[:subdue][:begin] = "14:30"
|
178
|
+
check[:subdue][:end] = "16:30"
|
179
|
+
@validator.validate_check(check)
|
180
|
+
@validator.reset.should eq(0)
|
181
|
+
check[:subdue][:days] = 1
|
182
|
+
@validator.validate_check(check)
|
183
|
+
@validator.reset.should eq(1)
|
184
|
+
check[:subdue][:days] = ["unknown"]
|
185
|
+
@validator.validate_check(check)
|
186
|
+
@validator.reset.should eq(1)
|
187
|
+
check[:subdue][:days] = [true]
|
188
|
+
@validator.validate_check(check)
|
189
|
+
@validator.reset.should eq(1)
|
190
|
+
check[:subdue][:days] = ["monday"]
|
191
|
+
@validator.validate_check(check)
|
192
|
+
@validator.reset.should eq(0)
|
193
|
+
check[:subdue][:exceptions] = 1
|
194
|
+
@validator.validate_check(check)
|
195
|
+
@validator.reset.should eq(1)
|
196
|
+
check[:subdue][:exceptions] = []
|
197
|
+
@validator.validate_check(check)
|
198
|
+
@validator.reset.should eq(0)
|
199
|
+
check[:subdue][:exceptions] = [1]
|
200
|
+
@validator.validate_check(check)
|
201
|
+
@validator.reset.should eq(1)
|
202
|
+
check[:subdue][:exceptions] = [{}]
|
203
|
+
@validator.validate_check(check)
|
204
|
+
@validator.reset.should eq(0)
|
205
|
+
check[:subdue][:exceptions] = [{:begin => "15:00"}]
|
206
|
+
@validator.validate_check(check)
|
207
|
+
@validator.reset.should eq(1)
|
208
|
+
check[:subdue][:exceptions] = [{:begin => "15:00", :end => "15:30"}]
|
209
|
+
@validator.validate_check(check)
|
210
|
+
@validator.reset.should eq(0)
|
211
|
+
end
|
212
|
+
|
213
|
+
it "can run, validating checks" do
|
214
|
+
settings = {
|
215
|
+
:checks => {
|
216
|
+
:foo => {
|
217
|
+
:command => "true",
|
218
|
+
:standalone => true
|
219
|
+
}
|
220
|
+
}
|
221
|
+
}
|
222
|
+
@validator.run(settings)
|
223
|
+
@validator.reset.should eq(4)
|
224
|
+
settings[:checks][:foo][:interval] = 1
|
225
|
+
@validator.run(settings)
|
226
|
+
@validator.reset.should eq(3)
|
227
|
+
end
|
228
|
+
|
229
|
+
it "can validate a filter definition" do
|
230
|
+
filter = {}
|
231
|
+
@validator.validate_filter(filter)
|
232
|
+
@validator.reset.should eq(1)
|
233
|
+
filter[:attributes] = 1
|
234
|
+
@validator.validate_filter(filter)
|
235
|
+
@validator.reset.should eq(1)
|
236
|
+
filter[:attributes] = {}
|
237
|
+
@validator.validate_filter(filter)
|
238
|
+
@validator.reset.should eq(0)
|
239
|
+
filter[:negate] = "true"
|
240
|
+
@validator.validate_filter(filter)
|
241
|
+
@validator.reset.should eq(1)
|
242
|
+
filter[:negate] = true
|
243
|
+
@validator.validate_filter(filter)
|
244
|
+
@validator.reset.should eq(0)
|
245
|
+
end
|
246
|
+
|
247
|
+
it "can validate a mutator definition" do
|
248
|
+
mutator = {}
|
249
|
+
@validator.validate_mutator(mutator)
|
250
|
+
@validator.reset.should eq(1)
|
251
|
+
mutator[:command] = "cat"
|
252
|
+
@validator.validate_mutator(mutator)
|
253
|
+
@validator.reset.should eq(0)
|
254
|
+
mutator[:timeout] = "foo"
|
255
|
+
@validator.validate_mutator(mutator)
|
256
|
+
@validator.reset.should eq(1)
|
257
|
+
mutator[:timeout] = 1.5
|
258
|
+
@validator.validate_mutator(mutator)
|
259
|
+
@validator.reset.should eq(0)
|
260
|
+
mutator[:timeout] = 1
|
261
|
+
@validator.validate_mutator(mutator)
|
262
|
+
@validator.reset.should eq(0)
|
263
|
+
end
|
264
|
+
|
265
|
+
it "can validate a handler definition" do
|
266
|
+
handler = {}
|
267
|
+
@validator.validate_handler(handler)
|
268
|
+
@validator.reset.should eq(2)
|
269
|
+
handler[:type] = 1
|
270
|
+
@validator.validate_handler(handler)
|
271
|
+
@validator.reset.should eq(2)
|
272
|
+
handler[:type] = "unknown"
|
273
|
+
@validator.validate_handler(handler)
|
274
|
+
@validator.reset.should eq(1)
|
275
|
+
handler[:type] = "pipe"
|
276
|
+
@validator.validate_handler(handler)
|
277
|
+
@validator.reset.should eq(1)
|
278
|
+
handler[:command] = 1
|
279
|
+
@validator.validate_handler(handler)
|
280
|
+
@validator.reset.should eq(1)
|
281
|
+
handler[:command] = "cat"
|
282
|
+
@validator.validate_handler(handler)
|
283
|
+
@validator.reset.should eq(0)
|
284
|
+
handler[:timeout] = "foo"
|
285
|
+
@validator.validate_handler(handler)
|
286
|
+
@validator.reset.should eq(1)
|
287
|
+
handler[:timeout] = 1
|
288
|
+
@validator.validate_handler(handler)
|
289
|
+
@validator.reset.should eq(0)
|
290
|
+
handler[:mutator] = 1
|
291
|
+
@validator.validate_handler(handler)
|
292
|
+
@validator.reset.should eq(1)
|
293
|
+
handler[:mutator] = "foo"
|
294
|
+
@validator.validate_handler(handler)
|
295
|
+
@validator.reset.should eq(0)
|
296
|
+
handler[:handle_flapping] = "true"
|
297
|
+
@validator.validate_handler(handler)
|
298
|
+
@validator.reset.should eq(1)
|
299
|
+
handler[:handle_flapping] = true
|
300
|
+
@validator.validate_handler(handler)
|
301
|
+
@validator.reset.should eq(0)
|
302
|
+
handler[:handle_flapping] = false
|
303
|
+
@validator.validate_handler(handler)
|
304
|
+
@validator.reset.should eq(0)
|
305
|
+
handler[:filter] = 1
|
306
|
+
@validator.validate_handler(handler)
|
307
|
+
@validator.reset.should eq(1)
|
308
|
+
handler[:filter] = "foo"
|
309
|
+
@validator.validate_handler(handler)
|
310
|
+
@validator.reset.should eq(0)
|
311
|
+
handler[:filters] = "foo"
|
312
|
+
@validator.validate_handler(handler)
|
313
|
+
@validator.reset.should eq(1)
|
314
|
+
handler[:filters] = []
|
315
|
+
@validator.validate_handler(handler)
|
316
|
+
@validator.reset.should eq(0)
|
317
|
+
handler[:filters] = [1]
|
318
|
+
@validator.validate_handler(handler)
|
319
|
+
@validator.reset.should eq(1)
|
320
|
+
handler[:filters] = ["foo"]
|
321
|
+
@validator.validate_handler(handler)
|
322
|
+
@validator.reset.should eq(0)
|
323
|
+
handler[:severities] = "foo"
|
324
|
+
@validator.validate_handler(handler)
|
325
|
+
@validator.reset.should eq(1)
|
326
|
+
handler[:severities] = []
|
327
|
+
@validator.validate_handler(handler)
|
328
|
+
@validator.reset.should eq(0)
|
329
|
+
handler[:severities] = ["foo"]
|
330
|
+
@validator.validate_handler(handler)
|
331
|
+
@validator.reset.should eq(1)
|
332
|
+
handler[:severities] = ["warning", "unknown"]
|
333
|
+
@validator.validate_handler(handler)
|
334
|
+
@validator.reset.should eq(0)
|
335
|
+
end
|
336
|
+
|
337
|
+
it "can validate a tcp/udp handler definition" do
|
338
|
+
handler = {
|
339
|
+
:type => "tcp"
|
340
|
+
}
|
341
|
+
@validator.validate_handler(handler)
|
342
|
+
@validator.reset.should eq(1)
|
343
|
+
handler[:socket] = {}
|
344
|
+
@validator.validate_handler(handler)
|
345
|
+
@validator.reset.should eq(2)
|
346
|
+
handler[:socket][:host] = 1
|
347
|
+
@validator.validate_handler(handler)
|
348
|
+
@validator.reset.should eq(2)
|
349
|
+
handler[:socket][:host] = "127.0.0.1"
|
350
|
+
@validator.validate_handler(handler)
|
351
|
+
@validator.reset.should eq(1)
|
352
|
+
handler[:socket][:port] = "foo"
|
353
|
+
@validator.validate_handler(handler)
|
354
|
+
@validator.reset.should eq(1)
|
355
|
+
handler[:socket][:port] = 2003
|
356
|
+
@validator.validate_handler(handler)
|
357
|
+
@validator.reset.should eq(0)
|
358
|
+
end
|
359
|
+
|
360
|
+
it "can validate a transport handler definition" do
|
361
|
+
handler = {
|
362
|
+
:type => "transport"
|
363
|
+
}
|
364
|
+
@validator.validate_handler(handler)
|
365
|
+
@validator.reset.should eq(1)
|
366
|
+
handler[:pipe] = 1
|
367
|
+
@validator.validate_handler(handler)
|
368
|
+
@validator.reset.should eq(1)
|
369
|
+
handler[:pipe] = {}
|
370
|
+
@validator.validate_handler(handler)
|
371
|
+
@validator.reset.should eq(3)
|
372
|
+
handler[:pipe][:type] = 1
|
373
|
+
@validator.validate_handler(handler)
|
374
|
+
@validator.reset.should eq(3)
|
375
|
+
handler[:pipe][:type] = "unknown"
|
376
|
+
@validator.validate_handler(handler)
|
377
|
+
@validator.reset.should eq(2)
|
378
|
+
handler[:pipe][:type] = "direct"
|
379
|
+
@validator.validate_handler(handler)
|
380
|
+
@validator.reset.should eq(1)
|
381
|
+
handler[:pipe][:name] = 1
|
382
|
+
@validator.validate_handler(handler)
|
383
|
+
@validator.reset.should eq(1)
|
384
|
+
handler[:pipe][:name] = "foo"
|
385
|
+
@validator.validate_handler(handler)
|
386
|
+
@validator.reset.should eq(0)
|
387
|
+
handler[:pipe][:options] = 1
|
388
|
+
@validator.validate_handler(handler)
|
389
|
+
@validator.reset.should eq(1)
|
390
|
+
handler[:pipe][:options] = {}
|
391
|
+
@validator.validate_handler(handler)
|
392
|
+
@validator.reset.should eq(0)
|
393
|
+
end
|
394
|
+
|
395
|
+
it "can validate a handler set definition" do
|
396
|
+
handler = {
|
397
|
+
:type => "set"
|
398
|
+
}
|
399
|
+
@validator.validate_handler(handler)
|
400
|
+
@validator.reset.should eq(1)
|
401
|
+
handler[:handlers] = 1
|
402
|
+
@validator.validate_handler(handler)
|
403
|
+
@validator.reset.should eq(1)
|
404
|
+
handler[:handlers] = "default"
|
405
|
+
@validator.validate_handler(handler)
|
406
|
+
@validator.reset.should eq(1)
|
407
|
+
handler[:handlers] = [1]
|
408
|
+
@validator.validate_handler(handler)
|
409
|
+
@validator.reset.should eq(1)
|
410
|
+
handler[:handlers] = ["default"]
|
411
|
+
@validator.validate_handler(handler)
|
412
|
+
@validator.reset.should eq(0)
|
413
|
+
end
|
414
|
+
|
415
|
+
it "can validate handler subdue" do
|
416
|
+
handler = {
|
417
|
+
:name => "foo",
|
418
|
+
:type => "pipe",
|
419
|
+
:command => "cat"
|
420
|
+
}
|
421
|
+
@validator.validate_handler(handler)
|
422
|
+
@validator.reset.should eq(0)
|
423
|
+
handler[:subdue] = true
|
424
|
+
@validator.validate_handler(handler)
|
425
|
+
@validator.reset.should eq(1)
|
426
|
+
handler[:subdue] = {
|
427
|
+
:at => "handler",
|
428
|
+
:begin => "14:30",
|
429
|
+
:end => "15:45"
|
430
|
+
}
|
431
|
+
@validator.validate_handler(handler)
|
432
|
+
@validator.reset.should eq(0)
|
433
|
+
end
|
434
|
+
|
435
|
+
it "can validate a client definition" do
|
436
|
+
client = true
|
437
|
+
@validator.validate_client(client)
|
438
|
+
@validator.reset.should eq(1)
|
439
|
+
client = {}
|
440
|
+
@validator.validate_client(client)
|
441
|
+
@validator.reset.should eq(4)
|
442
|
+
client[:name] = 1
|
443
|
+
@validator.validate_client(client)
|
444
|
+
@validator.reset.should eq(4)
|
445
|
+
client[:name] = "foo bar"
|
446
|
+
@validator.validate_client(client)
|
447
|
+
@validator.reset.should eq(3)
|
448
|
+
client[:name] = "foo"
|
449
|
+
@validator.validate_client(client)
|
450
|
+
@validator.reset.should eq(2)
|
451
|
+
client[:address] = 1
|
452
|
+
@validator.validate_client(client)
|
453
|
+
@validator.reset.should eq(2)
|
454
|
+
client[:address] = "127.0.0.1"
|
455
|
+
@validator.validate_client(client)
|
456
|
+
@validator.reset.should eq(1)
|
457
|
+
client[:subscriptions] = true
|
458
|
+
@validator.validate_client(client)
|
459
|
+
@validator.reset.should eq(1)
|
460
|
+
client[:subscriptions] = []
|
461
|
+
@validator.validate_client(client)
|
462
|
+
@validator.reset.should eq(0)
|
463
|
+
client[:subscriptions] = [1]
|
464
|
+
@validator.validate_client(client)
|
465
|
+
@validator.reset.should eq(1)
|
466
|
+
client[:subscriptions] = ["bar"]
|
467
|
+
@validator.validate_client(client)
|
468
|
+
@validator.reset.should eq(0)
|
469
|
+
client[:redact] = true
|
470
|
+
@validator.validate_client(client)
|
471
|
+
@validator.reset.should eq(1)
|
472
|
+
client[:redact] = []
|
473
|
+
@validator.validate_client(client)
|
474
|
+
@validator.reset.should eq(0)
|
475
|
+
client[:redact] = [1]
|
476
|
+
@validator.validate_client(client)
|
477
|
+
@validator.reset.should eq(1)
|
478
|
+
client[:redact] = ["secret"]
|
479
|
+
@validator.validate_client(client)
|
480
|
+
@validator.reset.should eq(0)
|
481
|
+
end
|
482
|
+
|
483
|
+
it "can validate client socket" do
|
484
|
+
client = {
|
485
|
+
:name => "foo",
|
486
|
+
:address => "127.0.0.1",
|
487
|
+
:subscriptions => ["bar"]
|
488
|
+
}
|
489
|
+
@validator.validate_client(client)
|
490
|
+
@validator.reset.should eq(0)
|
491
|
+
client[:socket] = true
|
492
|
+
@validator.validate_client(client)
|
493
|
+
@validator.reset.should eq(1)
|
494
|
+
client[:socket] = {}
|
495
|
+
@validator.validate_client(client)
|
496
|
+
@validator.reset.should eq(0)
|
497
|
+
client[:socket][:bind] = true
|
498
|
+
@validator.validate_client(client)
|
499
|
+
@validator.reset.should eq(1)
|
500
|
+
client[:socket][:bind] = "127.0.0.1"
|
501
|
+
@validator.validate_client(client)
|
502
|
+
@validator.reset.should eq(0)
|
503
|
+
client[:socket][:port] = "2012"
|
504
|
+
@validator.validate_client(client)
|
505
|
+
@validator.reset.should eq(1)
|
506
|
+
client[:socket][:port] = 2012
|
507
|
+
@validator.validate_client(client)
|
508
|
+
@validator.reset.should eq(0)
|
509
|
+
end
|
510
|
+
|
511
|
+
it "can validate client keepalive" do
|
512
|
+
client = {
|
513
|
+
:name => "foo",
|
514
|
+
:address => "127.0.0.1",
|
515
|
+
:subscriptions => ["bar"]
|
516
|
+
}
|
517
|
+
@validator.validate_client(client)
|
518
|
+
@validator.reset.should eq(0)
|
519
|
+
client[:keepalive] = true
|
520
|
+
@validator.validate_client(client)
|
521
|
+
@validator.reset.should eq(1)
|
522
|
+
client[:keepalive] = {}
|
523
|
+
@validator.validate_client(client)
|
524
|
+
@validator.reset.should eq(0)
|
525
|
+
client[:keepalive][:handler] = 1
|
526
|
+
@validator.validate_client(client)
|
527
|
+
@validator.reset.should eq(1)
|
528
|
+
client[:keepalive][:handler] = "foo"
|
529
|
+
@validator.validate_client(client)
|
530
|
+
@validator.reset.should eq(0)
|
531
|
+
client[:keepalive][:handlers] = 1
|
532
|
+
@validator.validate_client(client)
|
533
|
+
@validator.reset.should eq(1)
|
534
|
+
client[:keepalive][:handlers] = [1]
|
535
|
+
@validator.validate_client(client)
|
536
|
+
@validator.reset.should eq(1)
|
537
|
+
client[:keepalive][:handlers] = ["foo"]
|
538
|
+
@validator.validate_client(client)
|
539
|
+
@validator.reset.should eq(0)
|
540
|
+
client[:keepalive][:thresholds] = true
|
541
|
+
@validator.validate_client(client)
|
542
|
+
@validator.reset.should eq(1)
|
543
|
+
client[:keepalive][:thresholds] = {}
|
544
|
+
@validator.validate_client(client)
|
545
|
+
@validator.reset.should eq(0)
|
546
|
+
client[:keepalive][:thresholds][:warning] = "60"
|
547
|
+
@validator.validate_client(client)
|
548
|
+
@validator.reset.should eq(1)
|
549
|
+
client[:keepalive][:thresholds][:warning] = 60
|
550
|
+
@validator.validate_client(client)
|
551
|
+
@validator.reset.should eq(0)
|
552
|
+
client[:keepalive][:thresholds][:critical] = "90"
|
553
|
+
@validator.validate_client(client)
|
554
|
+
@validator.reset.should eq(1)
|
555
|
+
client[:keepalive][:thresholds][:critical] = 90
|
556
|
+
@validator.validate_client(client)
|
557
|
+
@validator.reset.should eq(0)
|
558
|
+
end
|
559
|
+
|
560
|
+
it "can run, validating client" do
|
561
|
+
settings = {
|
562
|
+
:client => {
|
563
|
+
:name => "foo",
|
564
|
+
:address => "127.0.0.1"
|
565
|
+
}
|
566
|
+
}
|
567
|
+
@validator.run(settings, "client")
|
568
|
+
@validator.reset.should eq(5)
|
569
|
+
settings[:client][:subscriptions] = ["bar"]
|
570
|
+
@validator.run(settings, "client")
|
571
|
+
@validator.reset.should eq(4)
|
572
|
+
end
|
573
|
+
|
574
|
+
it "can validate an api definition" do
|
575
|
+
api = true
|
576
|
+
@validator.validate_api(api)
|
577
|
+
@validator.reset.should eq(1)
|
578
|
+
api = {}
|
579
|
+
@validator.validate_api(api)
|
580
|
+
@validator.reset.should eq(1)
|
581
|
+
api[:port] = true
|
582
|
+
@validator.validate_api(api)
|
583
|
+
@validator.reset.should eq(1)
|
584
|
+
api[:port] = 4567
|
585
|
+
@validator.validate_api(api)
|
586
|
+
@validator.reset.should eq(0)
|
587
|
+
api[:bind] = true
|
588
|
+
@validator.validate_api(api)
|
589
|
+
@validator.reset.should eq(1)
|
590
|
+
api[:bind] = "127.0.0.1"
|
591
|
+
@validator.validate_api(api)
|
592
|
+
@validator.reset.should eq(0)
|
593
|
+
api[:user] = 1
|
594
|
+
@validator.validate_api(api)
|
595
|
+
@validator.reset.should eq(2)
|
596
|
+
api[:user] = "foo"
|
597
|
+
@validator.validate_api(api)
|
598
|
+
@validator.reset.should eq(1)
|
599
|
+
api[:password] = 1
|
600
|
+
@validator.validate_api(api)
|
601
|
+
@validator.reset.should eq(1)
|
602
|
+
api[:password] = "bar"
|
603
|
+
@validator.validate_api(api)
|
604
|
+
@validator.reset.should eq(0)
|
605
|
+
end
|
606
|
+
|
607
|
+
it "can run, validating api" do
|
608
|
+
settings = {
|
609
|
+
:api => {
|
610
|
+
:port => "4567"
|
611
|
+
}
|
612
|
+
}
|
613
|
+
@validator.run(settings, "api")
|
614
|
+
@validator.reset.should eq(5)
|
615
|
+
settings[:api][:port] = 4567
|
616
|
+
@validator.run(settings, "api")
|
617
|
+
@validator.reset.should eq(4)
|
618
|
+
end
|
619
|
+
end
|