nagiosplugin 2.0.0 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,14 +1,22 @@
1
1
  # NagiosPlugin
2
2
 
3
- The one [Nagios](http://www.nagios.org/) Plugin framework, forged in the
4
- fires of Mount Doom.
3
+ The one Nagios Plugin framework, forged in the fires of Mount Doom.
5
4
 
6
- [![Build
7
- Status](https://secure.travis-ci.org/bjoernalbers/nagiosplugin.png)](http://travis-ci.org/bjoernalbers/nagiosplugin)
5
+ [![Build Status](https://secure.travis-ci.org/bjoernalbers/nagiosplugin.png)](http://travis-ci.org/bjoernalbers/nagiosplugin)
8
6
 
9
- **NOTE: The API has changed since version 2.0 (see issue
10
- [#2](https://github.com/bjoernalbers/nagiosplugin/issues/2))!!!**
7
+ **NOTE: The API has changed since version 2.1 (see issues
8
+ [#2](https://github.com/bjoernalbers/nagiosplugin/issues/2)
9
+ and
10
+ [#4](https://github.com/bjoernalbers/nagiosplugin/issues/4))!!!**
11
11
 
12
+ ## Introduction
13
+
14
+ NagiosPlugin is an
15
+ [embarrassingly simple](https://github.com/bjoernalbers/nagiosplugin/blob/master/lib/nagiosplugin/plugin.rb)
16
+ framework to write custom monitoring plugins for
17
+ [Nagios](http://www.nagios.org/).
18
+ It was born out of duplication, because all nagios plugins share some
19
+ common behaviour...
12
20
 
13
21
  ## Installation
14
22
 
@@ -70,10 +78,10 @@ end
70
78
 
71
79
  ### Step 3: Perform the actual check.
72
80
 
73
- In your binary then call `check!` on your class and you're done:
81
+ In your binary then call the build-in class method `check` and you're done:
74
82
 
75
83
  ```Ruby
76
- MyFancyPlugin.new.check!
84
+ MyFancyPlugin.check
77
85
  ```
78
86
 
79
87
  This will output the check result and exits in compliance with the
@@ -27,7 +27,7 @@ Feature: NagiosPlugin Usage
27
27
  end
28
28
  end
29
29
 
30
- FancyPlugin.new.check!
30
+ FancyPlugin.check
31
31
  """
32
32
  When I run `ruby check_fancy.rb`
33
33
  Then the exit status should be <code>
@@ -7,12 +7,27 @@ module NagiosPlugin
7
7
  :ok => 0
8
8
  }
9
9
 
10
- def check!
11
- puts nagios_plugin_output
12
- exit nagios_plugin_exit_code
13
- rescue => e
14
- puts "PLUGIN UNKNOWN: #{e.to_s}\n\n#{e.backtrace}"
15
- exit NAGIOS_PLUGIN_EXIT_CODES[:unknown]
10
+ class << self
11
+ def check
12
+ plugin = new
13
+ puts plugin.nagios_plugin_output
14
+ exit plugin.nagios_plugin_exit_code
15
+ rescue => e
16
+ pretty_error = ([e.to_s, nil] + e.backtrace).join("\n")
17
+ puts "PLUGIN UNKNOWN: #{pretty_error}"
18
+ exit NAGIOS_PLUGIN_EXIT_CODES[:unknown]
19
+ end
20
+ end
21
+
22
+ def nagios_plugin_exit_code
23
+ NAGIOS_PLUGIN_EXIT_CODES[nagios_plugin_status]
24
+ end
25
+
26
+ def nagios_plugin_output
27
+ output = [nagios_plugin_service] << ' '
28
+ output << nagios_plugin_status.to_s.upcase
29
+ output << ': ' + message if respond_to?(:message)
30
+ output.join
16
31
  end
17
32
 
18
33
  private
@@ -27,19 +42,8 @@ module NagiosPlugin
27
42
  end
28
43
  end
29
44
 
30
- def nagios_plugin_exit_code
31
- NAGIOS_PLUGIN_EXIT_CODES[nagios_plugin_status]
32
- end
33
-
34
45
  def nagios_plugin_service
35
46
  self.class.name.split('::').last.gsub(/plugin$/i, '').upcase
36
47
  end
37
-
38
- def nagios_plugin_output
39
- output = [nagios_plugin_service] << ' '
40
- output << nagios_plugin_status.to_s.upcase
41
- output << ': ' + message if respond_to?(:message)
42
- output.join
43
- end
44
48
  end
45
49
  end
@@ -1,3 +1,3 @@
1
1
  module NagiosPlugin
2
- VERSION = '2.0.0'
2
+ VERSION = '2.1.0'
3
3
  end
@@ -4,49 +4,50 @@ module NagiosPlugin
4
4
  describe Plugin do
5
5
  let(:plugin) { Plugin.new }
6
6
 
7
- describe '#check!' do
7
+ describe '.check' do
8
8
  before do
9
- plugin.stub(:puts => nil,
10
- :exit => nil,
11
- :nagios_plugin_exit_code => nil,
9
+ plugin.stub(:nagios_plugin_exit_code => nil,
12
10
  :nagios_plugin_output => nil)
11
+ Plugin.stub(:puts => nil,
12
+ :exit => nil,
13
+ :new => plugin)
13
14
  end
14
15
 
15
16
  it 'displays the plugin output on stdout' do
16
- plugin.should_receive(:nagios_plugin_output).and_return('chunky bacon')
17
- plugin.should_receive(:puts).with('chunky bacon')
18
- plugin.check!
17
+ plugin.should_receive(:nagios_plugin_output).
18
+ and_return('chunky bacon')
19
+ Plugin.should_receive(:puts).with('chunky bacon')
20
+ Plugin.check
19
21
  end
20
22
 
21
23
  it 'exits with the status exit code' do
22
24
  plugin.should_receive(:nagios_plugin_exit_code).and_return(42)
23
- plugin.should_receive(:exit).with(42)
24
- plugin.check!
25
+ Plugin.should_receive(:exit).with(42)
26
+ Plugin.check
25
27
  end
26
28
 
27
29
  context 'when an exception was raised' do
28
30
  let(:exception) { StandardError.new }
29
31
 
30
32
  before do
31
- plugin.stub(:nagios_plugin_output).and_return { raise }
33
+ Plugin.stub(:new).and_return { raise 'Oops!' }
32
34
  end
33
35
 
34
36
  it 'rescues the exception' do
35
- expect { plugin.check! }.to_not raise_error
37
+ expect { Plugin.check }.to_not raise_error
36
38
  end
37
39
 
38
40
  it 'exits with exit code unknown' do
39
- plugin.should_receive(:exit).with(3)
40
- plugin.check!
41
+ Plugin.should_receive(:exit).with(3)
42
+ Plugin.check
41
43
  end
42
44
 
43
45
  it 'displays the exception and backtrace on stdout' do
44
- plugin.stub(:nagios_plugin_output).and_return { raise 'Oops!' }
45
46
  StandardError.any_instance.stub(:backtrace).
46
- and_return('Chunky Bacon')
47
- plugin.should_receive(:puts).
48
- with("PLUGIN UNKNOWN: Oops!\n\nChunky Bacon")
49
- plugin.check!
47
+ and_return(%w(Chunky Bacon))
48
+ Plugin.should_receive(:puts).
49
+ with("PLUGIN UNKNOWN: Oops!\n\nChunky\nBacon")
50
+ Plugin.check
50
51
  end
51
52
  end
52
53
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nagiosplugin
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.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: 2013-09-19 00:00:00.000000000 Z
12
+ date: 2013-10-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -145,7 +145,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
145
145
  version: '0'
146
146
  segments:
147
147
  - 0
148
- hash: 1579051430854649941
148
+ hash: 1074742340015625013
149
149
  required_rubygems_version: !ruby/object:Gem::Requirement
150
150
  none: false
151
151
  requirements:
@@ -154,13 +154,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
154
154
  version: '0'
155
155
  segments:
156
156
  - 0
157
- hash: 1579051430854649941
157
+ hash: 1074742340015625013
158
158
  requirements: []
159
159
  rubyforge_project:
160
160
  rubygems_version: 1.8.23
161
161
  signing_key:
162
162
  specification_version: 3
163
- summary: nagiosplugin-2.0.0
163
+ summary: nagiosplugin-2.1.0
164
164
  test_files:
165
165
  - features/nagiosplugin_usage.feature
166
166
  - features/support/env.rb