sensu-settings 4.1.1 → 5.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/sensu/settings/loader.rb +5 -0
- data/lib/sensu/settings/validator.rb +2 -1
- data/lib/sensu/settings/validators.rb +4 -2
- data/lib/sensu/settings/validators/sensu.rb +37 -0
- data/sensu-settings.gemspec +1 -1
- data/spec/validator_spec.rb +48 -9
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 945f0d180df7cf835f3fd0e94a998c7112a9f9f8
|
4
|
+
data.tar.gz: 51f3037a8a53f66dc1e1f91a2d25cabd15aacd15
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7b4bf57d1d696f63120641a88f26691491648fccab35dffe7f88cc558e7dd61ff97c6ebdcb2586ae25944e4fbe23f3eb8c6c40c5e0b112214e0d089c2d21b9ff
|
7
|
+
data.tar.gz: 742dc56ea7fcd14fc57a6389bd2f9f09aa88af495aa4f38084d0244bc9be7498aaf6728a7f300cd593bcbbe11a46f409fa32714a77f2c7049b9a27363cb635eb
|
@@ -22,8 +22,9 @@ module Sensu
|
|
22
22
|
# @param service [String] sensu service to validate for.
|
23
23
|
# @return [Array] validation failures.
|
24
24
|
def run(settings, service=nil)
|
25
|
-
|
25
|
+
validate_sensu(settings[:sensu])
|
26
26
|
validate_transport(settings[:transport])
|
27
|
+
validate_categories(settings)
|
27
28
|
case service
|
28
29
|
when "client"
|
29
30
|
validate_client(settings[:client])
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require "sensu/settings/validators/sensu"
|
2
|
+
require "sensu/settings/validators/transport"
|
1
3
|
require "sensu/settings/validators/subdue"
|
2
4
|
require "sensu/settings/validators/check"
|
3
5
|
require "sensu/settings/validators/filter"
|
@@ -5,11 +7,12 @@ require "sensu/settings/validators/mutator"
|
|
5
7
|
require "sensu/settings/validators/handler"
|
6
8
|
require "sensu/settings/validators/client"
|
7
9
|
require "sensu/settings/validators/api"
|
8
|
-
require "sensu/settings/validators/transport"
|
9
10
|
|
10
11
|
module Sensu
|
11
12
|
module Settings
|
12
13
|
module Validators
|
14
|
+
include Sensu
|
15
|
+
include Transport
|
13
16
|
include Subdue
|
14
17
|
include Check
|
15
18
|
include Filter
|
@@ -17,7 +20,6 @@ module Sensu
|
|
17
20
|
include Handler
|
18
21
|
include Client
|
19
22
|
include API
|
20
|
-
include Transport
|
21
23
|
end
|
22
24
|
end
|
23
25
|
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module Sensu
|
2
|
+
module Settings
|
3
|
+
module Validators
|
4
|
+
module Sensu
|
5
|
+
# Validate Sensu spawn.
|
6
|
+
# Validates: limit
|
7
|
+
#
|
8
|
+
# @param sensu [Hash] sensu definition.
|
9
|
+
def validate_sensu_spawn(sensu)
|
10
|
+
spawn = sensu[:spawn]
|
11
|
+
if is_a_hash?(spawn)
|
12
|
+
if is_an_integer?(spawn[:limit])
|
13
|
+
spawn[:limit] > 0 ||
|
14
|
+
invalid(sensu, "sensu spawn limit must be greater than 0")
|
15
|
+
else
|
16
|
+
invalid(sensu, "sensu spawn limit must be an integer")
|
17
|
+
end
|
18
|
+
else
|
19
|
+
invalid(sensu, "sensu spawn must be a hash")
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
# Validate a Sensu definition.
|
24
|
+
# Validates: spawn
|
25
|
+
#
|
26
|
+
# @param sensu [Hash] sensu definition.
|
27
|
+
def validate_sensu(sensu)
|
28
|
+
if is_a_hash?(sensu)
|
29
|
+
validate_sensu_spawn(sensu)
|
30
|
+
else
|
31
|
+
invalid(sensu, "sensu must be a hash")
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
data/sensu-settings.gemspec
CHANGED
data/spec/validator_spec.rb
CHANGED
@@ -21,7 +21,46 @@ describe "Sensu::Settings::Validator" do
|
|
21
21
|
expect(reasons).to include("filters must be a hash")
|
22
22
|
expect(reasons).to include("mutators must be a hash")
|
23
23
|
expect(reasons).to include("handlers must be a hash")
|
24
|
-
expect(reasons.size).to eq(
|
24
|
+
expect(reasons.size).to eq(6)
|
25
|
+
end
|
26
|
+
|
27
|
+
it "can validate a sensu definition" do
|
28
|
+
sensu = nil
|
29
|
+
@validator.validate_sensu(sensu)
|
30
|
+
expect(@validator.reset).to eq(1)
|
31
|
+
sensu = 1
|
32
|
+
@validator.validate_sensu(sensu)
|
33
|
+
expect(@validator.reset).to eq(1)
|
34
|
+
sensu = {}
|
35
|
+
@validator.validate_sensu(sensu)
|
36
|
+
expect(@validator.reset).to eq(1)
|
37
|
+
sensu[:spawn] = 1
|
38
|
+
@validator.validate_sensu(sensu)
|
39
|
+
expect(@validator.reset).to eq(1)
|
40
|
+
sensu[:spawn] = {}
|
41
|
+
@validator.validate_sensu(sensu)
|
42
|
+
expect(@validator.reset).to eq(1)
|
43
|
+
sensu[:spawn][:limit] = "1"
|
44
|
+
@validator.validate_sensu(sensu)
|
45
|
+
expect(@validator.reset).to eq(1)
|
46
|
+
sensu[:spawn][:limit] = 20
|
47
|
+
@validator.validate_sensu(sensu)
|
48
|
+
expect(@validator.reset).to eq(0)
|
49
|
+
end
|
50
|
+
|
51
|
+
it "can run, validating sensu" do
|
52
|
+
settings = {
|
53
|
+
:sensu => {
|
54
|
+
:spawn => {
|
55
|
+
:limit => "20"
|
56
|
+
}
|
57
|
+
}
|
58
|
+
}
|
59
|
+
@validator.run(settings)
|
60
|
+
expect(@validator.reset).to eq(6)
|
61
|
+
settings[:sensu][:spawn][:limit] = 20
|
62
|
+
@validator.run(settings)
|
63
|
+
expect(@validator.reset).to eq(5)
|
25
64
|
end
|
26
65
|
|
27
66
|
it "can validate a transport definition" do
|
@@ -52,10 +91,10 @@ describe "Sensu::Settings::Validator" do
|
|
52
91
|
}
|
53
92
|
}
|
54
93
|
@validator.run(settings)
|
55
|
-
expect(@validator.reset).to eq(
|
94
|
+
expect(@validator.reset).to eq(6)
|
56
95
|
settings[:transport][:name] = "rabbitmq"
|
57
96
|
@validator.run(settings)
|
58
|
-
expect(@validator.reset).to eq(
|
97
|
+
expect(@validator.reset).to eq(5)
|
59
98
|
end
|
60
99
|
|
61
100
|
it "can validate an empty check definition" do
|
@@ -258,10 +297,10 @@ describe "Sensu::Settings::Validator" do
|
|
258
297
|
}
|
259
298
|
}
|
260
299
|
@validator.run(settings)
|
261
|
-
expect(@validator.reset).to eq(
|
300
|
+
expect(@validator.reset).to eq(6)
|
262
301
|
settings[:checks][:foo][:interval] = 1
|
263
302
|
@validator.run(settings)
|
264
|
-
expect(@validator.reset).to eq(
|
303
|
+
expect(@validator.reset).to eq(5)
|
265
304
|
end
|
266
305
|
|
267
306
|
it "can validate a filter definition" do
|
@@ -671,10 +710,10 @@ describe "Sensu::Settings::Validator" do
|
|
671
710
|
}
|
672
711
|
}
|
673
712
|
@validator.run(settings, "client")
|
674
|
-
expect(@validator.reset).to eq(
|
713
|
+
expect(@validator.reset).to eq(7)
|
675
714
|
settings[:client][:subscriptions] = ["bar"]
|
676
715
|
@validator.run(settings, "client")
|
677
|
-
expect(@validator.reset).to eq(
|
716
|
+
expect(@validator.reset).to eq(6)
|
678
717
|
end
|
679
718
|
|
680
719
|
it "can validate an api definition" do
|
@@ -720,9 +759,9 @@ describe "Sensu::Settings::Validator" do
|
|
720
759
|
}
|
721
760
|
}
|
722
761
|
@validator.run(settings, "api")
|
723
|
-
expect(@validator.reset).to eq(
|
762
|
+
expect(@validator.reset).to eq(7)
|
724
763
|
settings[:api][:port] = 4567
|
725
764
|
@validator.run(settings, "api")
|
726
|
-
expect(@validator.reset).to eq(
|
765
|
+
expect(@validator.reset).to eq(6)
|
727
766
|
end
|
728
767
|
end
|
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:
|
4
|
+
version: 5.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-05-
|
11
|
+
date: 2016-05-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sensu-json
|
@@ -105,6 +105,7 @@ files:
|
|
105
105
|
- lib/sensu/settings/validators/filter.rb
|
106
106
|
- lib/sensu/settings/validators/handler.rb
|
107
107
|
- lib/sensu/settings/validators/mutator.rb
|
108
|
+
- lib/sensu/settings/validators/sensu.rb
|
108
109
|
- lib/sensu/settings/validators/subdue.rb
|
109
110
|
- lib/sensu/settings/validators/transport.rb
|
110
111
|
- sensu-settings.gemspec
|