nagios_check 0.0.6 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/lib/nagios_check.rb CHANGED
@@ -31,16 +31,16 @@ module NagiosCheck
31
31
  rescue OptionParser::InvalidArgument, NagiosCheck::MissingOption => e
32
32
  store_message "CLI ERROR: #{e}"
33
33
  rescue => e
34
- store_message "INTERNAL ERROR: #{e}"
34
+ store_message "INTERNAL ERROR: #{e.to_s.gsub(/[\r\n]+/, ' ')}"
35
35
  end
36
36
  msg = status
37
37
  msg += ': ' + message if message
38
- if @values && !@values.empty?
38
+ if @values && !@values.empty?
39
39
  msg += '|' + @values.map do |name, value|
40
40
  "#{name}=#{value};;;;"
41
41
  end.join(' ')
42
42
  end
43
- puts msg
43
+ puts msg
44
44
  exit return_val
45
45
  end
46
46
 
@@ -49,6 +49,7 @@ module NagiosCheck
49
49
  end
50
50
 
51
51
  def finish
52
+ raise "No value was provided" if @values.empty?
52
53
  value = @values.first.last
53
54
  if @options.c && !@options.c.include?(value)
54
55
  return [2, "CRITICAL"]
@@ -1,3 +1,3 @@
1
1
  module NagiosCheck
2
- VERSION = "0.0.6"
2
+ VERSION = "0.1.0"
3
3
  end
data/spec/finish_spec.rb CHANGED
@@ -1,15 +1,15 @@
1
1
  require 'spec_helper'
2
2
  def before_finish_test
3
- before(:each) do
4
- subject.prepare
5
- description = example.metadata[:example_group][:example_group][:description_args].first
6
- if /^when options are '(.*)'$/ =~ description
7
- subject.send :parse_options, $1.split
3
+ before(:each) do
4
+ subject.prepare
5
+ description = example.metadata[:example_group][:example_group][:description_args].first
6
+ if description.kind_of?(String) && /^when options are '(.*)'$/ =~ description
7
+ subject.send :parse_options, $1.split
8
8
  end
9
-
10
- description = example.metadata[:example_group][:description_args].first
11
- if /^when value is (.*)$/ =~ description
12
- subject.store_value 'val', $1.to_f
9
+
10
+ description = example.metadata[:example_group][:description_args].first
11
+ if description.kind_of?(String) && /^when value is (.*)$/ =~ description
12
+ subject.store_value 'val', $1.to_f
13
13
  end
14
14
  end
15
15
  end
@@ -31,8 +31,14 @@ end
31
31
 
32
32
  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
41
+
36
42
  context "when value is 0" do
37
43
  specify { subject.finish.should == [0, "OK"] }
38
44
  end
@@ -43,11 +49,10 @@ describe OkTestCheck do
43
49
  specify { subject.finish.should == [0, "OK"] }
44
50
  end
45
51
  end
46
-
47
52
  end
48
53
 
49
54
  describe WarningTestCheck do
50
- before_finish_test
55
+ before_finish_test
51
56
 
52
57
  context "when options are '-w 10'" do
53
58
  context "when value is -1" do
@@ -69,7 +74,7 @@ describe WarningTestCheck do
69
74
  end
70
75
 
71
76
  describe CriticalTestCheck do
72
- before_finish_test
77
+ before_finish_test
73
78
 
74
79
  context "when options are '-w 10 -c 20'" do
75
80
  context "when value is -1" do
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.0.6
4
+ version: 0.1.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: 2012-07-04 00:00:00.000000000 Z
12
+ date: 2012-07-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec