sensu-settings 9.1.1 → 9.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/spec/rules_spec.rb DELETED
@@ -1,66 +0,0 @@
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
- expect(must_be_a_hash({})).to be(true)
10
- expect(must_be_a_hash("")).to be(false)
11
- expect(must_be_a_hash_if_set({})).to be(true)
12
- expect(must_be_a_hash_if_set(nil)).to be(true)
13
- expect(must_be_a_hash_if_set("")).to be(false)
14
- expect(must_be_an_array([])).to be(true)
15
- expect(must_be_an_array("")).to be(false)
16
- expect(must_be_an_array_if_set([])).to be(true)
17
- expect(must_be_an_array_if_set(nil)).to be(true)
18
- expect(must_be_an_array_if_set("")).to be(false)
19
- expect(must_be_a_string("")).to be(true)
20
- expect(must_be_a_string(1)).to be(false)
21
- expect(must_be_a_string_if_set("")).to be(true)
22
- expect(must_be_a_string_if_set(nil)).to be(true)
23
- expect(must_be_a_string_if_set(1)).to be(false)
24
- expect(must_be_an_integer(1)).to be(true)
25
- expect(must_be_an_integer("")).to be(false)
26
- expect(must_be_a_numeric(1.5)).to be(true)
27
- expect(must_be_a_numeric("")).to be(false)
28
- expect(must_match_regex(/^foo$/, "foo")).to be(true)
29
- expect(must_match_regex(/^foo$/, "bar")).to be(false)
30
- expect(must_match_regex(/^\w+$/, "baz$")).to be(false)
31
- expect(must_be_boolean_if_set(true)).to be(true)
32
- expect(must_be_boolean_if_set(false)).to be(true)
33
- expect(must_be_boolean_if_set(nil)).to be(true)
34
- expect(must_be_boolean_if_set("")).to be(false)
35
- expect(items_must_be_strings([])).to be(true)
36
- expect(items_must_be_strings(["test"])).to be(true)
37
- expect(items_must_be_strings([1])).to be(false)
38
- expect(items_must_be_strings([""])).to be(false)
39
- expect(either_are_set?(1)).to be(true)
40
- expect(either_are_set?(1, nil)).to be(true)
41
- expect(either_are_set?(nil, nil, 1)).to be(true)
42
- expect(either_are_set?(1, 1)).to be(true)
43
- expect(either_are_set?).to be(false)
44
- expect(either_are_set?(nil)).to be(false)
45
- expect(either_are_set?(nil, nil)).to be(false)
46
- expect(must_be_time("16:30")).to be(true)
47
- expect(must_be_time("16:30", "21:00")).to be(true)
48
- expect(must_be_time(false)).to be(false)
49
- expect(must_be_time(false, "21:00")).to be(false)
50
- unless RUBY_VERSION < "1.9"
51
- expect(must_be_time("false")).to be(false)
52
- expect(must_be_time("false", "21:00")).to be(false)
53
- end
54
- expect(must_be_time(1)).to be(false)
55
- expect(must_be_either(%w[foo bar], "foo")).to be(true)
56
- expect(must_be_either(%w[foo bar], "bar")).to be(true)
57
- expect(must_be_either(%w[foo bar], ["foo", "bar"])).to be(true)
58
- expect(must_be_either(%w[foo bar], "baz")).to be(false)
59
- expect(must_be_either(%w[foo bar], 1)).to be(false)
60
- expect(must_be_either(%w[foo bar], nil)).to be(false)
61
- expect(must_be_either(%w[foo bar], ["foo", nil])).to be(false)
62
- expect(must_be_either_if_set(%w[foo bar], "foo")).to be(true)
63
- expect(must_be_either_if_set(%w[foo bar], nil)).to be(true)
64
- expect(must_be_either_if_set(%w[foo bar], "baz")).to be(false)
65
- end
66
- end
@@ -1,67 +0,0 @@
1
- require File.join(File.dirname(__FILE__), "helpers")
2
- require "sensu/settings"
3
-
4
- describe "Sensu::Settings" do
5
- include Helpers
6
-
7
- before do
8
- @assets_dir = File.join(File.dirname(__FILE__), "assets")
9
- @config_file = File.join(@assets_dir, "config.json")
10
- @config_dir = File.join(@assets_dir, "conf.d")
11
- @app_dir = File.join(@assets_dir, "app")
12
- end
13
-
14
- it "can provide a loader" do
15
- expect(Sensu::Settings).to respond_to(:load)
16
- expect(Sensu::Settings.load).to be_an_instance_of(Sensu::Settings::Loader)
17
- settings = Sensu::Settings.load
18
- expect(settings).to respond_to(:validate)
19
- end
20
-
21
- it "can retrive the current loaded loader" do
22
- settings = Sensu::Settings.load
23
- expect(Sensu::Settings.get).to eq(settings)
24
- expect(Sensu::Settings.get).to eq(settings)
25
- end
26
-
27
- it "can load up a loader if one doesn't exist" do
28
- settings = Sensu::Settings.get
29
- expect(settings).to be_an_instance_of(Sensu::Settings::Loader)
30
- expect(Sensu::Settings.get).to eq(settings)
31
- end
32
-
33
- it "can load settings from the environment, a file, and a directory" do
34
- ENV["RABBITMQ_URL"] = "amqp://guest:guest@localhost:5672/"
35
- settings = Sensu::Settings.load(:config_file => @config_file, :config_dir => @config_dir)
36
- expect(settings[:rabbitmq]).to eq(ENV["RABBITMQ_URL"])
37
- expect(settings[:api][:port]).to eq(4567)
38
- expect(settings[:checks][:merger][:command]).to eq("echo -n merger")
39
- expect(settings[:checks][:merger][:subscribers]).to eq(["foo", "bar"])
40
- expect(settings[:checks][:nested][:command]).to eq("true")
41
- expect(ENV["SENSU_LOADED_TEMPFILE"]).to match(/sensu_rspec_loaded_files/)
42
- loaded_files = IO.read(ENV["SENSU_LOADED_TEMPFILE"])
43
- expect(loaded_files.split(":")).to eq(settings.loaded_files)
44
- ENV["RABBITMQ_URL"] = nil
45
- end
46
-
47
- it "can load settings from files in multiple directories" do
48
- settings = Sensu::Settings.load(:config_dirs => [@config_dir, @app_dir])
49
- expect(settings[:checks][:merger][:command]).to eq("echo -n merger")
50
- expect(settings[:checks][:app_http_endpoint][:command]).to eq("check-http.rb -u https://localhost/ping -q pong")
51
- end
52
-
53
- it "can catch load errors" do
54
- settings = Sensu::Settings.load(:config_file => File.join(@assets_dir, "invalid.json"))
55
- expect(settings.errors.length).to eq(1)
56
- error = settings.errors.first
57
- expect(error[:message]).to include("config file must be valid json")
58
- end
59
-
60
- it "can handle a nonexistent config.json" do
61
- settings = Sensu::Settings.load(:config_file => "/tmp/bananaphone")
62
- expect(settings.errors.length).to eq(0)
63
- expect(settings.warnings.length).to eq(3)
64
- warning = settings.warnings[1]
65
- expect(warning[:message]).to include("ignoring config file")
66
- end
67
- end
@@ -1,942 +0,0 @@
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
- expect(failures).to be_kind_of(Array)
14
- failures.each do |failure|
15
- expect(failure[:object]).to be(nil)
16
- end
17
- reasons = failures.map do |failure|
18
- failure[:message]
19
- end
20
- expect(reasons).to include("checks must be a hash")
21
- expect(reasons).to include("filters must be a hash")
22
- expect(reasons).to include("mutators must be a hash")
23
- expect(reasons).to include("handlers must be a hash")
24
- expect(reasons).to include("extensions must be a hash")
25
- expect(reasons.size).to eq(7)
26
- end
27
-
28
- it "can validate a sensu definition" do
29
- sensu = nil
30
- @validator.validate_sensu(sensu)
31
- expect(@validator.reset).to eq(1)
32
- sensu = 1
33
- @validator.validate_sensu(sensu)
34
- expect(@validator.reset).to eq(1)
35
- sensu = {}
36
- @validator.validate_sensu(sensu)
37
- expect(@validator.reset).to eq(1)
38
- sensu[:spawn] = 1
39
- @validator.validate_sensu(sensu)
40
- expect(@validator.reset).to eq(1)
41
- sensu[:spawn] = {}
42
- @validator.validate_sensu(sensu)
43
- expect(@validator.reset).to eq(1)
44
- sensu[:spawn][:limit] = "1"
45
- @validator.validate_sensu(sensu)
46
- expect(@validator.reset).to eq(1)
47
- sensu[:spawn][:limit] = 20
48
- @validator.validate_sensu(sensu)
49
- expect(@validator.reset).to eq(0)
50
- end
51
-
52
- it "can run, validating sensu" do
53
- settings = {
54
- :sensu => {
55
- :spawn => {
56
- :limit => "20"
57
- }
58
- }
59
- }
60
- @validator.run(settings)
61
- expect(@validator.reset).to eq(7)
62
- settings[:sensu][:spawn][:limit] = 20
63
- @validator.run(settings)
64
- expect(@validator.reset).to eq(6)
65
- end
66
-
67
- it "can validate a transport definition" do
68
- transport = nil
69
- @validator.validate_transport(transport)
70
- expect(@validator.reset).to eq(1)
71
- transport = {}
72
- @validator.validate_transport(transport)
73
- expect(@validator.reset).to eq(1)
74
- transport[:name] = 1
75
- @validator.validate_transport(transport)
76
- expect(@validator.reset).to eq(1)
77
- transport[:name] = "rabbitmq"
78
- @validator.validate_transport(transport)
79
- expect(@validator.reset).to eq(0)
80
- transport[:reconnect_on_error] = "invalid"
81
- @validator.validate_transport(transport)
82
- expect(@validator.reset).to eq(1)
83
- transport[:reconnect_on_error] = false
84
- @validator.validate_transport(transport)
85
- expect(@validator.reset).to eq(0)
86
- end
87
-
88
- it "can run, validating transport" do
89
- settings = {
90
- :transport => {
91
- :name => 1
92
- }
93
- }
94
- @validator.run(settings)
95
- expect(@validator.reset).to eq(7)
96
- settings[:transport][:name] = "rabbitmq"
97
- @validator.run(settings)
98
- expect(@validator.reset).to eq(6)
99
- end
100
-
101
- it "can validate an empty check definition" do
102
- @validator.validate_check({})
103
- reasons = @validator.failures.map do |failure|
104
- failure[:message]
105
- end
106
- expect(reasons).to include("check name cannot contain spaces or special characters")
107
- expect(reasons).to include("either check command or extension must be set")
108
- expect(reasons).to include("check interval must be an integer greater than 0")
109
- expect(reasons).to include("check subscribers must be an array")
110
- expect(reasons.size).to eq(5)
111
- end
112
-
113
- it "can validate a check definition" do
114
- check = {:name => "foo bar"}
115
- @validator.validate_check(check)
116
- expect(@validator.reset).to eq(4)
117
- check[:name] = "foo\nbar"
118
- @validator.validate_check(check)
119
- expect(@validator.reset).to eq(4)
120
- check[:name] = "foo"
121
- @validator.validate_check(check)
122
- expect(@validator.reset).to eq(3)
123
- check[:command] = 1
124
- @validator.validate_check(check)
125
- expect(@validator.reset).to eq(3)
126
- check[:command] = "true"
127
- @validator.validate_check(check)
128
- expect(@validator.reset).to eq(2)
129
- check[:timeout] = "foo"
130
- @validator.validate_check(check)
131
- expect(@validator.reset).to eq(3)
132
- check[:timeout] = 1.5
133
- @validator.validate_check(check)
134
- expect(@validator.reset).to eq(2)
135
- check[:timeout] = 1
136
- @validator.validate_check(check)
137
- expect(@validator.reset).to eq(2)
138
- check[:publish] = "false"
139
- @validator.validate_check(check)
140
- expect(@validator.reset).to eq(3)
141
- check[:publish] = false
142
- @validator.validate_check(check)
143
- expect(@validator.reset).to eq(1)
144
- check[:publish] = true
145
- @validator.validate_check(check)
146
- expect(@validator.reset).to eq(2)
147
- check[:interval] = "1"
148
- @validator.validate_check(check)
149
- expect(@validator.reset).to eq(2)
150
- check[:interval] = 1
151
- @validator.validate_check(check)
152
- expect(@validator.reset).to eq(1)
153
- check[:subscribers] = 1
154
- @validator.validate_check(check)
155
- expect(@validator.reset).to eq(1)
156
- check[:subscribers] = [1]
157
- @validator.validate_check(check)
158
- expect(@validator.reset).to eq(1)
159
- check[:subscribers] = []
160
- @validator.validate_check(check)
161
- expect(@validator.reset).to eq(0)
162
- check[:standalone] = "true"
163
- @validator.validate_check(check)
164
- expect(@validator.reset).to eq(1)
165
- check[:standalone] = true
166
- @validator.validate_check(check)
167
- expect(@validator.reset).to eq(0)
168
- check[:handler] = 1
169
- @validator.validate_check(check)
170
- expect(@validator.reset).to eq(1)
171
- check[:handler] = "cat"
172
- @validator.validate_check(check)
173
- expect(@validator.reset).to eq(0)
174
- check[:handlers] = "cat"
175
- @validator.validate_check(check)
176
- expect(@validator.reset).to eq(1)
177
- check[:handlers] = ["cat"]
178
- @validator.validate_check(check)
179
- expect(@validator.reset).to eq(0)
180
- check[:ttl] = true
181
- @validator.validate_check(check)
182
- expect(@validator.reset).to eq(1)
183
- check[:ttl] = -1
184
- @validator.validate_check(check)
185
- expect(@validator.reset).to eq(1)
186
- check[:ttl] = 0
187
- @validator.validate_check(check)
188
- expect(@validator.reset).to eq(1)
189
- check[:ttl] = 1
190
- @validator.validate_check(check)
191
- expect(@validator.reset).to eq(0)
192
- check[:aggregates] = "string"
193
- @validator.validate_check(check)
194
- expect(@validator.reset).to eq(1)
195
- check[:aggregates] = true
196
- @validator.validate_check(check)
197
- expect(@validator.reset).to eq(1)
198
- check[:aggregates] = [1]
199
- @validator.validate_check(check)
200
- expect(@validator.reset).to eq(1)
201
- check[:aggregates] = [true]
202
- @validator.validate_check(check)
203
- expect(@validator.reset).to eq(1)
204
- check[:aggregates] = ["foo", "$bar$"]
205
- @validator.validate_check(check)
206
- expect(@validator.reset).to eq(1)
207
- check[:aggregates] = ["foo", "bar"]
208
- @validator.validate_check(check)
209
- expect(@validator.reset).to eq(0)
210
- check[:aggregates] = [":::some_custom_attr:::-checks", ":::another_custom_attr|default_value:::-checks"]
211
- @validator.validate_check(check)
212
- expect(@validator.reset).to eq(0)
213
- check[:aggregate] = 1
214
- @validator.validate_check(check)
215
- expect(@validator.reset).to eq(1)
216
- check[:aggregate] = true
217
- @validator.validate_check(check)
218
- expect(@validator.reset).to eq(0)
219
- check[:aggregate] = "$test"
220
- @validator.validate_check(check)
221
- expect(@validator.reset).to eq(1)
222
- check[:aggregate] = "test"
223
- @validator.validate_check(check)
224
- expect(@validator.reset).to eq(0)
225
- check[:aggregate] = ":::some_custom_attribute|magic:::"
226
- @validator.validate_check(check)
227
- expect(@validator.reset).to eq(0)
228
- check[:low_flap_threshold] = "25"
229
- @validator.validate_check(check)
230
- expect(@validator.reset).to eq(2)
231
- check[:low_flap_threshold] = 25
232
- @validator.validate_check(check)
233
- expect(@validator.reset).to eq(1)
234
- check[:high_flap_threshold] = "55"
235
- @validator.validate_check(check)
236
- expect(@validator.reset).to eq(1)
237
- check[:high_flap_threshold] = 55
238
- @validator.validate_check(check)
239
- expect(@validator.reset).to eq(0)
240
- check[:source] = 1
241
- @validator.validate_check(check)
242
- expect(@validator.reset).to eq(1)
243
- check[:source] = "switch-%42%"
244
- @validator.validate_check(check)
245
- expect(@validator.reset).to eq(1)
246
- check[:source] = "switch-42"
247
- @validator.validate_check(check)
248
- expect(@validator.reset).to eq(0)
249
- check[:extension] = 'foo'
250
- @validator.validate_check(check)
251
- expect(@validator.reset).to eq(1)
252
- check.delete(:command)
253
- @validator.validate_check(check)
254
- expect(@validator.reset).to eq(0)
255
- check[:extension] = true
256
- @validator.validate_check(check)
257
- expect(@validator.reset).to eq(1)
258
- end
259
-
260
- it "can validate check subdue" do
261
- check = {
262
- :name => "foo",
263
- :command => "true",
264
- :interval => 1,
265
- :standalone => true
266
- }
267
- @validator.validate_check(check)
268
- expect(@validator.reset).to eq(0)
269
- check[:subdue] = true
270
- @validator.validate_check(check)
271
- expect(@validator.reset).to eq(1)
272
- check[:subdue] = {
273
- :days => []
274
- }
275
- @validator.validate_check(check)
276
- expect(@validator.reset).to eq(1)
277
- check[:subdue] = {
278
- :days => {}
279
- }
280
- @validator.validate_check(check)
281
- expect(@validator.reset).to eq(1)
282
- check[:subdue] = {
283
- :days => {
284
- :nope => {}
285
- }
286
- }
287
- @validator.validate_check(check)
288
- expect(@validator.reset).to eq(1)
289
- check[:subdue] = {
290
- :days => {
291
- :nope => []
292
- }
293
- }
294
- @validator.validate_check(check)
295
- expect(@validator.reset).to eq(1)
296
- check[:subdue] = {
297
- :days => {
298
- :all => {}
299
- }
300
- }
301
- @validator.validate_check(check)
302
- expect(@validator.reset).to eq(1)
303
- check[:subdue] = {
304
- :days => {
305
- :all => []
306
- }
307
- }
308
- @validator.validate_check(check)
309
- expect(@validator.reset).to eq(1)
310
- check[:subdue] = {
311
- :days => {
312
- :all => [true]
313
- }
314
- }
315
- @validator.validate_check(check)
316
- expect(@validator.reset).to eq(1)
317
- check[:subdue] = {
318
- :days => {
319
- :all => [
320
- {
321
- :begin => "5:00 PM"
322
- }
323
- ]
324
- }
325
- }
326
- @validator.validate_check(check)
327
- expect(@validator.reset).to eq(1)
328
- check[:subdue] = {
329
- :days => {
330
- :all => [
331
- {
332
- :begin => "5:00 PM",
333
- :end => "nope"
334
- }
335
- ]
336
- }
337
- }
338
- @validator.validate_check(check)
339
- expect(@validator.reset).to eq(1)
340
- check[:subdue] = {
341
- :days => {
342
- :all => [
343
- {
344
- :begin => "5:00 PM",
345
- :end => "8:00 AM"
346
- }
347
- ]
348
- }
349
- }
350
- @validator.validate_check(check)
351
- expect(@validator.reset).to eq(0)
352
- end
353
-
354
- it "can run, validating checks" do
355
- settings = {
356
- :checks => {
357
- :foo => {
358
- :command => "true",
359
- :standalone => true
360
- }
361
- }
362
- }
363
- @validator.run(settings)
364
- expect(@validator.reset).to eq(7)
365
- settings[:checks][:foo][:interval] = 1
366
- @validator.run(settings)
367
- expect(@validator.reset).to eq(6)
368
- end
369
-
370
- it "can validate a filter definition" do
371
- filter = {}
372
- @validator.validate_filter(filter)
373
- expect(@validator.reset).to eq(1)
374
- filter[:attributes] = 1
375
- @validator.validate_filter(filter)
376
- expect(@validator.reset).to eq(1)
377
- filter[:attributes] = {}
378
- @validator.validate_filter(filter)
379
- expect(@validator.reset).to eq(0)
380
- filter[:negate] = "true"
381
- @validator.validate_filter(filter)
382
- expect(@validator.reset).to eq(1)
383
- filter[:negate] = true
384
- @validator.validate_filter(filter)
385
- expect(@validator.reset).to eq(0)
386
- end
387
-
388
- it "can validate filter when" do
389
- filter = {
390
- :attributes => {}
391
- }
392
- @validator.validate_filter(filter)
393
- expect(@validator.reset).to eq(0)
394
- filter[:when] = true
395
- @validator.validate_filter(filter)
396
- expect(@validator.reset).to eq(1)
397
- filter[:when] = {
398
- :days => []
399
- }
400
- @validator.validate_filter(filter)
401
- expect(@validator.reset).to eq(1)
402
- filter[:when] = {
403
- :days => {}
404
- }
405
- @validator.validate_filter(filter)
406
- expect(@validator.reset).to eq(1)
407
- filter[:when] = {
408
- :days => {
409
- :nope => {}
410
- }
411
- }
412
- @validator.validate_filter(filter)
413
- expect(@validator.reset).to eq(1)
414
- filter[:when] = {
415
- :days => {
416
- :nope => []
417
- }
418
- }
419
- @validator.validate_filter(filter)
420
- expect(@validator.reset).to eq(1)
421
- filter[:when] = {
422
- :days => {
423
- :all => {}
424
- }
425
- }
426
- @validator.validate_filter(filter)
427
- expect(@validator.reset).to eq(1)
428
- filter[:when] = {
429
- :days => {
430
- :all => []
431
- }
432
- }
433
- @validator.validate_filter(filter)
434
- expect(@validator.reset).to eq(1)
435
- filter[:when] = {
436
- :days => {
437
- :all => [true]
438
- }
439
- }
440
- @validator.validate_filter(filter)
441
- expect(@validator.reset).to eq(1)
442
- filter[:when] = {
443
- :days => {
444
- :all => [
445
- {
446
- :begin => "5:00 PM"
447
- }
448
- ]
449
- }
450
- }
451
- @validator.validate_filter(filter)
452
- expect(@validator.reset).to eq(1)
453
- filter[:when] = {
454
- :days => {
455
- :all => [
456
- {
457
- :begin => "5:00 PM",
458
- :end => "nope"
459
- }
460
- ]
461
- }
462
- }
463
- @validator.validate_filter(filter)
464
- expect(@validator.reset).to eq(1)
465
- filter[:when] = {
466
- :days => {
467
- :all => [
468
- {
469
- :begin => "5:00 PM",
470
- :end => "8:00 AM"
471
- }
472
- ]
473
- }
474
- }
475
- @validator.validate_filter(filter)
476
- expect(@validator.reset).to eq(0)
477
- end
478
-
479
- it "can validate a mutator definition" do
480
- mutator = {}
481
- @validator.validate_mutator(mutator)
482
- expect(@validator.reset).to eq(1)
483
- mutator[:command] = "cat"
484
- @validator.validate_mutator(mutator)
485
- expect(@validator.reset).to eq(0)
486
- mutator[:timeout] = "foo"
487
- @validator.validate_mutator(mutator)
488
- expect(@validator.reset).to eq(1)
489
- mutator[:timeout] = 1.5
490
- @validator.validate_mutator(mutator)
491
- expect(@validator.reset).to eq(0)
492
- mutator[:timeout] = 1
493
- @validator.validate_mutator(mutator)
494
- expect(@validator.reset).to eq(0)
495
- end
496
-
497
- it "can validate a handler definition" do
498
- handler = {}
499
- @validator.validate_handler(handler)
500
- expect(@validator.reset).to eq(2)
501
- handler[:type] = 1
502
- @validator.validate_handler(handler)
503
- expect(@validator.reset).to eq(2)
504
- handler[:type] = "unknown"
505
- @validator.validate_handler(handler)
506
- expect(@validator.reset).to eq(1)
507
- handler[:type] = "pipe"
508
- @validator.validate_handler(handler)
509
- expect(@validator.reset).to eq(1)
510
- handler[:command] = 1
511
- @validator.validate_handler(handler)
512
- expect(@validator.reset).to eq(1)
513
- handler[:command] = "cat"
514
- @validator.validate_handler(handler)
515
- expect(@validator.reset).to eq(0)
516
- handler[:timeout] = "foo"
517
- @validator.validate_handler(handler)
518
- expect(@validator.reset).to eq(1)
519
- handler[:timeout] = 1
520
- @validator.validate_handler(handler)
521
- expect(@validator.reset).to eq(0)
522
- handler[:mutator] = 1
523
- @validator.validate_handler(handler)
524
- expect(@validator.reset).to eq(1)
525
- handler[:mutator] = "foo"
526
- @validator.validate_handler(handler)
527
- expect(@validator.reset).to eq(0)
528
- handler[:handle_flapping] = "true"
529
- @validator.validate_handler(handler)
530
- expect(@validator.reset).to eq(1)
531
- handler[:handle_flapping] = true
532
- @validator.validate_handler(handler)
533
- expect(@validator.reset).to eq(0)
534
- handler[:handle_flapping] = false
535
- @validator.validate_handler(handler)
536
- expect(@validator.reset).to eq(0)
537
- handler[:filter] = 1
538
- @validator.validate_handler(handler)
539
- expect(@validator.reset).to eq(1)
540
- handler[:filter] = "foo"
541
- @validator.validate_handler(handler)
542
- expect(@validator.reset).to eq(0)
543
- handler[:filters] = "foo"
544
- @validator.validate_handler(handler)
545
- expect(@validator.reset).to eq(1)
546
- handler[:filters] = []
547
- @validator.validate_handler(handler)
548
- expect(@validator.reset).to eq(0)
549
- handler[:filters] = [1]
550
- @validator.validate_handler(handler)
551
- expect(@validator.reset).to eq(1)
552
- handler[:filters] = ["foo"]
553
- @validator.validate_handler(handler)
554
- expect(@validator.reset).to eq(0)
555
- handler[:severities] = "foo"
556
- @validator.validate_handler(handler)
557
- expect(@validator.reset).to eq(1)
558
- handler[:severities] = []
559
- @validator.validate_handler(handler)
560
- expect(@validator.reset).to eq(0)
561
- handler[:severities] = ["foo"]
562
- @validator.validate_handler(handler)
563
- expect(@validator.reset).to eq(1)
564
- handler[:severities] = ["warning", "unknown"]
565
- @validator.validate_handler(handler)
566
- expect(@validator.reset).to eq(0)
567
- end
568
-
569
- it "can validate a tcp/udp handler definition" do
570
- handler = {
571
- :type => "tcp"
572
- }
573
- @validator.validate_handler(handler)
574
- expect(@validator.reset).to eq(1)
575
- handler[:socket] = {}
576
- @validator.validate_handler(handler)
577
- expect(@validator.reset).to eq(2)
578
- handler[:socket][:host] = 1
579
- @validator.validate_handler(handler)
580
- expect(@validator.reset).to eq(2)
581
- handler[:socket][:host] = "127.0.0.1"
582
- @validator.validate_handler(handler)
583
- expect(@validator.reset).to eq(1)
584
- handler[:socket][:port] = "foo"
585
- @validator.validate_handler(handler)
586
- expect(@validator.reset).to eq(1)
587
- handler[:socket][:port] = 2003
588
- @validator.validate_handler(handler)
589
- expect(@validator.reset).to eq(0)
590
- end
591
-
592
- it "can validate a transport handler definition" do
593
- handler = {
594
- :type => "transport"
595
- }
596
- @validator.validate_handler(handler)
597
- expect(@validator.reset).to eq(1)
598
- handler[:pipe] = 1
599
- @validator.validate_handler(handler)
600
- expect(@validator.reset).to eq(1)
601
- handler[:pipe] = {}
602
- @validator.validate_handler(handler)
603
- expect(@validator.reset).to eq(3)
604
- handler[:pipe][:type] = 1
605
- @validator.validate_handler(handler)
606
- expect(@validator.reset).to eq(3)
607
- handler[:pipe][:type] = "unknown"
608
- @validator.validate_handler(handler)
609
- expect(@validator.reset).to eq(2)
610
- handler[:pipe][:type] = "direct"
611
- @validator.validate_handler(handler)
612
- expect(@validator.reset).to eq(1)
613
- handler[:pipe][:name] = 1
614
- @validator.validate_handler(handler)
615
- expect(@validator.reset).to eq(1)
616
- handler[:pipe][:name] = "foo"
617
- @validator.validate_handler(handler)
618
- expect(@validator.reset).to eq(0)
619
- handler[:pipe][:options] = 1
620
- @validator.validate_handler(handler)
621
- expect(@validator.reset).to eq(1)
622
- handler[:pipe][:options] = {}
623
- @validator.validate_handler(handler)
624
- expect(@validator.reset).to eq(0)
625
- end
626
-
627
- it "can validate a handler set definition" do
628
- handler = {
629
- :type => "set"
630
- }
631
- @validator.validate_handler(handler)
632
- expect(@validator.reset).to eq(1)
633
- handler[:handlers] = 1
634
- @validator.validate_handler(handler)
635
- expect(@validator.reset).to eq(1)
636
- handler[:handlers] = "default"
637
- @validator.validate_handler(handler)
638
- expect(@validator.reset).to eq(1)
639
- handler[:handlers] = [1]
640
- @validator.validate_handler(handler)
641
- expect(@validator.reset).to eq(1)
642
- handler[:handlers] = ["default"]
643
- @validator.validate_handler(handler)
644
- expect(@validator.reset).to eq(0)
645
- end
646
-
647
- it "can validate a client definition" do
648
- client = true
649
- @validator.validate_client(client)
650
- expect(@validator.reset).to eq(1)
651
- client = {}
652
- @validator.validate_client(client)
653
- expect(@validator.reset).to eq(4)
654
- client[:name] = 1
655
- @validator.validate_client(client)
656
- expect(@validator.reset).to eq(4)
657
- client[:name] = "foo bar"
658
- @validator.validate_client(client)
659
- expect(@validator.reset).to eq(3)
660
- client[:name] = "foo\nbar"
661
- @validator.validate_client(client)
662
- expect(@validator.reset).to eq(3)
663
- client[:name] = "foo"
664
- @validator.validate_client(client)
665
- expect(@validator.reset).to eq(2)
666
- client[:address] = 1
667
- @validator.validate_client(client)
668
- expect(@validator.reset).to eq(2)
669
- client[:address] = "127.0.0.1"
670
- @validator.validate_client(client)
671
- expect(@validator.reset).to eq(1)
672
- client[:subscriptions] = true
673
- @validator.validate_client(client)
674
- expect(@validator.reset).to eq(1)
675
- client[:subscriptions] = []
676
- @validator.validate_client(client)
677
- expect(@validator.reset).to eq(0)
678
- client[:subscriptions] = [1]
679
- @validator.validate_client(client)
680
- expect(@validator.reset).to eq(1)
681
- client[:subscriptions] = ["bar"]
682
- @validator.validate_client(client)
683
- expect(@validator.reset).to eq(0)
684
- client[:redact] = true
685
- @validator.validate_client(client)
686
- expect(@validator.reset).to eq(1)
687
- client[:redact] = []
688
- @validator.validate_client(client)
689
- expect(@validator.reset).to eq(0)
690
- client[:redact] = [1]
691
- @validator.validate_client(client)
692
- expect(@validator.reset).to eq(1)
693
- client[:redact] = ["secret"]
694
- @validator.validate_client(client)
695
- expect(@validator.reset).to eq(0)
696
- client[:safe_mode] = 1
697
- @validator.validate_client(client)
698
- expect(@validator.reset).to eq(1)
699
- client[:safe_mode] = false
700
- @validator.validate_client(client)
701
- expect(@validator.reset).to eq(0)
702
- client[:signature] = 1
703
- @validator.validate_client(client)
704
- expect(@validator.reset).to eq(1)
705
- client[:signature] = "foo"
706
- @validator.validate_client(client)
707
- expect(@validator.reset).to eq(0)
708
- end
709
-
710
- it "can validate client socket" do
711
- client = {
712
- :name => "foo",
713
- :address => "127.0.0.1",
714
- :subscriptions => ["bar"]
715
- }
716
- @validator.validate_client(client)
717
- expect(@validator.reset).to eq(0)
718
- client[:socket] = true
719
- @validator.validate_client(client)
720
- expect(@validator.reset).to eq(1)
721
- client[:socket] = {}
722
- @validator.validate_client(client)
723
- expect(@validator.reset).to eq(0)
724
- client[:socket][:bind] = true
725
- @validator.validate_client(client)
726
- expect(@validator.reset).to eq(1)
727
- client[:socket][:bind] = "127.0.0.1"
728
- @validator.validate_client(client)
729
- expect(@validator.reset).to eq(0)
730
- client[:socket][:port] = "2012"
731
- @validator.validate_client(client)
732
- expect(@validator.reset).to eq(1)
733
- client[:socket][:port] = 2012
734
- @validator.validate_client(client)
735
- expect(@validator.reset).to eq(0)
736
- end
737
-
738
- it "can validate client keepalives" do
739
- client = {
740
- :name => "foo",
741
- :address => "127.0.0.1",
742
- :subscriptions => ["bar"]
743
- }
744
- @validator.validate_client(client)
745
- expect(@validator.reset).to eq(0)
746
- client[:keepalives] = 1
747
- @validator.validate_client(client)
748
- expect(@validator.reset).to eq(1)
749
- client[:keepalives] = "true"
750
- @validator.validate_client(client)
751
- expect(@validator.reset).to eq(1)
752
- client[:keepalives] = true
753
- @validator.validate_client(client)
754
- expect(@validator.reset).to eq(0)
755
- client[:keepalives] = false
756
- @validator.validate_client(client)
757
- expect(@validator.reset).to eq(0)
758
- end
759
-
760
- it "can validate client keepalive" do
761
- client = {
762
- :name => "foo",
763
- :address => "127.0.0.1",
764
- :subscriptions => ["bar"]
765
- }
766
- @validator.validate_client(client)
767
- expect(@validator.reset).to eq(0)
768
- client[:keepalive] = true
769
- @validator.validate_client(client)
770
- expect(@validator.reset).to eq(1)
771
- client[:keepalive] = {}
772
- @validator.validate_client(client)
773
- expect(@validator.reset).to eq(0)
774
- client[:keepalive][:handler] = 1
775
- @validator.validate_client(client)
776
- expect(@validator.reset).to eq(1)
777
- client[:keepalive][:handler] = "foo"
778
- @validator.validate_client(client)
779
- expect(@validator.reset).to eq(0)
780
- client[:keepalive][:handlers] = 1
781
- @validator.validate_client(client)
782
- expect(@validator.reset).to eq(1)
783
- client[:keepalive][:handlers] = [1]
784
- @validator.validate_client(client)
785
- expect(@validator.reset).to eq(1)
786
- client[:keepalive][:handlers] = ["foo"]
787
- @validator.validate_client(client)
788
- expect(@validator.reset).to eq(0)
789
- client[:keepalive][:thresholds] = true
790
- @validator.validate_client(client)
791
- expect(@validator.reset).to eq(1)
792
- client[:keepalive][:thresholds] = {}
793
- @validator.validate_client(client)
794
- expect(@validator.reset).to eq(0)
795
- client[:keepalive][:thresholds][:warning] = "60"
796
- @validator.validate_client(client)
797
- expect(@validator.reset).to eq(1)
798
- client[:keepalive][:thresholds][:warning] = 60
799
- @validator.validate_client(client)
800
- expect(@validator.reset).to eq(0)
801
- client[:keepalive][:thresholds][:critical] = "90"
802
- @validator.validate_client(client)
803
- expect(@validator.reset).to eq(1)
804
- client[:keepalive][:thresholds][:critical] = 90
805
- @validator.validate_client(client)
806
- expect(@validator.reset).to eq(0)
807
- end
808
-
809
- it "can validate client registration" do
810
- client = {
811
- :name => "foo",
812
- :address => "127.0.0.1",
813
- :subscriptions => ["bar"]
814
- }
815
- @validator.validate_client(client)
816
- expect(@validator.reset).to eq(0)
817
- client[:registration] = true
818
- @validator.validate_client(client)
819
- expect(@validator.reset).to eq(1)
820
- client[:registration] = {}
821
- @validator.validate_client(client)
822
- expect(@validator.reset).to eq(0)
823
- client[:registration][:handler] = 1
824
- @validator.validate_client(client)
825
- expect(@validator.reset).to eq(1)
826
- client[:registration][:handler] = "foo"
827
- @validator.validate_client(client)
828
- expect(@validator.reset).to eq(0)
829
- client[:registration][:handlers] = 1
830
- @validator.validate_client(client)
831
- expect(@validator.reset).to eq(1)
832
- client[:registration][:handlers] = [1]
833
- @validator.validate_client(client)
834
- expect(@validator.reset).to eq(1)
835
- client[:registration][:handlers] = ["foo"]
836
- @validator.validate_client(client)
837
- expect(@validator.reset).to eq(0)
838
- end
839
-
840
- it "can run, validating client" do
841
- settings = {
842
- :client => {
843
- :name => "foo",
844
- :address => "127.0.0.1"
845
- }
846
- }
847
- @validator.run(settings, "client")
848
- expect(@validator.reset).to eq(8)
849
- settings[:client][:subscriptions] = ["bar"]
850
- @validator.run(settings, "client")
851
- expect(@validator.reset).to eq(7)
852
- end
853
-
854
- it "can validate an api definition" do
855
- api = nil
856
- @validator.validate_api(api)
857
- expect(@validator.reset).to eq(0)
858
- api = true
859
- @validator.validate_api(api)
860
- expect(@validator.reset).to eq(1)
861
- api = {}
862
- @validator.validate_api(api)
863
- expect(@validator.reset).to eq(0)
864
- api[:port] = true
865
- @validator.validate_api(api)
866
- expect(@validator.reset).to eq(1)
867
- api[:port] = 4567
868
- @validator.validate_api(api)
869
- expect(@validator.reset).to eq(0)
870
- api[:bind] = true
871
- @validator.validate_api(api)
872
- expect(@validator.reset).to eq(1)
873
- api[:bind] = "127.0.0.1"
874
- @validator.validate_api(api)
875
- expect(@validator.reset).to eq(0)
876
- api[:user] = 1
877
- @validator.validate_api(api)
878
- expect(@validator.reset).to eq(2)
879
- api[:user] = "foo"
880
- @validator.validate_api(api)
881
- expect(@validator.reset).to eq(1)
882
- api[:password] = 1
883
- @validator.validate_api(api)
884
- expect(@validator.reset).to eq(1)
885
- api[:password] = "bar"
886
- @validator.validate_api(api)
887
- expect(@validator.reset).to eq(0)
888
- end
889
-
890
- it "can run, validating api" do
891
- settings = {
892
- :api => {
893
- :port => "4567"
894
- }
895
- }
896
- @validator.run(settings, "api")
897
- expect(@validator.reset).to eq(8)
898
- settings[:api][:port] = 4567
899
- @validator.run(settings, "api")
900
- expect(@validator.reset).to eq(7)
901
- end
902
-
903
- it "can validate a extension definition" do
904
- extension = {}
905
- @validator.validate_extension(extension)
906
- expect(@validator.reset).to eq(0)
907
- extension[:gem] = 1
908
- @validator.validate_extension(extension)
909
- expect(@validator.reset).to eq(1)
910
- extension[:gem] = true
911
- @validator.validate_extension(extension)
912
- expect(@validator.reset).to eq(1)
913
- extension[:gem] = "test"
914
- @validator.validate_extension(extension)
915
- expect(@validator.reset).to eq(0)
916
- extension[:version] = 1
917
- @validator.validate_extension(extension)
918
- expect(@validator.reset).to eq(1)
919
- extension[:version] = false
920
- @validator.validate_extension(extension)
921
- expect(@validator.reset).to eq(1)
922
- extension[:version] = "1.0.0"
923
- @validator.validate_extension(extension)
924
- expect(@validator.reset).to eq(0)
925
- end
926
-
927
- it "can run, validating extensions" do
928
- settings = {
929
- :extensions => {
930
- :foo => {
931
- :gem => "sensu-extensions-test",
932
- :version => 1
933
- }
934
- }
935
- }
936
- @validator.run(settings)
937
- expect(@validator.reset).to eq(7)
938
- settings[:extensions][:foo][:version] = "1.0.0"
939
- @validator.run(settings)
940
- expect(@validator.reset).to eq(6)
941
- end
942
- end