sensu-settings 1.8.0 → 1.9.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: 1a4f1a3ec54f01cdcbc1695ae3ea50bd3f729e45
4
- data.tar.gz: 38ab52e28a371d5466c4275e24b9027dd9b35eb3
3
+ metadata.gz: c40db4538a2eb9d126977fc84d1c1a7276517986
4
+ data.tar.gz: 5f13e4dac37f2b7abda31f79c6580244c50ff6ab
5
5
  SHA512:
6
- metadata.gz: ccf5e6b166eb86f7e505c49838fd537468ead0a1573d0725490fa93e84aa265b4d124a167b057148dbed4e0ef027abe47f24e146b14b7c153d1d29b40e249d09
7
- data.tar.gz: 9c8bcdbc0271df0ba12684bc7323c082030398eef0e6a2cb15297cb8b2f22dcda87b879edd29862575d29e6c9729bf7fe3c21d5d55955bd233ce9cb8e3e174ed
6
+ metadata.gz: 694e9e8e2590d42fc060e938226aa9c2460c79fdec5dedec4d83946a1b19370b6bb22a2da5697bd583070573a1e0d1813d76167ca6b7300966e32569838aed79
7
+ data.tar.gz: 456f4622d3e33dc8bdb00f7703655541edda5939d3f5cb1fd69c089232f124d7fd1c350e592722c6a26b0037f88cfa59211984315bd94580a4be4974ceb12d1b
@@ -59,6 +59,7 @@ module Sensu
59
59
  def must_be_an_integer(value)
60
60
  value.is_a?(Integer)
61
61
  end
62
+ alias_method :is_an_integer?, :must_be_an_integer
62
63
 
63
64
  # Check that a value is an integer, if set (not nil).
64
65
  #
@@ -2,6 +2,32 @@ module Sensu
2
2
  module Settings
3
3
  module Validators
4
4
  module Check
5
+ # Validate check name.
6
+ # Validates: name
7
+ #
8
+ # @param check [Hash] sensu check definition.
9
+ def validate_check_name(check)
10
+ must_be_a_string(check[:name]) ||
11
+ invalid(check, "check name must be a string")
12
+ must_match_regex(/^[\w\.-]+$/, check[:name]) ||
13
+ invalid(check, "check name cannot contain spaces or special characters")
14
+ end
15
+
16
+ # Validate check execution.
17
+ # Validates: command, extension, timeout
18
+ #
19
+ # @param check [Hash] sensu check definition.
20
+ def validate_check_execution(check)
21
+ must_be_a_string_if_set(check[:command]) ||
22
+ invalid(check, "check command must be a string")
23
+ must_be_a_string_if_set(check[:extension]) ||
24
+ invalid(check, "check extension must be a string")
25
+ (!check[:command].nil? ^ !check[:extension].nil?) ||
26
+ invalid(check, "either check command or extension must be set")
27
+ must_be_a_numeric_if_set(check[:timeout]) ||
28
+ invalid(check, "check timeout must be numeric")
29
+ end
30
+
5
31
  # Validate check source.
6
32
  # Validates: source
7
33
  #
@@ -53,6 +79,19 @@ module Sensu
53
79
  end
54
80
  end
55
81
 
82
+ # Validate check ttl.
83
+ # Validates: ttl
84
+ #
85
+ # @param check [Hash] sensu check definition.
86
+ def validate_check_ttl(check)
87
+ if is_an_integer?(check[:ttl])
88
+ check[:ttl] > 0 ||
89
+ invalid(check, "check ttl must be greater than 0")
90
+ else
91
+ invalid(check, "check ttl must be an integer")
92
+ end
93
+ end
94
+
56
95
  # Validate check flap detection.
57
96
  # Validates: low_flap_threshold, high_flap_threshold
58
97
  #
@@ -70,21 +109,12 @@ module Sensu
70
109
  #
71
110
  # @param check [Hash] sensu check definition.
72
111
  def validate_check(check)
73
- must_be_a_string(check[:name]) ||
74
- invalid(check, "check name must be a string")
75
- must_match_regex(/^[\w\.-]+$/, check[:name]) ||
76
- invalid(check, "check name cannot contain spaces or special characters")
77
- must_be_a_string_if_set(check[:command]) ||
78
- invalid(check, "check command must be a string")
79
- must_be_a_string_if_set(check[:extension]) ||
80
- invalid(check, "check extension must be a string")
81
- (!check[:command].nil? ^ !check[:extension].nil?) ||
82
- invalid(check, "either check command or extension must be set")
83
- must_be_a_numeric_if_set(check[:timeout]) ||
84
- invalid(check, "check timeout must be numeric")
112
+ validate_check_name(check)
113
+ validate_check_execution(check)
85
114
  validate_check_source(check) if check[:source]
86
115
  validate_check_scheduling(check)
87
116
  validate_check_handling(check)
117
+ validate_check_ttl(check) if check[:ttl]
88
118
  validate_check_flap_detection(check)
89
119
  validate_subdue(check) if check[:subdue]
90
120
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = "sensu-settings"
5
- spec.version = "1.8.0"
5
+ spec.version = "1.9.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"
@@ -134,6 +134,18 @@ describe "Sensu::Settings::Validator" do
134
134
  check[:handlers] = ["cat"]
135
135
  @validator.validate_check(check)
136
136
  expect(@validator.reset).to eq(0)
137
+ check[:ttl] = true
138
+ @validator.validate_check(check)
139
+ expect(@validator.reset).to eq(1)
140
+ check[:ttl] = -1
141
+ @validator.validate_check(check)
142
+ expect(@validator.reset).to eq(1)
143
+ check[:ttl] = 0
144
+ @validator.validate_check(check)
145
+ expect(@validator.reset).to eq(1)
146
+ check[:ttl] = 1
147
+ @validator.validate_check(check)
148
+ expect(@validator.reset).to eq(0)
137
149
  check[:low_flap_threshold] = "25"
138
150
  @validator.validate_check(check)
139
151
  expect(@validator.reset).to eq(2)
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: 1.8.0
4
+ version: 1.9.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: 2015-05-06 00:00:00.000000000 Z
11
+ date: 2015-05-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: multi_json