sensu-settings 8.0.0 → 9.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ecff7fd492c9359b7cd7acd1a5d96cbd58dbb4ba
4
- data.tar.gz: c28ea05aada28e40f753142d7028a62106926ae2
3
+ metadata.gz: 3cbf9a4e7d37ba04e4fbbcfe697fcadb75a448c2
4
+ data.tar.gz: c6c4db9dcbf1f9f076aa6f5f9770c865b9ed1fe0
5
5
  SHA512:
6
- metadata.gz: dd1cb0e18dfa49dd1eddc80ec674d63306b1ec546ea346ff68fdec00e5938d114cd6fb2f89838c80fac442e39f610df8a5efa0a7ad8388b32f244c0684b3450f
7
- data.tar.gz: f27ce319271b20543fa332d1945ca064965f6ea27a2658461df5e6e452339925933c898c46178d4a3a1c31def07f6d3e4de536916daec878b18c1042c0b21ec1
6
+ metadata.gz: 7b07bc280b7a7c920cc3f4eac878f49645bf34a48812c021cb2c111d55a0b8a23fbc9594a8aa8180491da316386ff2ae8d7f84126e7e0ba5b46cc7a10d5cc558
7
+ data.tar.gz: 5aff8a7a597d6d6c8ceeaa061663fa403167003c734c7b53dd6bfb7c2c4ab7cc8c5e2900b8c66d694b2ead2f60953d4151d8c026b45a3f8684d1fb21e60f6399
@@ -1,6 +1,6 @@
1
1
  require "sensu/settings/validators/sensu"
2
2
  require "sensu/settings/validators/transport"
3
- require "sensu/settings/validators/subdue"
3
+ require "sensu/settings/validators/time_window"
4
4
  require "sensu/settings/validators/check"
5
5
  require "sensu/settings/validators/filter"
6
6
  require "sensu/settings/validators/mutator"
@@ -14,7 +14,7 @@ module Sensu
14
14
  module Validators
15
15
  include Sensu
16
16
  include Transport
17
- include Subdue
17
+ include TimeWindow
18
18
  include Check
19
19
  include Filter
20
20
  include Mutator
@@ -129,6 +129,14 @@ module Sensu
129
129
  end
130
130
  end
131
131
 
132
+ # Validate check subdue.
133
+ # Validates: subdue
134
+ #
135
+ # @param check [Hash] sensu check definition.
136
+ def validate_check_subdue(check)
137
+ validate_time_windows(check, :subdue)
138
+ end
139
+
132
140
  # Validate a Sensu check definition.
133
141
  #
134
142
  # @param check [Hash] sensu check definition.
@@ -141,7 +149,7 @@ module Sensu
141
149
  validate_check_ttl(check) if check[:ttl]
142
150
  validate_check_aggregate(check)
143
151
  validate_check_flap_detection(check)
144
- validate_subdue(check) if check[:subdue]
152
+ validate_check_subdue(check) if check[:subdue]
145
153
  end
146
154
  end
147
155
  end
@@ -2,6 +2,14 @@ module Sensu
2
2
  module Settings
3
3
  module Validators
4
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, :when)
11
+ end
12
+
5
13
  # Validate a Sensu filter definition.
6
14
  # Validates: attributes, negate
7
15
  #
@@ -11,6 +19,7 @@ module Sensu
11
19
  invalid(filter, "filter negate must be boolean")
12
20
  must_be_a_hash(filter[:attributes]) ||
13
21
  invalid(filter, "filter attributes must be a hash")
22
+ validate_filter_when(filter) if filter[:when]
14
23
  end
15
24
  end
16
25
  end
@@ -110,7 +110,7 @@ module Sensu
110
110
  end
111
111
 
112
112
  # Validate a Sensu handler definition.
113
- # Validates: timeout, mutator, handle_flapping
113
+ # Validates: timeout, mutator, handle_flapping, handle_silenced
114
114
  #
115
115
  # @param handler [Hash] sensu handler definition.
116
116
  def validate_handler(handler)
@@ -123,9 +123,8 @@ module Sensu
123
123
  invalid(handler, "handler mutator must be a string")
124
124
  must_be_boolean_if_set(handler[:handle_flapping]) ||
125
125
  invalid(handler, "handler handle_flapping must be boolean")
126
- if handler[:subdue]
127
- validate_subdue(handler)
128
- end
126
+ must_be_boolean_if_set(handler[:handle_silenced]) ||
127
+ invalid(handler, "handler handle_silenced must be boolean")
129
128
  end
