nagios_check 0.4.0 → 0.4.1

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
- SHA1:
3
- metadata.gz: 0be1e0cf8818d77cf5df2270e14dc0b22666b3fc
4
- data.tar.gz: 7939ff0f301d34eda715e3c7af90f48629f493cb
2
+ SHA256:
3
+ metadata.gz: 9fc94a2d97088c48f83d820d58bae3cd3b98531feb9007fd9ba44a5f9853dfd4
4
+ data.tar.gz: dd9022e057eb61941652f6e4a3f15fc179e6f4de15b310d090121b8ea2277028
5
5
  SHA512:
6
- metadata.gz: 2ef4a3d420ce9a217769345c5e1bddce5b574bff440b4f095d0f32d79a9c526cc13ced9a1951d0ef9822cc1b4e761ffe754ad199fe67c4a56f57b84bf09edd6e
7
- data.tar.gz: 1e3d9531a483d3e7a418891d22762d6361602a038dabb3700c45d04ae5a5b88f450a27ffa28a4d7151f8921bfebeaa72e55148c665ce4e21e693ef80d6bf23be
6
+ metadata.gz: f7b5358d1903d83548fca5e8a951a06e2af1cec7f2ef58670eb32be2678f82402ae5823b43c3826cecb39de235a77d1b9caf52e26359e87bf98fbd71c485c843
7
+ data.tar.gz: 0f7d461c349997293955d4679b805511f3b619648b61c4cb52e24dbf67c30c63b94e0983d45a68ae8bca073ab0e27f16c724ec75ae43b1a0d62056609891ec13
data/.travis.yml ADDED
@@ -0,0 +1,17 @@
1
+ language: ruby
2
+ sudo: false
3
+ cache:
4
+ directories:
5
+ - ../bundle
6
+ rvm:
7
+ - 1.9.2
8
+ - 1.9.3
9
+ - 2.0.0
10
+ - 2.1
11
+ - 2.2.7
12
+ - 2.3.4
13
+ - 2.4.1
14
+ - ruby-head
15
+ branches:
16
+ only:
17
+ - master
data/README.md CHANGED
@@ -1,6 +1,9 @@
1
1
  NagiosCheck
2
2
  ============
3
3
 
