nagios_check 0.4.0 → 0.4.1
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 +5 -5
- data/.travis.yml +17 -0
- data/README.md +44 -3
- data/Rakefile +2 -0
- data/lib/nagios_check/version.rb +1 -1
- data/lib/nagios_check.rb +30 -3
- data/nagios_check.gemspec +2 -2
- data/spec/finish_spec.rb +31 -34
- data/spec/options_spec.rb +47 -47
- data/spec/range_spec.rb +119 -119
- data/spec/spec_helper.rb +8 -23
- metadata +11 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 9fc94a2d97088c48f83d820d58bae3cd3b98531feb9007fd9ba44a5f9853dfd4
|
4
|
+
data.tar.gz: dd9022e057eb61941652f6e4a3f15fc179e6f4de15b310d090121b8ea2277028
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f7b5358d1903d83548fca5e8a951a06e2af1cec7f2ef58670eb32be2678f82402ae5823b43c3826cecb39de235a77d1b9caf52e26359e87bf98fbd71c485c843
|
7
|
+
data.tar.gz: 0f7d461c349997293955d4679b805511f3b619648b61c4cb52e24dbf67c30c63b94e0983d45a68ae8bca073ab0e27f16c724ec75ae43b1a0d62056609891ec13
|
data/.travis.yml
ADDED
data/README.md
CHANGED
@@ -1,6 +1,9 @@
|
|
1
1
|
NagiosCheck
|
2
2
|
============
|
3
3
|
|
4
|
+
[](https://badge.fury.io/rb/nagios_check)
|
5
|
+
[](https://travis-ci.org/dbroeglin/nagios_check)
|
6
|
+
|
4
7
|
Description
|
5
8
|
-----------
|
6
9
|
|
@@ -47,7 +50,9 @@ class SimpleCheck
|
|
47
50
|
|
48
51
|
def check
|
49
52
|
time = do_some_check(options.host, options.port)
|
53
|
+
|
50
54
|
store_value :duration, time
|
55
|
+
store_message "The check took #{time} seconds"
|
51
56
|
end
|
52
57
|
end
|
53
58
|
|
@@ -60,20 +65,56 @@ The command can then be used by Nagios:
|
|
60
65
|
ruby simple_check.rb -H my_host -P my_port -w 4 -c 8 -t 10
|
61
66
|
```
|
62
67
|
|
63
|
-
If the
|
68
|
+
If the number passed to `store_value` is between 0 and 4 inclusive the result is OK. If it is greater than 4 and less than 8 inclusive the result is WARNING. If it is greater than 8 the result is CRITICAL. See [Nagios Developer Guidelines][nagios-dev] for more details on how the arguments of `-w` and `-c` are interpreted.
|
69
|
+
|
70
|
+
If `store_value` is called multiple times, the value from the first call is used to determine the result. Multiple `store_value` calls can be used to include additional performance data in the output.
|
64
71
|
|
65
72
|
If the check method lasts more than 10 seconds, it times out and the returned value is UNKNOWN.
|
66
73
|
|
67
|
-
|
74
|
+
Calling `store_message` is optional. However, the text passed to `store_message` will be displayed next to the check status in the Nagios web interface and can be included in notification mails to provide some context in a human readable format.
|
75
|
+
|
76
|
+
If the only metric we are interested is the time it takes to execute the check, an alternative shorter way of writting the above would be:
|
68
77
|
|
69
78
|
```ruby
|
70
79
|
def check
|
71
|
-
time(value_name: 'duration' do
|
80
|
+
time(value_name: 'duration') do
|
72
81
|
do_some_check(options.host, options.port)
|
73
82
|
end
|
74
83
|
end
|
75
84
|
```
|
76
85
|
|
86
|
+
This check will execute `do_some_check` measure the time it takes to execute it and return both status and performance data labeled `duration`.
|
87
|
+
|
88
|
+
Writing Tests for Checks
|
89
|
+
------------------------
|
90
|
+
|
91
|
+
Checks can be integration tested by calling the `perform` method
|
92
|
+
instead of the `run` method. `perform` takes an array of command line
|
93
|
+
arguments and returns a `NagiosCheck::Result` object, which supports
|
94
|
+
`ok?`, `warning?` and `critical?` methods to query the status and
|
95
|
+
exposes the stored values:
|
96
|
+
|
97
|
+
```ruby
|
98
|
+
RSpec.describe SomeCheck do
|
99
|
+
it 'is ok by default' do
|
100
|
+
result = SomeCheck.new.perform(%w(-w 5 -c 10))
|
101
|
+
|
102
|
+
expect(result).to be_ok
|
103
|
+
end
|
104
|
+
|
105
|
+
it 'results in warning if there are more thn 5 uploads purchases' do
|
106
|
+
# Setup environment such that the check detects problems
|
107
|
+
# ...
|
108
|
+
|
109
|
+
result = SomeCheck.new.perform(%w(-w 5 -c 10))
|
110
|
+
|
111
|
+
expect(result).to be_warning
|
112
|
+
expect(result.values[:some_stored_value]).to eq(6)
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
```
|
117
|
+
|
77
118
|
License
|
78
119
|
-------
|
79
120
|
Released under the MIT License. See the [MIT-LICENSE][license] file for further details.
|
data/Rakefile
CHANGED
data/lib/nagios_check/version.rb
CHANGED
data/lib/nagios_check.rb
CHANGED
@@ -12,6 +12,27 @@ module NagiosCheck
|
|
12
12
|
attr_reader :options
|
13
13
|
attr_accessor :message
|
14
14
|
|
15
|
+
class Result
|
16
|
+
attr_reader :exit_status, :output, :values
|
17
|
+
|
18
|
+
def initialize(exit_status, output, values)
|
19
|
+
@exit_status = exit_status
|
20
|
+
@output = output
|
21
|
+
@values = values
|
22
|
+
end
|
23
|
+
|
24
|
+
def critical?
|
25
|
+
exit_status == 2
|
26
|
+
end
|
27
|
+
|
28
|
+
def warning?
|
29
|
+
exit_status == 1
|
30
|
+
end
|
31
|
+
|
32
|
+
def ok?
|
33
|
+
exit_status == 0
|
34
|
+
end
|
35
|
+
end
|
15
36
|
|
16
37
|
def prepare
|
17
38
|
@values = {}
|
@@ -19,10 +40,16 @@ module NagiosCheck
|
|
19
40
|
end
|
20
41
|
|
21
42
|
def run
|
43
|
+
result = perform(ARGV)
|
44
|
+
puts result.output
|
45
|
+
exit result.exit_status
|
46
|
+
end
|
47
|
+
|
48
|
+
def perform(argv)
|
22
49
|
prepare
|
23
50
|
return_val, status = 3, "UNKNOWN"
|
24
51
|
begin
|
25
|
-
parse_options
|
52
|
+
parse_options(argv)
|
26
53
|
if @options.t
|
27
54
|
check_with_timeout
|
28
55
|
else
|
@@ -43,8 +70,8 @@ module NagiosCheck
|
|
43
70
|
"#{name}=#{value};;;;"
|
44
71
|
end.join(' ')
|
45
72
|
end
|
46
|
-
|
47
|
-
|
73
|
+
|
74
|
+
Result.new(return_val, msg, @values)
|
48
75
|
end
|
49
76
|
|
50
77
|
def store_message(message)
|
data/nagios_check.gemspec
CHANGED
@@ -18,6 +18,6 @@ Gem::Specification.new do |s|
|
|
18
18
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
19
|
s.require_paths = ["lib"]
|
20
20
|
|
21
|
-
s.add_development_dependency "rspec", "~>
|
22
|
-
s.add_development_dependency "rake"
|
21
|
+
s.add_development_dependency "rspec", "~> 3.13"
|
22
|
+
s.add_development_dependency "rake", ">= 12.3.3"
|
23
23
|
end
|
data/spec/finish_spec.rb
CHANGED
@@ -2,12 +2,12 @@ require 'spec_helper'
|
|
2
2
|
def before_finish_test
|
3
3
|
before(:each) do
|
4
4
|
subject.prepare
|
5
|
-
description =
|
5
|
+
description = RSpec.current_example.example_group.metadata[:parent_example_group][:description_args].first
|
6
6
|
if description.kind_of?(String) && /^when options are '(.*)'$/ =~ description
|
7
7
|
subject.send :parse_options, $1.split
|
8
8
|
end
|
9
9
|
|
10
|
-
description =
|
10
|
+
description = RSpec.current_example.example_group.metadata[:description_args].first
|
11
11
|
if description.kind_of?(String) && /^when value is (.*)$/ =~ description
|
12
12
|
subject.store_value 'val', $1.to_f
|
13
13
|
end
|
@@ -33,26 +33,24 @@ describe OkTestCheck do
|
|
33
33
|
before_finish_test
|
34
34
|
|
35
35
|
context "when options are ''" do
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
}.should raise_error(RuntimeError, "No value was provided")
|
40
|
-
end
|
36
|
+
it "should fail when no value is given" do
|
37
|
+
expect { subject.finish }.to raise_error(RuntimeError, "No value was provided")
|
38
|
+
end
|
41
39
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
40
|
+
context "when value is 0" do
|
41
|
+
specify { expect(subject.finish).to eq([0, "OK"]) }
|
42
|
+
end
|
43
|
+
context "when value is 5" do
|
44
|
+
specify { expect(subject.finish).to eq([0, "OK"]) }
|
45
|
+
end
|
46
|
+
context "when value is 10" do
|
47
|
+
specify { expect(subject.finish).to eq([0, "OK"]) }
|
48
|
+
end
|
51
49
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
50
|
+
context "when nil is given" do
|
51
|
+
before { subject.store_value 'val', nil }
|
52
|
+
specify { expect(subject.finish).to eq([3, "UNKNOWN"]) }
|
53
|
+
end
|
56
54
|
end
|
57
55
|
end
|
58
56
|
|
@@ -61,21 +59,20 @@ describe WarningTestCheck do
|
|
61
59
|
|
62
60
|
context "when options are '-w 10'" do
|
63
61
|
context "when value is -1" do
|
64
|
-
specify { subject.finish.
|
62
|
+
specify { expect(subject.finish).to eq([1, "WARNING"]) }
|
65
63
|
end
|
66
64
|
context "when value is 0" do
|
67
|
-
specify { subject.finish.
|
65
|
+
specify { expect(subject.finish).to eq([0, "OK"]) }
|
68
66
|
end
|
69
67
|
context "when value is 5" do
|
70
|
-
specify { subject.finish.
|
68
|
+
specify { expect(subject.finish).to eq([0, "OK"]) }
|
71
69
|
end
|
72
70
|
context "when value is 10" do
|
73
|
-
specify { subject.finish.
|
71
|
+
specify { expect(subject.finish).to eq([0, "OK"]) }
|
74
72
|
end
|
75
73
|
context "when value is 11" do
|
76
|
-
specify { subject.finish.
|
77
|
-
end
|
78
|
-
end
|
74
|
+
specify { expect(subject.finish).to eq([1, "WARNING"]) }
|
75
|
+
end end
|
79
76
|
end
|
80
77
|
|
81
78
|
describe CriticalTestCheck do
|
@@ -83,25 +80,25 @@ describe CriticalTestCheck do
|
|
83
80
|
|
84
81
|
context "when options are '-w 10 -c 20'" do
|
85
82
|
context "when value is -1" do
|
86
|
-
specify { subject.finish.
|
83
|
+
specify { expect(subject.finish).to eq([2, "CRITICAL"]) }
|
87
84
|
end
|
88
85
|
context "when value is 0" do
|
89
|
-
specify { subject.finish.
|
86
|
+
specify { expect(subject.finish).to eq([0, "OK"]) }
|
90
87
|
end
|
91
88
|
context "when value is 5" do
|
92
|
-
specify { subject.finish.
|
89
|
+
specify { expect(subject.finish).to eq([0, "OK"]) }
|
93
90
|
end
|
94
91
|
context "when value is 10" do
|
95
|
-
specify { subject.finish.
|
92
|
+
specify { expect(subject.finish).to eq([0, "OK"]) }
|
96
93
|
end
|
97
94
|
context "when value is 15" do
|
98
|
-
specify { subject.finish.
|
95
|
+
specify { expect(subject.finish).to eq([1, "WARNING"]) }
|
99
96
|
end
|
100
97
|
context "when value is 20" do
|
101
|
-
specify { subject.finish.
|
98
|
+
specify { expect(subject.finish).to eq([1, "WARNING"]) }
|
102
99
|
end
|
103
100
|
context "when value is 21" do
|
104
|
-
specify { subject.finish.
|
101
|
+
specify { expect(subject.finish).to eq([2, "CRITICAL"]) }
|
105
102
|
end
|
106
103
|
end
|
107
104
|
end
|
data/spec/options_spec.rb
CHANGED
@@ -8,7 +8,7 @@ describe NagiosCheck do
|
|
8
8
|
|
9
9
|
specify { subject.send :parse_options, [] }
|
10
10
|
end
|
11
|
-
|
11
|
+
|
12
12
|
context "when warning is specified" do
|
13
13
|
subject do
|
14
14
|
Class::new do
|
@@ -19,19 +19,19 @@ describe NagiosCheck do
|
|
19
19
|
|
20
20
|
it("works with no arguments"){ subject.send :parse_options, %w{} }
|
21
21
|
specify { subject.send :parse_options, %w{-w 10} }
|
22
|
-
|
22
|
+
|
23
23
|
it "fails if -w has no argument" do
|
24
|
-
|
25
|
-
subject.send :parse_options, %w{-w}
|
26
|
-
}.
|
24
|
+
expect {
|
25
|
+
subject.send :parse_options, %w{-w}
|
26
|
+
}.to raise_error(OptionParser::MissingArgument)
|
27
27
|
end
|
28
28
|
it "fails if -c is given" do
|
29
|
-
|
30
|
-
subject.send :parse_options, %w{-c}
|
31
|
-
}.
|
29
|
+
expect {
|
30
|
+
subject.send :parse_options, %w{-c}
|
31
|
+
}.to raise_error(OptionParser::InvalidOption)
|
32
32
|
end
|
33
33
|
end
|
34
|
-
|
34
|
+
|
35
35
|
context "when critical is specified" do
|
36
36
|
subject do
|
37
37
|
Class::new do
|
@@ -42,20 +42,20 @@ describe NagiosCheck do
|
|
42
42
|
|
43
43
|
it("works with no arguments"){ subject.send :parse_options, %w{} }
|
44
44
|
specify { subject.send :parse_options, %w{-c 10} }
|
45
|
-
|
45
|
+
|
46
46
|
it "fails if -c has no argument" do
|
47
|
-
|
48
|
-
subject.send :parse_options, %w{-c}
|
49
|
-
}.
|
47
|
+
expect {
|
48
|
+
subject.send :parse_options, %w{-c}
|
49
|
+
}.to raise_error(OptionParser::MissingArgument)
|
50
50
|
end
|
51
|
-
|
51
|
+
|
52
52
|
it "fails if -w is given" do
|
53
|
-
|
54
|
-
subject.send :parse_options, %w{-w}
|
55
|
-
}.
|
53
|
+
expect {
|
54
|
+
subject.send :parse_options, %w{-w}
|
55
|
+
}.to raise_error(OptionParser::InvalidOption)
|
56
56
|
end
|
57
57
|
end
|
58
|
-
|
58
|
+
|
59
59
|
context "when a non mandatory option is specified" do
|
60
60
|
subject do
|
61
61
|
Class::new do
|
@@ -69,27 +69,27 @@ describe NagiosCheck do
|
|
69
69
|
|
70
70
|
it "works with '-a 10'" do
|
71
71
|
subject.send :parse_options, %w{-a 10}
|
72
|
-
subject.options.a.
|
73
|
-
end
|
74
|
-
|
72
|
+
expect(subject.options.a).to eq("10")
|
73
|
+
end
|
74
|
+
|
75
75
|
it "works with '-b 20' and converts to int" do
|
76
76
|
subject.send :parse_options, %w{-b 20}
|
77
|
-
subject.options.b.
|
78
|
-
end
|
77
|
+
expect(subject.options.b).to eq(20)
|
78
|
+
end
|
79
79
|
|
80
80
|
it "fails if -a has no argument" do
|
81
|
-
|
82
|
-
subject.send :parse_options, %w{-a}
|
83
|
-
}.
|
81
|
+
expect {
|
82
|
+
subject.send :parse_options, %w{-a}
|
83
|
+
}.to raise_error(OptionParser::MissingArgument)
|
84
84
|
end
|
85
|
-
|
85
|
+
|
86
86
|
it "fails if -w is given" do
|
87
|
-
|
88
|
-
subject.send :parse_options, %w{-w}
|
89
|
-
}.
|
87
|
+
expect {
|
88
|
+
subject.send :parse_options, %w{-w}
|
89
|
+
}.to raise_error(OptionParser::InvalidOption)
|
90
90
|
end
|
91
91
|
end
|
92
|
-
|
92
|
+
|
93
93
|
context "when a mandatory option is specified in arg list" do
|
94
94
|
subject do
|
95
95
|
Class::new do
|
@@ -99,14 +99,14 @@ describe NagiosCheck do
|
|
99
99
|
end
|
100
100
|
|
101
101
|
it "fails if -a is not given" do
|
102
|
-
|
103
|
-
subject.send :parse_options, %w{}
|
104
|
-
}.
|
102
|
+
expect {
|
103
|
+
subject.send :parse_options, %w{}
|
104
|
+
}.to raise_error(NagiosCheck::MissingOption)
|
105
105
|
end
|
106
106
|
|
107
|
-
it "parses option a 3.14" do
|
108
|
-
subject.send :parse_options, %w{-a 3.14}
|
109
|
-
subject.options.a.
|
107
|
+
it "parses option a 3.14" do
|
108
|
+
subject.send :parse_options, %w{-a 3.14}
|
109
|
+
expect(subject.options.a).to eq(3.14)
|
110
110
|
end
|
111
111
|
end
|
112
112
|
|
@@ -119,26 +119,26 @@ describe NagiosCheck do
|
|
119
119
|
end
|
120
120
|
|
121
121
|
it "fails if -a is not given" do
|
122
|
-
|
123
|
-
subject.send :parse_options, %w{}
|
124
|
-
}.
|
122
|
+
expect {
|
123
|
+
subject.send :parse_options, %w{}
|
124
|
+
}.to raise_error(NagiosCheck::MissingOption)
|
125
125
|
end
|
126
126
|
|
127
|
-
it "parses option a 3.14" do
|
128
|
-
subject.send :parse_options, %w{-a 3.14}
|
129
|
-
subject.options.a.
|
127
|
+
it "parses option a 3.14" do
|
128
|
+
subject.send :parse_options, %w{-a 3.14}
|
129
|
+
expect(subject.options.a).to eq(3.14)
|
130
130
|
end
|
131
131
|
end
|
132
132
|
|
133
133
|
shared_examples_for "default provided" do
|
134
134
|
it "defaults to 3.14" do
|
135
|
-
subject.send :parse_options, %w{}
|
136
|
-
subject.options.a.
|
135
|
+
subject.send :parse_options, %w{}
|
136
|
+
expect(subject.options.a).to eq(3.14)
|
137
137
|
end
|
138
138
|
|
139
|
-
it "parses option a at 1.4142" do
|
139
|
+
it "parses option a at 1.4142" do
|
140
140
|
subject.send :parse_options, %w{-a 1.4142}
|
141
|
-
subject.options.a.
|
141
|
+
expect(subject.options.a).to eq(1.4142)
|
142
142
|
end
|
143
143
|
end
|
144
144
|
|
data/spec/range_spec.rb
CHANGED
@@ -4,164 +4,164 @@ require 'pp'
|
|
4
4
|
|
5
5
|
describe NagiosCheck::Range do
|
6
6
|
subject { @range }
|
7
|
-
before(:each) do
|
8
|
-
description =
|
7
|
+
before(:each) do
|
8
|
+
description = RSpec.current_example.metadata[:example_group][:description_args].first
|
9
9
|
if /^when pattern is (.*)/ =~ description
|
10
10
|
@range = NagiosCheck::Range::new($1)
|
11
11
|
end
|
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 { is_expected.to alert_if(-1) }
|
16
|
+
it { is_expected.not_to alert_if(0) }
|
17
|
+
it { is_expected.not_to alert_if(0.1) }
|
18
|
+
it { is_expected.not_to alert_if(1) }
|
19
|
+
it { is_expected.not_to alert_if(9) }
|
20
|
+
it { is_expected.not_to alert_if(9.9) }
|
21
|
+
it { is_expected.not_to alert_if(10) }
|
22
|
+
it { is_expected.not_to alert_if(10.0) }
|
23
|
+
it { is_expected.to 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 {
|
36
|
-
end
|
37
|
-
|
27
|
+
it { is_expected.to alert_if(-1) }
|
28
|
+
it { is_expected.not_to alert_if(0) }
|
29
|
+
it { is_expected.not_to alert_if(0.1) }
|
30
|
+
it { is_expected.not_to alert_if(1) }
|
31
|
+
it { is_expected.not_to alert_if(9) }
|
32
|
+
it { is_expected.not_to alert_if(9.9) }
|
33
|
+
it { is_expected.not_to alert_if(10) }
|
34
|
+
it { is_expected.not_to alert_if(10.0) }
|
35
|
+
it { is_expected.to alert_if(10.1) }
|
36
|
+
end
|
37
|
+
|
38
38
|
context "when pattern is @:10" do
|
39
|
-
it {
|
40
|
-
it {
|
41
|
-
it {
|
42
|
-
it {
|
43
|
-
it {
|
44
|
-
it {
|
39
|
+
it { is_expected.not_to alert_if(-1) }
|
40
|
+
it { is_expected.to alert_if(0) }
|
41
|
+
it { is_expected.to alert_if(5) }
|
42
|
+
it { is_expected.to alert_if(10) }
|
43
|
+
it { is_expected.to alert_if(10.0) }
|
44
|
+
it { is_expected.not_to 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 {
|
55
|
-
end
|
56
|
-
|
48
|
+
it { is_expected.to alert_if(-1) }
|
49
|
+
it { is_expected.to alert_if(1) }
|
50
|
+
it { is_expected.to alert_if(9.9) }
|
51
|
+
it { is_expected.not_to alert_if(10) }
|
52
|
+
it { is_expected.not_to alert_if(10.0) }
|
53
|
+
it { is_expected.not_to alert_if(10.1) }
|
54
|
+
it { is_expected.not_to alert_if(11) }
|
55
|
+
end
|
56
|
+
|
57
57
|
context "when pattern is @10:" do
|
58
|
-
it {
|
59
|
-
it {
|
60
|
-
it {
|
61
|
-
it {
|
62
|
-
it {
|
63
|
-
it {
|
64
|
-
it {
|
58
|
+
it { is_expected.not_to alert_if(-1) }
|
59
|
+
it { is_expected.not_to alert_if(1) }
|
60
|
+
it { is_expected.not_to alert_if(9.9) }
|
61
|
+
it { is_expected.to alert_if(10) }
|
62
|
+
it { is_expected.to alert_if(10.0) }
|
63
|
+
it { is_expected.to alert_if(10.1) }
|
64
|
+
it { is_expected.to 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 {
|
78
|
-
end
|
79
|
-
|
68
|
+
it { is_expected.to alert_if(-1) }
|
69
|
+
it { is_expected.to alert_if(1) }
|
70
|
+
it { is_expected.to alert_if(9.9) }
|
71
|
+
it { is_expected.not_to alert_if(10) }
|
72
|
+
it { is_expected.not_to alert_if(10.0) }
|
73
|
+
it { is_expected.not_to alert_if(10.1) }
|
74
|
+
it { is_expected.not_to alert_if(10.9) }
|
75
|
+
it { is_expected.not_to alert_if(11) }
|
76
|
+
it { is_expected.to alert_if(11.1) }
|
77
|
+
it { is_expected.to alert_if(12) }
|
78
|
+
end
|
79
|
+
|
80
80
|
context "when pattern is 10:10" do
|
81
|
-
it {
|
82
|
-
it {
|
83
|
-
it {
|
84
|
-
it {
|
85
|
-
it {
|
86
|
-
it {
|
87
|
-
it {
|
88
|
-
it {
|
89
|
-
it {
|
90
|
-
it {
|
81
|
+
it { is_expected.to alert_if(-1) }
|
82
|
+
it { is_expected.to alert_if(1) }
|
83
|
+
it { is_expected.to alert_if(9.9) }
|
84
|
+
it { is_expected.not_to alert_if(10) }
|
85
|
+
it { is_expected.not_to alert_if(10.0) }
|
86
|
+
it { is_expected.to alert_if(10.1) }
|
87
|
+
it { is_expected.to alert_if(10.9) }
|
88
|
+
it { is_expected.to alert_if(11) }
|
89
|
+
it { is_expected.to alert_if(11.1) }
|
90
|
+
it { is_expected.to alert_if(12) }
|
91
91
|
end
|
92
92
|
|
93
93
|
context "when pattern is @10:10" do
|
94
|
-
it {
|
95
|
-
it {
|
96
|
-
it {
|
97
|
-
it {
|
98
|
-
it {
|
99
|
-
it {
|
100
|
-
it {
|
101
|
-
it {
|
102
|
-
it {
|
103
|
-
it {
|
94
|
+
it { is_expected.not_to alert_if(-1) }
|
95
|
+
it { is_expected.not_to alert_if(1) }
|
96
|
+
it { is_expected.not_to alert_if(9.9) }
|
97
|
+
it { is_expected.to alert_if(10) }
|
98
|
+
it { is_expected.to alert_if(10.0) }
|
99
|
+
it { is_expected.not_to alert_if(10.1) }
|
100
|
+
it { is_expected.not_to alert_if(10.9) }
|
101
|
+
it { is_expected.not_to alert_if(11) }
|
102
|
+
it { is_expected.not_to alert_if(11.1) }
|
103
|
+
it { is_expected.not_to alert_if(12) }
|
104
104
|
end
|
105
105
|
|
106
106
|
context "when pattern is @10:11" do
|
107
|
-
it {
|
108
|
-
it {
|
109
|
-
it {
|
110
|
-
it {
|
111
|
-
it {
|
112
|
-
it {
|
113
|
-
it {
|
114
|
-
it {
|
115
|
-
it {
|
107
|
+
it { is_expected.not_to alert_if(-1) }
|
108
|
+
it { is_expected.not_to alert_if(1) }
|
109
|
+
it { is_expected.not_to alert_if(9.9) }
|
110
|
+
it { is_expected.to alert_if(10) }
|
111
|
+
it { is_expected.to alert_if(10.0) }
|
112
|
+
it { is_expected.to alert_if(10.1) }
|
113
|
+
it { is_expected.to alert_if(11) }
|
114
|
+
it { is_expected.not_to alert_if(11.1) }
|
115
|
+
it { is_expected.not_to alert_if(12) }
|
116
116
|
end
|
117
117
|
|
118
118
|
context "when pattern is @10.05:11.05" do
|
119
|
-
it {
|
120
|
-
it {
|
121
|
-
it {
|
122
|
-
it {
|
123
|
-
it {
|
124
|
-
it {
|
125
|
-
it {
|
126
|
-
it {
|
127
|
-
it {
|
119
|
+
it { is_expected.not_to alert_if(-1) }
|
120
|
+
it { is_expected.not_to alert_if(1) }
|
121
|
+
it { is_expected.not_to alert_if(9.9) }
|
122
|
+
it { is_expected.not_to alert_if(10) }
|
123
|
+
it { is_expected.not_to alert_if(10.0) }
|
124
|
+
it { is_expected.to alert_if(10.1) }
|
125
|
+
it { is_expected.to alert_if(11) }
|
126
|
+
it { is_expected.not_to alert_if(11.1) }
|
127
|
+
it { is_expected.not_to alert_if(12) }
|
128
128
|
end
|
129
129
|
|
130
130
|
context "when pattern is -1:1" do
|
131
|
-
it {
|
132
|
-
it {
|
133
|
-
it {
|
134
|
-
it {
|
135
|
-
it {
|
136
|
-
it {
|
137
|
-
it {
|
138
|
-
end
|
139
|
-
|
131
|
+
it { is_expected.to alert_if(-2) }
|
132
|
+
it { is_expected.not_to alert_if(-1) }
|
133
|
+
it { is_expected.not_to alert_if(-0.9) }
|
134
|
+
it { is_expected.not_to alert_if(0) }
|
135
|
+
it { is_expected.not_to alert_if(0.9) }
|
136
|
+
it { is_expected.not_to alert_if(1) }
|
137
|
+
it { is_expected.to alert_if(2) }
|
138
|
+
end
|
139
|
+
|
140
140
|
context "when pattern is ~:1" do
|
141
|
-
it {
|
142
|
-
it {
|
143
|
-
it {
|
144
|
-
it {
|
145
|
-
it {
|
141
|
+
it { is_expected.not_to alert_if(-2) }
|
142
|
+
it { is_expected.not_to alert_if(-1) }
|
143
|
+
it { is_expected.not_to alert_if(0) }
|
144
|
+
it { is_expected.not_to alert_if(1) }
|
145
|
+
it { is_expected.to alert_if(2) }
|
146
146
|
end
|
147
|
-
|
147
|
+
|
148
148
|
context "when pattern is @~:1" do
|
149
|
-
it {
|
150
|
-
it {
|
151
|
-
it {
|
152
|
-
it {
|
153
|
-
it {
|
149
|
+
it { is_expected.to alert_if(-2) }
|
150
|
+
it { is_expected.to alert_if(-1) }
|
151
|
+
it { is_expected.to alert_if(0) }
|
152
|
+
it { is_expected.to alert_if(1) }
|
153
|
+
it { is_expected.not_to alert_if(2) }
|
154
154
|
end
|
155
155
|
|
156
|
-
context "when nil pattern" do
|
156
|
+
context "when nil pattern" do
|
157
157
|
it "raises an error" do
|
158
|
-
|
158
|
+
expect { NagiosCheck::Range.new nil }.to raise_error(RuntimeError, "Pattern should not be nil")
|
159
159
|
end
|
160
160
|
end
|
161
|
-
|
162
|
-
context "when empty pattern" do
|
161
|
+
|
162
|
+
context "when empty pattern" do
|
163
163
|
it "raises an error" do
|
164
|
-
|
164
|
+
expect { NagiosCheck::Range.new "" }.to raise_error(RuntimeError, "Pattern should not be nil")
|
165
165
|
end
|
166
166
|
end
|
167
167
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,30 +1,15 @@
|
|
1
1
|
require 'nagios_check'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
@expected = expected
|
7
|
-
end
|
8
|
-
|
9
|
-
def matches?(actual)
|
10
|
-
@actual = actual
|
11
|
-
!@actual.include?(@expected)
|
12
|
-
end
|
13
|
-
|
14
|
-
def failure_message
|
15
|
-
"expected #{@actual} to alert for value #{@expected}"
|
16
|
-
end
|
17
|
-
|
18
|
-
def negative_failure_message
|
19
|
-
"expected #{@actual} not to alert for value #{@expected}"
|
20
|
-
end
|
3
|
+
RSpec::Matchers.define :alert_if do |expected|
|
4
|
+
match do |actual|
|
5
|
+
!actual.include?(expected)
|
21
6
|
end
|
22
7
|
|
23
|
-
|
24
|
-
|
8
|
+
failure_message do |actual|
|
9
|
+
"expected that #{actual} would alert for value #{expected}"
|
25
10
|
end
|
26
|
-
end
|
27
11
|
|
28
|
-
|
29
|
-
|
12
|
+
failure_message_when_negated do |actual|
|
13
|
+
"expected that #{actual} would not alert for value #{expected}"
|
14
|
+
end
|
30
15
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nagios_check
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dominique Broeglin
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-04-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -16,28 +16,28 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: '3.13'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: '3.13'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: 12.3.3
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
40
|
+
version: 12.3.3
|
41
41
|
description: An easy to use DSL for building custom probes for the Nagios monitoring
|
42
42
|
system
|
43
43
|
email:
|
@@ -47,6 +47,7 @@ extensions: []
|
|
47
47
|
extra_rdoc_files: []
|
48
48
|
files:
|
49
49
|
- ".gitignore"
|
50
|
+
- ".travis.yml"
|
50
51
|
- Gemfile
|
51
52
|
- MIT-LICENSE
|
52
53
|
- README.md
|
@@ -63,7 +64,7 @@ files:
|
|
63
64
|
homepage: https://github.com/dbroeglin/nagios_check
|
64
65
|
licenses: []
|
65
66
|
metadata: {}
|
66
|
-
post_install_message:
|
67
|
+
post_install_message:
|
67
68
|
rdoc_options: []
|
68
69
|
require_paths:
|
69
70
|
- lib
|
@@ -78,9 +79,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
78
79
|
- !ruby/object:Gem::Version
|
79
80
|
version: '0'
|
80
81
|
requirements: []
|
81
|
-
|
82
|
-
|
83
|
-
signing_key:
|
82
|
+
rubygems_version: 3.5.7
|
83
|
+
signing_key:
|
84
84
|
specification_version: 4
|
85
85
|
summary: Ruby Nagios Check Integration
|
86
86
|
test_files:
|