130
129
  end
131
130
  end
@@ -0,0 +1,65 @@
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 condition [Hash] to have begin and end validated.
11
+ def validate_time_window_condition(definition, scope, condition)
12
+ if is_a_hash?(condition)
13
+ if either_are_set?(condition[:begin], condition[:end])
14
+ must_be_time(condition[:begin], condition[:end]) ||
15
+ invalid(definition, "#{scope} begin and end times must be valid")
16
+ end
17
+ else
18
+ invalid(definition, "#{scope} must be a hash")
19
+ end
20
+ end
21
+
22
+ # Validate time windows
23
+ # Validates: days
24
+ #
25
+ # @param definition [Hash] sensu definition.
26
+ # @param scope [String] definition scope to validate.
27
+ # @param days [String] time window days to validate.
28
+ def validate_time_windows_days(definition, scope, 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
+ conditions.each do |condition|
34
+ validate_time_window_condition(definition, scope, condition)
35
+ end
36
+ else
37
+ invalid(definition, "#{scope} #{day} time windows must be in an array")
38
+ end
39
+ end
40
+ else
41
+ invalid(definition, "#{scope} days must be valid days of the week or 'all'")
42
+ end
43
+ end
44
+
45
+ # Validate time windows
46
+ # Validates: days
47
+ #
48
+ # @param definition [Hash] sensu definition.
49
+ # @param scope [String] definition scope to validate.
50
+ def validate_time_windows(definition, scope)
51
+ if is_a_hash?(definition[scope])
52
+ days = definition[scope][:days]
53
+ must_be_a_hash_if_set(days) ||
54
+ invalid(definition, "#{scope} days must be a hash")
55
+ if is_a_hash?(days)
56
+ validate_time_windows_days(definition, scope, days)
57
+ end
58
+ else
59
+ invalid(definition, "#{scope} must be a hash")
60
+ end
61
+ end
62
+ end
63
+ end
64
+ end
65
+ end
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = "sensu-settings"
5
- spec.version = "8.0.0"
5
+ spec.version = "9.0.0"
6
6
  spec.authors = ["Sean Porter"]
7
7
  spec.email = ["portertech@gmail.com"]
8
8
  spec.summary = "The Sensu settings library, loader and validator"
@@ -270,56 +270,72 @@ describe "Sensu::Settings::Validator" do
270
270
  @validator.validate_check(check)
271
271
  expect(@validator.reset).to eq(1)
272
272
  check[:subdue] = {
273
- :at => "unknown"
273
+ :days => []
274
274
  }
275
275
  @validator.validate_check(check)
276
276
  expect(@validator.reset).to eq(1)
277
- check[:subdue][:at] = "publisher"
278
- @validator.validate_check(check)
279
- expect(@validator.reset).to eq(0)
280
- check[:subdue][:at] = "handler"
281
- @validator.validate_check(check)
282
- expect(@validator.reset).to eq(0)
283
- check[:subdue][:begin] = "14:30"
284
- check[:subdue][:end] = 1
285
- @validator.validate_check(check)
286
- expect(@validator.reset).to eq(1)
287
- check[:subdue][:begin] = 1
288
- check[:subdue][:end] = "14:30"
289
- @validator.validate_check(check)
290
- expect(@validator.reset).to eq(1)
291
- check[:subdue][:begin] = "14:30"
292
- check[:subdue][:end] = "16:30"
277
+ check[:subdue] = {
278
+ :days => {}
279
+ }
293
280
  @validator.validate_check(check)
294
281
  expect(@validator.reset).to eq(0)
295
- check[:subdue][:days] = 1
296
- @validator.validate_check(check)
297
- expect(@validator.reset).to eq(1)
298
- check[:subdue][:days] = ["unknown"]
282
+ check[:subdue] = {
283
+ :days => {
284
+ :nope => {}
285
+ }
286
+ }
299
287
  @validator.validate_check(check)
300
288
  expect(@validator.reset).to eq(1)
301
- check[:subdue][:days] = [true]
289
+ check[:subdue] = {
290
+ :days => {
291
+ :nope => []
292
+ }
293
+ }
302
294
  @validator.validate_check(check)
303
295
  expect(@validator.reset).to eq(1)
304
- check[:subdue][:days] = ["monday"]
305
- @validator.validate_check(check)
306
- expect(@validator.reset).to eq(0)
307
- check[:subdue][:exceptions] = 1
296
+ check[:subdue] = {
297
+ :days => {
298
+ :all => {}
299
+ }
300
+ }
308
301
  @validator.validate_check(check)
309
302
  expect(@validator.reset).to eq(1)
310
- check[:subdue][:exceptions] = []
303
+ check[:subdue] = {
304
+ :days => {
305
+ :all => []
306
+ }
307
+ }
311
308
  @validator.validate_check(check)
312
309
  expect(@validator.reset).to eq(0)
313
- check[:subdue][:exceptions] = [1]
310
+ check[:subdue] = {
311
+ :days => {
312
+ :all => [true]
313
+ }
314
+ }
314
315
  @validator.validate_check(check)
315
316
  expect(@validator.reset).to eq(1)
316
- check[:subdue][:exceptions] = [{}]
317
- @validator.validate_check(check)
318
- expect(@validator.reset).to eq(0)
319
- check[:subdue][:exceptions] = [{:begin => "15:00"}]
317
+ check[:subdue] = {
318
+ :days => {
319
+ :all => [
320
+ {
321
+ :begin => "5:00 PM",
322
+ :end => "nope"
323
+ }
324
+ ]
325
+ }
326
+ }
320
327
  @validator.validate_check(check)
321
328
  expect(@validator.reset).to eq(1)
322
- check[:subdue][:exceptions] = [{:begin => "15:00", :end => "15:30"}]
329
+ check[:subdue] = {
330
+ :days => {
331
+ :all => [
332
+ {
333
+ :begin => "5:00 PM",
334
+ :end => "8:00 AM"
335
+ }
336
+ ]
337
+ }
338
+ }
323
339
  @validator.validate_check(check)
324
340
  expect(@validator.reset).to eq(0)
325
341
  end
@@ -358,6 +374,86 @@ describe "Sensu::Settings::Validator" do
358
374
  expect(@validator.reset).to eq(0)
359
375
  end
360
376
 
377
+ it "can validate filter when" do
378
+ filter = {
379
+ :attributes => {}
380
+ }
381
+ @validator.validate_filter(filter)
382
+ expect(@validator.reset).to eq(0)
383
+ filter[:when] = true
384
+ @validator.validate_filter(filter)
385
+ expect(@validator.reset).to eq(1)
386
+ filter[:when] = {
387
+ :days => []
388
+ }
389
+ @validator.validate_filter(filter)
390
+ expect(@validator.reset).to eq(1)
391
+ filter[:when] = {
392
+ :days => {}
393
+ }
394
+ @validator.validate_filter(filter)
395
+ expect(@validator.reset).to eq(0)
396
+ filter[:when] = {
397
+ :days => {
398
+ :nope => {}
399
+ }
400
+ }
401
+ @validator.validate_filter(filter)
402
+ expect(@validator.reset).to eq(1)
403
+ filter[:when] = {
404
+ :days => {
405
+ :nope => []
406
+ }
407
+ }
408
+ @validator.validate_filter(filter)
409
+ expect(@validator.reset).to eq(1)
410
+ filter[:when] = {
411
+ :days => {
412
+ :all => {}
413
+ }
414
+ }
415
+ @validator.validate_filter(filter)
416
+ expect(@validator.reset).to eq(1)
417
+ filter[:when] = {
418
+ :days => {
419
+ :all => []
420
+ }
421
+ }
422
+ @validator.validate_filter(filter)
423
+ expect(@validator.reset).to eq(0)
424
+ filter[:when] = {
425
+ :days => {
426
+ :all => [true]
427
+ }
428
+ }
429
+ @validator.validate_filter(filter)
430
+ expect(@validator.reset).to eq(1)
431
+ filter[:when] = {
432
+ :days => {
433
+ :all => [
434
+ {
435
+ :begin => "5:00 PM",
436
+ :end => "nope"
437
+ }
438
+ ]
439
+ }
440
+ }
441
+ @validator.validate_filter(filter)
442
+ expect(@validator.reset).to eq(1)
443
+ filter[:when] = {
444
+ :days => {
445
+ :all => [
446
+ {
447
+ :begin => "5:00 PM",
448
+ :end => "8:00 AM"
449
+ }
450
+ ]
451
+ }
452
+ }
453
+ @validator.validate_filter(filter)
454
+ expect(@validator.reset).to eq(0)
455
+ end
456
+
361
457
  it "can validate a mutator definition" do
362
458
  mutator = {}
363
459
  @validator.validate_mutator(mutator)
@@ -526,26 +622,6 @@ describe "Sensu::Settings::Validator" do
526
622
  expect(@validator.reset).to eq(0)
527
623
  end
528
624
 
529
- it "can validate handler subdue" do
530
- handler = {
531
- :name => "foo",
532
- :type => "pipe",
533
- :command => "cat"
534
- }
535
- @validator.validate_handler(handler)
536
- expect(@validator.reset).to eq(0)
537
- handler[:subdue] = true
538
- @validator.validate_handler(handler)
539
- expect(@validator.reset).to eq(1)
540
- handler[:subdue] = {
541
- :at => "handler",
542
- :begin => "14:30",
543
- :end => "15:45"
544
- }
545
- @validator.validate_handler(handler)
546
- expect(@validator.reset).to eq(0)
547
- end
548
-
549
625
  it "can validate a client definition" do
550
626
  client = true
551
627
  @validator.validate_client(client)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sensu-settings
3
3
  version: !ruby/object:Gem::Version
4
- version: 8.0.0
4
+ version: 9.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sean Porter
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-08-11 00:00:00.000000000 Z
11
+ date: 2016-08-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sensu-json
@@ -107,7 +107,7 @@ files:
107
107
  - lib/sensu/settings/validators/handler.rb
108
108
  - lib/sensu/settings/validators/mutator.rb
109
109
  - lib/sensu/settings/validators/sensu.rb
110
- - lib/sensu/settings/validators/subdue.rb
110
+ - lib/sensu/settings/validators/time_window.rb
111
111
  - lib/sensu/settings/validators/transport.rb
112
112
  - sensu-settings.gemspec
113
113
  - spec/assets/alternative/conf.d/loop
@@ -1,68 +0,0 @@
1
- module Sensu
2
- module Settings
3
- module Validators
4
- module Subdue
5
- # Validate subdue time.
6
- # Validates: begin, end
7
- #
8
- # @param scope [String] definition scope to report under.
9
- # @param definition [Hash] sensu definition.
10
- # @param object [Hash] to have begin and end validated.
11
- def validate_subdue_time(scope, definition, object)
12
- if is_a_hash?(object)
13
- if either_are_set?(object[:begin], object[:end])
14
- must_be_time(object[:begin], object[:end]) ||
15
- invalid(definition, "#{scope} begin and end times must be valid")
16
- end
17
- else
18
- invalid(definition, "#{scope} must be a hash")
19
- end
20
- end
21
-
22
- # Validate subdue days.
23
- # Validates: days
24
- #
25
- # @param definition [Hash] sensu definition.
26
- def validate_subdue_days(definition)
27
- subdue = definition[:subdue]
28
- must_be_an_array_if_set(subdue[:days]) ||
29
- invalid(definition, "subdue days must be an array")
30
- if is_an_array?(subdue[:days])
31
- days = %w[sunday monday tuesday wednesday thursday friday saturday]
32
- must_be_either(days, subdue[:days]) ||
33
- invalid(definition, "subdue days must be valid days of the week")
34
- end
35
- end
36
-
37
- # Validate subdue exceptions.
38
- # Validates: exceptions (begin, end)
39
- #
40
- # @param definition [Hash] sensu definition.
41
- def validate_subdue_exceptions(definition)
42
- subdue = definition[:subdue]
43
- must_be_an_array_if_set(subdue[:exceptions]) ||
44
- invalid(definition, "subdue exceptions must be an array")
45
- if is_an_array?(subdue[:exceptions])
46
- subdue[:exceptions].each do |exception|
47
- validate_subdue_time("subdue exceptions", definition, exception)
48
- end
49
- end
50
- end
51
-
52
- # Validate Sensu subdue, for either a check or handler definition.
53
- #
54
- # @param definition [Hash] sensu definition.
55
- def validate_subdue(definition)
56
- subdue = definition[:subdue]
57
- validate_subdue_time("subdue", definition, subdue)
58
- if is_a_hash?(subdue)
59
- must_be_either_if_set(%w[handler publisher], subdue[:at]) ||
60
- invalid(definition, "subdue at must be either handler or publisher")
61
- validate_subdue_days(definition)
62
- validate_subdue_exceptions(definition)
63
- end
64
- end
65
- end
66
- end
67
- end
68
- end