sensu-settings 1.8.0 → 1.9.0
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 +4 -4
- data/lib/sensu/settings/rules.rb +1 -0
- data/lib/sensu/settings/validators/check.rb +42 -12
- data/sensu-settings.gemspec +1 -1
- data/spec/validator_spec.rb +12 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c40db4538a2eb9d126977fc84d1c1a7276517986
|
4
|
+
data.tar.gz: 5f13e4dac37f2b7abda31f79c6580244c50ff6ab
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 694e9e8e2590d42fc060e938226aa9c2460c79fdec5dedec4d83946a1b19370b6bb22a2da5697bd583070573a1e0d1813d76167ca6b7300966e32569838aed79
|
7
|
+
data.tar.gz: 456f4622d3e33dc8bdb00f7703655541edda5939d3f5cb1fd69c089232f124d7fd1c350e592722c6a26b0037f88cfa59211984315bd94580a4be4974ceb12d1b
|
data/lib/sensu/settings/rules.rb
CHANGED
@@ -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
|
-
|
74
|
-
|
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
|
data/sensu-settings.gemspec
CHANGED
data/spec/validator_spec.rb
CHANGED
@@ -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.
|
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-
|
11
|
+
date: 2015-05-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: multi_json
|