4
+ [![Gem Version](https://badge.fury.io/rb/nagios_check.svg)](https://badge.fury.io/rb/nagios_check)
5
+ [![Build Status](https://travis-ci.org/dbroeglin/nagios_check.svg?branch=master)](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 value returned by `do_some_check` 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.
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
- An alternative shorter way of writting the above check would be:
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
@@ -2,3 +2,5 @@ require 'bundler/gem_tasks'
2
2
 
3
3
  require "rspec/core/rake_task"
4
4
  RSpec::Core::RakeTask.new(:rspec)
5
+
6
+ task :default => :rspec
@@ -1,3 +1,3 @@
1
1
  module NagiosCheck
2
- VERSION = "0.4.0"
2
+ VERSION = "0.4.1"
3
3
  end
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
- puts msg
47
- exit return_val
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", "~> 2.14.0"
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 = example.metadata[:example_group][:example_group][:description_args].first
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 = example.metadata[:example_group][:description_args].first
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
- it "should fail when no value is given" do
37
- lambda {
38
- subject.finish
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
- context "when value is 0" do
43
- specify { subject.finish.should == [0, "OK"] }
44
- end
45
- context "when value is 5" do
46
- specify { subject.finish.should == [0, "OK"] }
47
- end
48
- context "when value is 10" do
49
- specify { subject.finish.should == [0, "OK"] }
50
- end
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
- context "when nil is given" do
53
- before { subject.store_value 'val', nil }
54
- specify { subject.finish.should == [3, "UNKNOWN"] }
55
- end
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.should == [1, "WARNING"] }
62
+ specify { expect(subject.finish).to eq([1, "WARNING"]) }
65
63
  end
66
64
  context "when value is 0" do
67
- specify { subject.finish.should == [0, "OK"] }
65
+ specify { expect(subject.finish).to eq([0, "OK"]) }
68
66
  end
69
67
  context "when value is 5" do
70
- specify { subject.finish.should == [0, "OK"] }
68
+ specify { expect(subject.finish).to eq([0, "OK"]) }
71
69
  end
72
70
  context "when value is 10" do
73
- specify { subject.finish.should == [0, "OK"] }
71
+ specify { expect(subject.finish).to eq([0, "OK"]) }
74
72
  end
75
73
  context "when value is 11" do
76
- specify { subject.finish.should == [1, "WARNING"] }
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.should == [2, "CRITICAL"] }
83
+ specify { expect(subject.finish).to eq([2, "CRITICAL"]) }
87
84
  end
88
85
  context "when value is 0" do
89
- specify { subject.finish.should == [0, "OK"] }
86
+ specify { expect(subject.finish).to eq([0, "OK"]) }
90
87
  end
91
88
  context "when value is 5" do
92
- specify { subject.finish.should == [0, "OK"] }
89
+ specify { expect(subject.finish).to eq([0, "OK"]) }
93
90
  end
94
91
  context "when value is 10" do
95
- specify { subject.finish.should == [0, "OK"] }
92
+ specify { expect(subject.finish).to eq([0, "OK"]) }
96
93
  end
97
94
  context "when value is 15" do
98
- specify { subject.finish.should == [1, "WARNING"] }
95
+ specify { expect(subject.finish).to eq([1, "WARNING"]) }
99
96
  end
100
97
  context "when value is 20" do
101
- specify { subject.finish.should == [1, "WARNING"] }
98
+ specify { expect(subject.finish).to eq([1, "WARNING"]) }
102
99
  end
103
100
  context "when value is 21" do
104
- specify { subject.finish.should == [2, "CRITICAL"] }
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
- lambda {
25
- subject.send :parse_options, %w{-w}
26
- }.should raise_error(OptionParser::MissingArgument)
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
- lambda {
30
- subject.send :parse_options, %w{-c}
31
- }.should raise_error(OptionParser::InvalidOption)
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
- lambda {
48
- subject.send :parse_options, %w{-c}
49
- }.should raise_error(OptionParser::MissingArgument)
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
- lambda {
54
- subject.send :parse_options, %w{-w}
55
- }.should raise_error(OptionParser::InvalidOption)
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.should == "10"
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.should == 20
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
- lambda {
82
- subject.send :parse_options, %w{-a}
83
- }.should raise_error(OptionParser::MissingArgument)
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
- lambda {
88
- subject.send :parse_options, %w{-w}
89
- }.should raise_error(OptionParser::InvalidOption)
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
- lambda {
103
- subject.send :parse_options, %w{}
104
- }.should raise_error(NagiosCheck::MissingOption)
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.should == 3.14
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
- lambda {
123
- subject.send :parse_options, %w{}
124
- }.should raise_error(NagiosCheck::MissingOption)
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.should == 3.14
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.should == 3.14
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.should == 1.4142
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 = example.metadata[:example_group][:description_args].first
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 { 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 }
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 { 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
- 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 { 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 }
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 { 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
- 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 { 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 }
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 { 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
- 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 { 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 }
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 { 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 }
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 { 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 }
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 { 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 }
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 { 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 }
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 { 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 }
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 { 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 }
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
- lambda { NagiosCheck::Range.new nil }.should raise_error
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
- lambda { NagiosCheck::Range.new "" }.should raise_error
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
- module Matchers
4
- class Contain
5
- def initialize(expected)
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
- def alert_if(value)
24
- Contain::new(value)
8
+ failure_message do |actual|
9
+ "expected that #{actual} would alert for value #{expected}"
25
10
  end
26
- end
27
11
 
28
- RSpec.configure do |config|
29
- config.include(Matchers)
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.0
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: 2017-01-27 00:00:00.000000000 Z
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: 2.14.0
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: 2.14.0
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: '0'
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: '0'
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
- rubyforge_project: nagios_check
82
- rubygems_version: 2.5.1
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: