sensu-settings 9.0.0 → 9.1.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: 3cbf9a4e7d37ba04e4fbbcfe697fcadb75a448c2
4
- data.tar.gz: c6c4db9dcbf1f9f076aa6f5f9770c865b9ed1fe0
3
+ metadata.gz: 8b950b91c23d3c11482819e912226b3b86ea4a34
4
+ data.tar.gz: 29c40cb6cca44e4b658c667e928ed4817256bdd3
5
5
  SHA512:
6
- metadata.gz: 7b07bc280b7a7c920cc3f4eac878f49645bf34a48812c021cb2c111d55a0b8a23fbc9594a8aa8180491da316386ff2ae8d7f84126e7e0ba5b46cc7a10d5cc558
7
- data.tar.gz: 5aff8a7a597d6d6c8ceeaa061663fa403167003c734c7b53dd6bfb7c2c4ab7cc8c5e2900b8c66d694b2ead2f60953d4151d8c026b45a3f8684d1fb21e60f6399
6
+ metadata.gz: 71fe52ecfd5e5b7c5248d584dfb38d599db6641a3bd9fae6af2a43ddfd15589f9d21872b9fd0107cc991f8f62582d3abcb1efe47c031a1cdbd9cd4b58652b457
7
+ data.tar.gz: 30dd3f1dad803d23d0d213cc16697f25654eeefe67e14f752272171c0c03fad9a9b7dddd8ecd22f05827bbf51297d7e3fa7c147c331841809e888bc497b7819c
@@ -134,7 +134,7 @@ module Sensu
134
134
  #
135
135
  # @param check [Hash] sensu check definition.
136
136
  def validate_check_subdue(check)
137
- validate_time_windows(check, :subdue)
137
+ validate_time_windows(check, "check", :subdue)
138
138
  end
139
139
 
140
140
  # Validate a Sensu check definition.
@@ -7,7 +7,7 @@ module Sensu
7
7
  #
8
8
  # @param filter [Hash] sensu filter definition.
9
9
  def validate_filter_when(filter)
10
- validate_time_windows(filter, :when)
10
+ validate_time_windows(filter, "filter", :when)
11
11
  end
12
12
 
13
13
  # Validate a Sensu filter definition.
@@ -7,38 +7,42 @@ module Sensu
7
7
  #
8
8
  # @param definition [Hash] sensu definition.
9
9
  # @param scope [String] definition scope to validate.
10
+ # @param attribute [String] definition attribute to validate.
10
11
  # @param condition [Hash] to have begin and end validated.
11
- def validate_time_window_condition(definition, scope, condition)
12
+ def validate_time_window_condition(definition, scope, attribute, condition)
12
13
  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
14
+ must_be_time(condition[:begin], condition[:end]) ||
15
+ invalid(definition, "#{scope} #{attribute} day time window begin and end times must be valid")
17
16
  else
18
- invalid(definition, "#{scope} must be a hash")
17
+ invalid(definition, "#{scope} #{attribute} day time window must be a hash")
19
18
  end
20
19
  end
21
20
 
22
- # Validate time windows
21
+ # Validate time windows days
23
22
  # Validates: days
24
23
  #
25
24
  # @param definition [Hash] sensu definition.
26
25
  # @param scope [String] definition scope to validate.
26
+ # @param attribute [String] definition attribute to validate.
27
27
  # @param days [String] time window days to validate.
28
- def validate_time_windows_days(definition, scope, days)
28
+ def validate_time_windows_days(definition, scope, attribute, days)
29
29
  valid_days = [:all, :sunday, :monday, :tuesday, :wednesday, :thursday, :friday, :saturday]
30
30
  if must_be_either(valid_days, days.keys)
31
31
  days.each do |day, conditions|
32
32
  if is_an_array?(conditions)
33
- conditions.each do |condition|
34
- validate_time_window_condition(definition, scope, condition)
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")
35
39
  end
36
40
  else
37
- invalid(definition, "#{scope} #{day} time windows must be in an array")
41
+ invalid(definition, "#{scope} #{attribute} days #{day} must be in an array")
38
42
  end
39
43
  end
40
44
  else
41
- invalid(definition, "#{scope} days must be valid days of the week or 'all'")
45
+ invalid(definition, "#{scope} #{attribute} days must be valid days of the week or 'all'")
42
46
  end
43
47
  end
44
48
 
@@ -47,16 +51,21 @@ module Sensu
47
51
  #
48
52
  # @param definition [Hash] sensu definition.
49
53
  # @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")
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]
55
58
  if is_a_hash?(days)
56
- validate_time_windows_days(definition, scope, 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")
57
66
  end
58
67
  else
59
- invalid(definition, "#{scope} must be a hash")
68
+ invalid(definition, "#{scope} #{attribute} must be a hash")
60
69
  end
61
70
  end
62
71
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = "sensu-settings"
5
- spec.version = "9.0.0"
5
+ spec.version = "9.1.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"
@@ -278,7 +278,7 @@ describe "Sensu::Settings::Validator" do
278
278
  :days => {}
279
279
  }
280
280
  @validator.validate_check(check)
281
- expect(@validator.reset).to eq(0)
281
+ expect(@validator.reset).to eq(1)
282
282
  check[:subdue] = {
283
283
  :days => {
284
284
  :nope => {}
@@ -306,7 +306,7 @@ describe "Sensu::Settings::Validator" do
306
306
  }
307
307
  }
308
308
  @validator.validate_check(check)
309
- expect(@validator.reset).to eq(0)
309
+ expect(@validator.reset).to eq(1)
310
310
  check[:subdue] = {
311
311
  :days => {
312
312
  :all => [true]
@@ -314,6 +314,17 @@ describe "Sensu::Settings::Validator" do
314
314
  }
315
315
  @validator.validate_check(check)
316
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)
317
328
  check[:subdue] = {
318
329
  :days => {
319
330
  :all => [
@@ -392,7 +403,7 @@ describe "Sensu::Settings::Validator" do
392
403
  :days => {}
393
404
  }
394
405
  @validator.validate_filter(filter)
395
- expect(@validator.reset).to eq(0)
406
+ expect(@validator.reset).to eq(1)
396
407
  filter[:when] = {
397
408
  :days => {
398
409
  :nope => {}
@@ -420,7 +431,7 @@ describe "Sensu::Settings::Validator" do
420
431
  }
421
432
  }
422
433
  @validator.validate_filter(filter)
423
- expect(@validator.reset).to eq(0)
434
+ expect(@validator.reset).to eq(1)
424
435
  filter[:when] = {
425
436
  :days => {
426
437
  :all => [true]
@@ -428,6 +439,17 @@ describe "Sensu::Settings::Validator" do
428
439
  }
429
440
  @validator.validate_filter(filter)
430
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)
431
453
  filter[:when] = {
432
454
  :days => {
433
455
  :all => [
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: 9.0.0
4
+ version: 9.1.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-18 00:00:00.000000000 Z
11
+ date: 2016-08-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sensu-json