nagios_check 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/nagios_check/range.rb +3 -6
- data/lib/nagios_check/version.rb +1 -1
- data/spec/range_spec.rb +109 -83
- data/spec/spec_helper.rb +4 -4
- metadata +3 -3
data/lib/nagios_check/range.rb
CHANGED
@@ -9,7 +9,7 @@ module NagiosCheck
|
|
9
9
|
unless tokens
|
10
10
|
raise RuntimeError, "Pattern should be of form [@][~][min]:max"
|
11
11
|
end
|
12
|
-
@
|
12
|
+
@inverse = true if tokens.include? "@"
|
13
13
|
case tokens[2]
|
14
14
|
when nil, "" then @min = 0
|
15
15
|
when '~' then @min = nil
|
@@ -19,11 +19,8 @@ module NagiosCheck
|
|
19
19
|
end
|
20
20
|
|
21
21
|
def include?(value)
|
22
|
-
|
23
|
-
|
24
|
-
else
|
25
|
-
(@min.nil? || value >= @min) && (@max.nil? || value <= @max)
|
26
|
-
end
|
22
|
+
result = (@min.nil? || value >= @min) && (@max.nil? || value <= @max)
|
23
|
+
@inverse ? not(result) : result
|
27
24
|
end
|
28
25
|
|
29
26
|
def ===(value)
|
data/lib/nagios_check/version.rb
CHANGED
data/spec/range_spec.rb
CHANGED
@@ -12,119 +12,145 @@ describe NagiosCheck::Range do
|
|
12
12
|
end
|
13
13
|
|
14
14
|
context "when pattern is 10" do
|
15
|
-
it {
|
16
|
-
it {
|
17
|
-
it {
|
18
|
-
it {
|
19
|
-
it {
|
20
|
-
it {
|
21
|
-
it {
|
22
|
-
it {
|
23
|
-
it {
|
15
|
+
it { should alert_if -1 }
|
16
|
+
it { should_not alert_if 0 }
|
17
|
+
it { should_not alert_if 0.1 }
|
18
|
+
it { should_not alert_if 1 }
|
19
|
+
it { should_not alert_if 9 }
|
20
|
+
it { should_not alert_if 9.9 }
|
21
|
+
it { should_not alert_if 10 }
|
22
|
+
it { should_not alert_if 10.0 }
|
23
|
+
it { should alert_if 10.1 }
|
24
24
|
end
|
25
25
|
|
26
26
|
context "when pattern is :10" do
|
27
|
-
it {
|
28
|
-
it {
|
29
|
-
it {
|
30
|
-
it {
|
31
|
-
it {
|
32
|
-
it {
|
33
|
-
it {
|
34
|
-
it {
|
35
|
-
it {
|
27
|
+
it { should alert_if -1 }
|
28
|
+
it { should_not alert_if 0 }
|
29
|
+
it { should_not alert_if 0.1 }
|
30
|
+
it { should_not alert_if 1 }
|
31
|
+
it { should_not alert_if 9 }
|
32
|
+
it { should_not alert_if 9.9 }
|
33
|
+
it { should_not alert_if 10 }
|
34
|
+
it { should_not alert_if 10.0 }
|
35
|
+
it { should alert_if 10.1 }
|
36
36
|
end
|
37
37
|
|
38
38
|
context "when pattern is @:10" do
|
39
|
-
it { should_not
|
40
|
-
it {
|
41
|
-
it { should
|
42
|
-
it {
|
43
|
-
it {
|
44
|
-
it { should_not
|
39
|
+
it { should_not alert_if -1 }
|
40
|
+
it { should alert_if 0 }
|
41
|
+
it { should alert_if 5 }
|
42
|
+
it { should alert_if 10 }
|
43
|
+
it { should alert_if 10.0 }
|
44
|
+
it { should_not alert_if 11 }
|
45
45
|
end
|
46
46
|
|
47
47
|
context "when pattern is 10:" do
|
48
|
-
it {
|
49
|
-
it {
|
50
|
-
it {
|
51
|
-
it {
|
52
|
-
it {
|
53
|
-
it {
|
54
|
-
it {
|
48
|
+
it { should alert_if -1 }
|
49
|
+
it { should alert_if 1 }
|
50
|
+
it { should alert_if 9.9 }
|
51
|
+
it { should_not alert_if 10 }
|
52
|
+
it { should_not alert_if 10.0 }
|
53
|
+
it { should_not alert_if 10.1 }
|
54
|
+
it { should_not alert_if 11 }
|
55
55
|
end
|
56
56
|
|
57
57
|
context "when pattern is @10:" do
|
58
|
-
it { should_not
|
59
|
-
it { should_not
|
60
|
-
it { should_not
|
61
|
-
it {
|
62
|
-
it {
|
63
|
-
it { should
|
64
|
-
it { should
|
58
|
+
it { should_not alert_if -1 }
|
59
|
+
it { should_not alert_if 1 }
|
60
|
+
it { should_not alert_if 9.9 }
|
61
|
+
it { should alert_if 10 }
|
62
|
+
it { should alert_if 10.0 }
|
63
|
+
it { should alert_if 10.1 }
|
64
|
+
it { should alert_if 11 }
|
65
65
|
end
|
66
66
|
|
67
67
|
context "when pattern is 10:11" do
|
68
|
-
it {
|
69
|
-
it {
|
70
|
-
it {
|
71
|
-
it {
|
72
|
-
it {
|
73
|
-
it {
|
74
|
-
it {
|
75
|
-
it {
|
76
|
-
it {
|
77
|
-
it {
|
68
|
+
it { should alert_if -1 }
|
69
|
+
it { should alert_if 1 }
|
70
|
+
it { should alert_if 9.9 }
|
71
|
+
it { should_not alert_if 10 }
|
72
|
+
it { should_not alert_if 10.0 }
|
73
|
+
it { should_not alert_if 10.1 }
|
74
|
+
it { should_not alert_if 10.9 }
|
75
|
+
it { should_not alert_if 11 }
|
76
|
+
it { should alert_if 11.1 }
|
77
|
+
it { should alert_if 12 }
|
78
78
|
end
|
79
79
|
|
80
|
+
context "when pattern is 10:10" do
|
81
|
+
it { should alert_if -1 }
|
82
|
+
it { should alert_if 1 }
|
83
|
+
it { should alert_if 9.9 }
|
84
|
+
it { should_not alert_if 10 }
|
85
|
+
it { should_not alert_if 10.0 }
|
86
|
+
it { should alert_if 10.1 }
|
87
|
+
it { should alert_if 10.9 }
|
88
|
+
it { should alert_if 11 }
|
89
|
+
it { should alert_if 11.1 }
|
90
|
+
it { should alert_if 12 }
|
91
|
+
end
|
92
|
+
|
93
|
+
context "when pattern is @10:10" do
|
94
|
+
it { should_not alert_if -1 }
|
95
|
+
it { should_not alert_if 1 }
|
96
|
+
it { should_not alert_if 9.9 }
|
97
|
+
it { should alert_if 10 }
|
98
|
+
it { should alert_if 10.0 }
|
99
|
+
it { should_not alert_if 10.1 }
|
100
|
+
it { should_not alert_if 10.9 }
|
101
|
+
it { should_not alert_if 11 }
|
102
|
+
it { should_not alert_if 11.1 }
|
103
|
+
it { should_not alert_if 12 }
|
104
|
+
end
|
105
|
+
|
80
106
|
context "when pattern is @10:11" do
|
81
|
-
it { should_not
|
82
|
-
it { should_not
|
83
|
-
it { should_not
|
84
|
-
it {
|
85
|
-
it {
|
86
|
-
it { should
|
87
|
-
it {
|
88
|
-
it { should_not
|
89
|
-
it { should_not
|
107
|
+
it { should_not alert_if -1 }
|
108
|
+
it { should_not alert_if 1 }
|
109
|
+
it { should_not alert_if 9.9 }
|
110
|
+
it { should alert_if 10 }
|
111
|
+
it { should alert_if 10.0 }
|
112
|
+
it { should alert_if 10.1 }
|
113
|
+
it { should alert_if 11 }
|
114
|
+
it { should_not alert_if 11.1 }
|
115
|
+
it { should_not alert_if 12 }
|
90
116
|
end
|
91
117
|
|
92
118
|
context "when pattern is @10.05:11.05" do
|
93
|
-
it { should_not
|
94
|
-
it { should_not
|
95
|
-
it { should_not
|
96
|
-
it { should_not
|
97
|
-
it { should_not
|
98
|
-
it { should
|
99
|
-
it { should
|
100
|
-
it { should_not
|
101
|
-
it { should_not
|
119
|
+
it { should_not alert_if -1 }
|
120
|
+
it { should_not alert_if 1 }
|
121
|
+
it { should_not alert_if 9.9 }
|
122
|
+
it { should_not alert_if 10 }
|
123
|
+
it { should_not alert_if 10.0 }
|
124
|
+
it { should alert_if 10.1 }
|
125
|
+
it { should alert_if 11 }
|
126
|
+
it { should_not alert_if 11.1 }
|
127
|
+
it { should_not alert_if 12 }
|
102
128
|
end
|
103
129
|
|
104
130
|
context "when pattern is -1:1" do
|
105
|
-
it {
|
106
|
-
it {
|
107
|
-
it {
|
108
|
-
it {
|
109
|
-
it {
|
110
|
-
it {
|
111
|
-
it {
|
131
|
+
it { should alert_if -2 }
|
132
|
+
it { should_not alert_if -1 }
|
133
|
+
it { should_not alert_if -0.9 }
|
134
|
+
it { should_not alert_if 0 }
|
135
|
+
it { should_not alert_if 0.9 }
|
136
|
+
it { should_not alert_if 1 }
|
137
|
+
it { should alert_if 2 }
|
112
138
|
end
|
113
139
|
|
114
140
|
context "when pattern is ~:1" do
|
115
|
-
it {
|
116
|
-
it {
|
117
|
-
it {
|
118
|
-
it {
|
119
|
-
it {
|
141
|
+
it { should_not alert_if -2 }
|
142
|
+
it { should_not alert_if -1 }
|
143
|
+
it { should_not alert_if 0 }
|
144
|
+
it { should_not alert_if 1 }
|
145
|
+
it { should alert_if 2 }
|
120
146
|
end
|
121
147
|
|
122
148
|
context "when pattern is @~:1" do
|
123
|
-
it { should
|
124
|
-
it { should
|
125
|
-
it { should
|
126
|
-
it {
|
127
|
-
it { should_not
|
149
|
+
it { should alert_if -2 }
|
150
|
+
it { should alert_if -1 }
|
151
|
+
it { should alert_if 0 }
|
152
|
+
it { should alert_if 1 }
|
153
|
+
it { should_not alert_if 2 }
|
128
154
|
end
|
129
155
|
|
130
156
|
context "when nil pattern" do
|
data/spec/spec_helper.rb
CHANGED
@@ -8,19 +8,19 @@ module Matchers
|
|
8
8
|
|
9
9
|
def matches?(actual)
|
10
10
|
@actual = actual
|
11
|
-
|
11
|
+
!@actual.include?(@expected)
|
12
12
|
end
|
13
13
|
|
14
14
|
def failure_message
|
15
|
-
"expected #{@actual} to
|
15
|
+
"expected #{@actual} to alert for value #{@expected}"
|
16
16
|
end
|
17
17
|
|
18
18
|
def negative_failure_message
|
19
|
-
"expected #{@actual} not to
|
19
|
+
"expected #{@actual} not to alert for value #{@expected}"
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
|
-
def
|
23
|
+
def alert_if(value)
|
24
24
|
Contain::new(value)
|
25
25
|
end
|
26
26
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nagios_check
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2013-01-26 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
@@ -85,7 +85,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
85
85
|
version: '0'
|
86
86
|
requirements: []
|
87
87
|
rubyforge_project: nagios_check
|
88
|
-
rubygems_version: 1.8.
|
88
|
+
rubygems_version: 1.8.23
|
89
89
|
signing_key:
|
90
90
|
specification_version: 3
|
91
91
|
summary: Ruby Nagios Check Integration
|