nagiosplugin 1.0.3 → 1.1.0

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.
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.8.7
4
+ - 1.9.3
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # NagiosPlugin
2
2
 
3
- A simple framework for writing [Nagios](http://www.nagios.org/) Plugins.
3
+ The one [Nagios](http://www.nagios.org/) Plugin framework, forged in the fires of Mount Doom.
4
4
 
5
5
  ## Installation
6
6
 
@@ -8,35 +8,25 @@ A simple framework for writing [Nagios](http://www.nagios.org/) Plugins.
8
8
 
9
9
  ## Usage
10
10
 
11
- Create your executable file (which will be called by nagios), `require
12
- 'nagiosplugin'` and subclass from `NagiosPlugin::Plugin`.
11
+ ### Step 1
13
12
 
14
- Then define a check method in your class which figures out the status
15
- for what you want to check and calls the corresponding status method
16
- (`ok`, `warning`, `critical` or `unknown`) to display a status message
17
- and exit immediately.
13
+ Just subclass from `NagiosPlugin::Plugin` and define your `check` method
14
+ which should figure out the status and then call the appropriate status
15
+ method (`ok`, `warning`, `critical` or `unknown`) with meaningfull message.
16
+ (The status methods will exit immediately by raising a corresponding StatusError.)
18
17
 
19
- Here's a simple example plugin named `check_u2d`:
18
+ Take a look at a working [usage
19
+ example](https://github.com/bjoernalbers/nagiosplugin/blob/master/features/nagiosplugin_usage.feature).
20
20
 
21
- ```Ruby
22
- #!/usr/bin/env ruby
23
- require 'nagiosplugin'
21
+ ### Step 2
24
22
 
25
- class UnicornToDwarfRatio < NagiosPlugin::Plugin
26
- def check
27
- unicorn_to_dwarf_ratio = ... # We still need an alogrithm for this.
28
- msg = "#{unicorn_to_dwarf_ratio} unicorns/dwarves"
23
+ Call the `run` method on your new class, which outputs the check result
24
+ and exits in compliance with the official [Nagios plug-in development
25
+ guidelines](http://nagiosplug.sourceforge.net/developer-guidelines.html)
29
26
 
30
- critical(msg) if unicorn_to_dwarf_ratio < 0.0
31
- warning(msg) if unicorn_to_dwarf_ratio == 0.0
32
- ok(msg)
33
- end
34
- end
27
+ ### Step 3
35
28
 
36
- UnicornToDwarfRatio.run
37
- ```
38
-
39
- Take a look below `features` to see what's going on...
29
+ Profit... and maybe also fun.
40
30
 
41
31
  ## Note on Patches/Pull Requests
42
32
 
data/Rakefile CHANGED
@@ -11,4 +11,4 @@ RSpec::Core::RakeTask.new do |t|
11
11
  t.pattern = './spec/**/*_spec.rb'
12
12
  end
13
13
 
14
- task :default => :features
14
+ task :default => :spec
@@ -0,0 +1,38 @@
1
+ Feature: NagiosPlugin Usage
2
+
3
+ In order to write awesome Nagios Plugins with minimal effort
4
+ As a busy (developer|sysadmin|devop|hacker|superhero|rockstar)
5
+ I want to use the one NagiosPlugin framework
6
+
7
+ Scenario Outline: Subclass from NagiosPlugin
8
+ Given a file named "check_foo.rb" with:
9
+ """
10
+ require 'nagiosplugin'
11
+
12
+ class Foo < NagiosPlugin::Plugin
13
+ def check
14
+ case ARGV.first
15
+ when 'UNKNOWN' then unknown 'no clue, sorry'
16
+ when 'CRITICAL' then critical 'booooom!'
17
+ when 'WARNING' then warning 'it could be worse'
18
+ when 'OK' then ok 'all is fine'
19
+ end
20
+ end
21
+ end
22
+
23
+ Foo.run
24
+ """
25
+ When I run `ruby check_foo.rb <status>`
26
+ Then the exit status should be <code>
27
+ And the stdout should contain exactly:
28
+ """
29
+ <stdout>
30
+
31
+ """
32
+
33
+ Examples:
34
+ | status | code | stdout |
35
+ | UNKNOWN | 3 | FOO UNKNOWN: no clue, sorry |
36
+ | CRITICAL | 2 | FOO CRITICAL: booooom! |
37
+ | WARNING | 1 | FOO WARNING: it could be worse |
38
+ | OK | 0 | FOO OK: all is fine |
@@ -1,36 +1,5 @@
1
1
  module NagiosPlugin
2
2
  class Plugin
3
-
4
- # A custom status error which will be raised through the status methods.
5
- class StatusError < StandardError
6
-
7
- # All allowed statuses sorted by their corresponding exit status.
8
- STATUS = [:ok, :warning, :critical, :unknown]
9
-
10
- # @param [Symbol] status the status (must be {NagiosPlugin::Plugin::StatusError::STATUS a valid status})
11
- # @param [String] message the message you want to display
12
- def initialize(status, message)
13
- @status, @message = status.to_sym, message
14
- end
15
-
16
- # @return [String] the status and message
17
- def to_s
18
- "#{status.to_s.upcase}: #{@message}"
19
- end
20
-
21
- # @return [Fixnum] the status converted into an exit code
22
- def to_i
23
- STATUS.find_index(status)
24
- end
25
-
26
- private
27
-
28
- # @return [Symbol] the status (:unknown if invalid)
29
- def status
30
- (STATUS.include?(@status) && @status) || STATUS.last
31
- end
32
- end
33
-
34
3
  class << self
35
4
 
36
5
  # Create new instance and run it.
@@ -58,7 +27,7 @@ module NagiosPlugin
58
27
 
59
28
  # Overwrite this check method and call a status method within.
60
29
  def check
61
- unknown 'please overwrite the method `check` in your class'
30
+ unknown 'please overwrite the `check` method in your class'
62
31
  end
63
32
 
64
33
  # Run check and return result in a nagios-compatible format.
@@ -0,0 +1,32 @@
1
+ module NagiosPlugin
2
+
3
+ # A custom status error which will be raised through the status methods.
4
+ class StatusError < StandardError
5
+
6
+ # All allowed statuses sorted by their corresponding exit status.
7
+ STATUS = [:ok, :warning, :critical, :unknown]
8
+
9
+ # @param [Symbol] status the status (must be {NagiosPlugin::Plugin::StatusError::STATUS a valid status})
10
+ # @param [String] message the message you want to display
11
+ def initialize(status, message)
12
+ @status, @message = status.to_sym, message
13
+ end
14
+
15
+ # @return [String] the status and message
16
+ def to_s
17
+ "#{status.to_s.upcase}: #{@message}"
18
+ end
19
+
20
+ # @return [Fixnum] the status converted into an exit code
21
+ def to_i
22
+ STATUS.find_index(status)
23
+ end
24
+
25
+ private
26
+
27
+ # @return [Symbol] the status (:unknown if invalid)
28
+ def status
29
+ (STATUS.include?(@status) && @status) || STATUS.last
30
+ end
31
+ end
32
+ end
@@ -1,3 +1,3 @@
1
1
  module NagiosPlugin
2
- VERSION = '1.0.3'
2
+ VERSION = '1.1.0'
3
3
  end
data/lib/nagiosplugin.rb CHANGED
@@ -1,2 +1,3 @@
1
1
  require 'nagiosplugin/version'
2
2
  require 'nagiosplugin/plugin'
3
+ require 'nagiosplugin/status_error'
data/nagiosplugin.gemspec CHANGED
@@ -9,7 +9,7 @@ Gem::Specification.new do |s|
9
9
  s.email = ['bjoernalbers@googlemail.com']
10
10
  s.homepage = 'https://github.com/bjoernalbers/nagiosplugin'
11
11
  s.summary = "#{s.name}-#{s.version}"
12
- s.description = 'A simple framework for writing Nagios Plugins'
12
+ s.description = 'The one Nagios Plugin framework, forged in the fires of Mount Doom.'
13
13
 
14
14
  s.files = `git ls-files`.split("\n")
15
15
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
@@ -24,7 +24,7 @@ describe NagiosPlugin::Plugin do
24
24
  end
25
25
 
26
26
  it 'should output an appropriate message when check was not overwritten' do
27
- @plugin.should_receive(:puts).with(/please overwrite the method `check` in your class/i)
27
+ @plugin.should_receive(:puts).with(/please overwrite the `check` method in your class/i)
28
28
  @plugin.run
29
29
  end
30
30
 
@@ -69,7 +69,7 @@ describe NagiosPlugin::Plugin do
69
69
  context 'when a status error was raised' do
70
70
  before do
71
71
  def @plugin.check
72
- raise NagiosPlugin::Plugin::StatusError.new(:ok, 'hello, world.')
72
+ raise NagiosPlugin::StatusError.new(:ok, 'hello, world.')
73
73
  end
74
74
  end
75
75
 
@@ -90,36 +90,3 @@ describe NagiosPlugin::Plugin do
90
90
  end
91
91
  end
92
92
  end
93
-
94
-
95
- describe NagiosPlugin::Plugin::StatusError do
96
- def create_status(status, msg = '')
97
- NagiosPlugin::Plugin::StatusError.new(status, msg)
98
- end
99
-
100
- %w[ok warning critical unknown].each_with_index do |s,i|
101
- context "when #{s}" do
102
- before { @status = create_status(s.to_sym) }
103
-
104
- it 'should include status in the exception message' do
105
- @status.to_s.should include(s.upcase)
106
- end
107
-
108
- it "should convert to #{i}" do
109
- @status.to_i.should eql(i)
110
- end
111
- end
112
- end
113
-
114
- context 'when initialized with invalid status' do
115
- before { @status = create_status(:invalid) }
116
-
117
- it 'should include unknown status in the exception message' do
118
- @status.to_s.should include('UNKNOWN')
119
- end
120
-
121
- it 'should convert to 3' do
122
- @status.to_i.should eql(3)
123
- end
124
- end
125
- end
@@ -0,0 +1,33 @@
1
+ require 'spec_helper'
2
+
3
+ describe NagiosPlugin::StatusError do
4
+ def create_status(status, msg = '')
5
+ NagiosPlugin::StatusError.new(status, msg)
6
+ end
7
+
8
+ %w[ok warning critical unknown].each_with_index do |s,i|
9
+ context "when #{s}" do
10
+ before { @status = create_status(s.to_sym) }
11
+
12
+ it 'should include status in the exception message' do
13
+ @status.to_s.should include(s.upcase)
14
+ end
15
+
16
+ it "should convert to #{i}" do
17
+ @status.to_i.should eql(i)
18
+ end
19
+ end
20
+ end
21
+
22
+ context 'when initialized with invalid status' do
23
+ before { @status = create_status(:invalid) }
24
+
25
+ it 'should include unknown status in the exception message' do
26
+ @status.to_s.should include('UNKNOWN')
27
+ end
28
+
29
+ it 'should convert to 3' do
30
+ @status.to_i.should eql(3)
31
+ end
32
+ end
33
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nagiosplugin
3
3
  version: !ruby/object:Gem::Version
4
- hash: 17
4
+ hash: 19
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
+ - 1
8
9
  - 0
9
- - 3
10
- version: 1.0.3
10
+ version: 1.1.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - "Bj\xC3\xB6rn Albers"
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-03-30 00:00:00 Z
18
+ date: 2012-04-02 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  type: :development
@@ -101,7 +101,7 @@ dependencies:
101
101
  prerelease: false
102
102
  name: guard-rspec
103
103
  version_requirements: *id006
104
- description: A simple framework for writing Nagios Plugins
104
+ description: The one Nagios Plugin framework, forged in the fires of Mount Doom.
105
105
  email:
106
106
  - bjoernalbers@googlemail.com
107
107
  executables: []
@@ -112,19 +112,22 @@ extra_rdoc_files: []
112
112
 
113
113
  files:
114
114
  - .gitignore
115
+ - .travis.yml
115
116
  - Gemfile
116
117
  - Guardfile
117
118
  - LICENSE
118
119
  - README.md
119
120
  - Rakefile
120
- - features/plugin_output.feature
121
+ - features/nagiosplugin_usage.feature
121
122
  - features/steps/dev_steps.rb
122
123
  - features/support/env.rb
123
124
  - lib/nagiosplugin.rb
124
125
  - lib/nagiosplugin/plugin.rb
126
+ - lib/nagiosplugin/status_error.rb
125
127
  - lib/nagiosplugin/version.rb
126
128
  - nagiosplugin.gemspec
127
129
  - spec/nagiosplugin/plugin_spec.rb
130
+ - spec/nagiosplugin/status_error_spec.rb
128
131
  - spec/spec_helper.rb
129
132
  homepage: https://github.com/bjoernalbers/nagiosplugin
130
133
  licenses: []
@@ -158,10 +161,11 @@ rubyforge_project:
158
161
  rubygems_version: 1.8.11
159
162
  signing_key:
160
163
  specification_version: 3
161
- summary: nagiosplugin-1.0.3
164
+ summary: nagiosplugin-1.1.0
162
165
  test_files:
163
- - features/plugin_output.feature
166
+ - features/nagiosplugin_usage.feature
164
167
  - features/steps/dev_steps.rb
165
168
  - features/support/env.rb
166
169
  - spec/nagiosplugin/plugin_spec.rb
170
+ - spec/nagiosplugin/status_error_spec.rb
167
171
  - spec/spec_helper.rb
@@ -1,50 +0,0 @@
1
- Feature: Plugin Output
2
-
3
- In order to comply with official nagios plugin development guidelines
4
- As a sysadmin building my own nagios plugins
5
- I want to return a nagios compatible plugin output
6
-
7
- Scenario Outline: UNKNOWN, CRITICAL, WARNING and OK
8
- Given a file named "check_foo.rb" with:
9
- """
10
- require 'nagiosplugin'
11
-
12
- class Foo < NagiosPlugin::Plugin
13
- def check
14
- case ARGV.first
15
- when 'UNKNOWN' then unknown 'no clue, sorry'
16
- when 'CRITICAL' then critical 'booooom!'
17
- when 'WARNING' then warning 'it could be worse'
18
- when 'OK' then ok 'all is fine'
19
- end
20
- end
21
- end
22
-
23
- Foo.run
24
- """
25
- When I run `ruby check_foo.rb <status>`
26
- Then the exit status should be <code>
27
- And the stdout should contain "<status>"
28
-
29
- Examples:
30
- | status | code |
31
- | UNKNOWN | 3 |
32
- | CRITICAL | 2 |
33
- | WARNING | 1 |
34
- | OK | 0 |
35
-
36
- Scenario: UNKNOWN when no status method was called
37
- Given a file named "check_foo" with:
38
- """
39
- require 'nagiosplugin'
40
-
41
- class Foo < NagiosPlugin::Plugin
42
- def check
43
- end
44
- end
45
-
46
- Foo.run
47
- """
48
- When I run `ruby check_foo`
49
- Then the exit status should be 3
50
- And the stdout should contain "UNKNOWN"