nagiosplugin 0.0.2 → 0.0.3

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.
@@ -4,20 +4,14 @@ Feature: Plugin Output
4
4
  As a sysadmin building my own nagios plugins
5
5
  I want to return a nagios compatible plugin output
6
6
 
7
-
8
7
  Scenario Outline: CRITICAL, WARNING and OK
9
- Given a file named "check_foo" with:
8
+ When I run a plugin with the following methods:
10
9
  """
11
- require 'nagiosplugin'
12
- class Foo < NagiosPlugin::Plugin
13
- def critical?; <crit> end
14
- def warning?; <warn> end
15
- end
16
- Foo.check!
10
+ def critical?; <crit> end
11
+ def warning?; <warn> end
17
12
  """
18
- When I run `ruby check_foo`
19
13
  Then the exit status should be <code>
20
- And the stdout should contain "FOO <status>"
14
+ And the plugin should print "<status>"
21
15
 
22
16
  Examples:
23
17
  | crit | warn | code | status |
@@ -26,40 +20,27 @@ Feature: Plugin Output
26
20
  | false | true | 1 | WARNING |
27
21
  | false | false | 0 | OK |
28
22
 
29
-
30
23
  Scenario Outline: UNKNOWN when all status checks return false
31
- Given a file named "check_bar" with:
24
+ When I run a plugin with the following methods:
32
25
  """
33
- require 'nagiosplugin'
34
- class Bar < NagiosPlugin::Plugin
35
- def critical?; false end
36
- def warning?; false end
37
- def ok?; <ok> end
38
- end
39
- Bar.check!
26
+ def critical?; false end
27
+ def warning?; false end
28
+ def ok?; <ok> end
40
29
  """
41
- When I run `ruby check_bar`
42
30
  Then the exit status should be <code>
43
- And the stdout should contain "BAR <status>"
31
+ And the plugin should print "<status>"
44
32
 
45
33
  Examples:
46
34
  | ok | code | status |
47
35
  | true | 0 | OK |
48
36
  | false | 3 | UNKNOWN: All status checks returned false! |
49
37
 
50
-
51
38
  Scenario: UNKNOWN when an exception was raised
52
- Given a file named "check_baz" with:
39
+ When I run a plugin with the following methods:
53
40
  """
54
- require 'nagiosplugin'
55
- class Baz < NagiosPlugin::Plugin
56
- def critical?
57
- raise "OOPS!"
58
- end
41
+ def critical?
42
+ raise "OOPS!"
59
43
  end
60
- Baz.check!
61
44
  """
62
- When I run `ruby check_baz`
63
45
  Then the exit status should be 3
64
- And the stdout should contain "BAZ UNKNOWN: OOPS!"
65
-
46
+ And the plugin should print "UNKNOWN: OOPS!"
@@ -0,0 +1,17 @@
1
+ When /^I run a plugin with the following methods:$/ do |methods|
2
+ steps %Q{
3
+ Given a file named "check_foo" with:
4
+ """
5
+ require 'nagiosplugin'
6
+ class Foo < NagiosPlugin::Plugin
7
+ #{methods}
8
+ end
9
+ Foo.check!
10
+ """
11
+ When I run `ruby check_foo`
12
+ }
13
+ end
14
+
15
+ Then /^the plugin should print "([^"]*)"$/ do |stdout|
16
+ steps %Q{Then the stdout should contain "FOO #{stdout}"}
17
+ end
@@ -6,38 +6,49 @@ module NagiosPlugin
6
6
  :unknown => 3,
7
7
  }
8
8
 
9
+ PluginError = Class.new(StandardError)
10
+
9
11
  class Plugin
10
12
  def self.check!
11
13
  plugin = self.new
12
14
  plugin.check
13
- ensure
15
+ rescue Exception => e
16
+ puts [plugin.prefix, e.to_s].join(' ')
17
+ else
14
18
  puts plugin.message
19
+ ensure
15
20
  exit plugin.code
16
21
  end
17
22
 
18
23
  def check
19
24
  measure if respond_to?(:measure)
20
- @status = [:critical, :warning, :ok].select { |s| send("#{s}?") }.first
21
- raise "All status checks returned false!" if @status.nil?
22
- rescue => e
23
- @info_text = e.to_s
25
+ set_status
26
+ rescue Exception
27
+ @status = :unknown
24
28
  raise
25
29
  end
26
30
 
27
31
  def message
28
- "#{service.upcase} #{status.upcase}: #{@info_text}"
32
+ [prefix, (output if respond_to?(:output))].compact.join(' ')
29
33
  end
30
34
 
31
- def service
32
- self.class.name
35
+ def prefix
36
+ "#{self.class.name.upcase} #{status.upcase}:"
37
+ end
38
+
39
+ def code
40
+ EXIT_CODES[status]
33
41
  end
34
42
 
35
43
  def status
36
44
  @status || :unknown
37
45
  end
38
-
39
- def code
40
- EXIT_CODES[status]
46
+
47
+ protected
48
+
49
+ def set_status
50
+ @status = [:critical, :warning, :ok].select { |s| send("#{s}?") }.first
51
+ raise PluginError, "All status checks returned false!" if @status.nil?
41
52
  end
42
53
 
43
54
  def ok?
@@ -1,3 +1,3 @@
1
1
  module NagiosPlugin
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  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: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-12-30 00:00:00.000000000Z
12
+ date: 2011-12-31 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
16
- requirement: &70108978892680 !ruby/object:Gem::Requirement
16
+ requirement: &70104759276640 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *70108978892680
24
+ version_requirements: *70104759276640
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: cucumber
27
- requirement: &70108978891880 !ruby/object:Gem::Requirement
27
+ requirement: &70104759276020 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *70108978891880
35
+ version_requirements: *70104759276020
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: aruba
38
- requirement: &70108978891080 !ruby/object:Gem::Requirement
38
+ requirement: &70104759275320 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *70108978891080
46
+ version_requirements: *70104759275320
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: guard-cucumber
49
- requirement: &70108978890380 !ruby/object:Gem::Requirement
49
+ requirement: &70104759274600 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,7 +54,7 @@ dependencies:
54
54
  version: '0'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *70108978890380
57
+ version_requirements: *70104759274600
58
58
  description: Yet another framework for writing Nagios Plugins
59
59
  email:
60
60
  - bjoernalbers@googlemail.com
@@ -70,6 +70,7 @@ files:
70
70
  - README.md
71
71
  - Rakefile
72
72
  - features/plugin_output.feature
73
+ - features/steps/dev_steps.rb
73
74
  - features/support/env.rb
74
75
  - lib/nagiosplugin.rb
75
76
  - lib/nagiosplugin/plugin.rb
@@ -89,7 +90,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
89
90
  version: '0'
90
91
  segments:
91
92
  - 0
92
- hash: 2438389996345902943
93
+ hash: -3495919354484579037
93
94
  required_rubygems_version: !ruby/object:Gem::Requirement
94
95
  none: false
95
96
  requirements:
@@ -98,13 +99,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
98
99
  version: '0'
99
100
  segments:
100
101
  - 0
101
- hash: 2438389996345902943
102
+ hash: -3495919354484579037
102
103
  requirements: []
103
104
  rubyforge_project:
104
105
  rubygems_version: 1.8.10
105
106
  signing_key:
106
107
  specification_version: 3
107
- summary: nagiosplugin-0.0.2
108
+ summary: nagiosplugin-0.0.3
108
109
  test_files:
109
110
  - features/plugin_output.feature
111
+ - features/steps/dev_steps.rb
110
112
  - features/support/env.rb