nagiosplugin 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -11,6 +11,7 @@ NagiosPlugin is a simple framework for writing [Nagios](http://www.nagios.org/)
11
11
  Create your executable plugin (which will be called by nagios), `require "nagiosplugin"` and subclass from `NagiosPlugin::Plugin`.
12
12
  You must define the methods `critical?` and `warning?` which determine the plugin status during a check based on their boolean return value (`ok?` returns true by default but can be overwritten).
13
13
  The optional method `measure` will be called *first* on every check to take samples.
14
+ Additional plugin output can be assigned to `@info_text`.
14
15
  Run `check!` on your *class* to ensure a proper plugin output (= stdout & exit status).
15
16
 
16
17
  Here's a simple example plugin named `check_u2d`:
data/Rakefile CHANGED
@@ -1 +1,8 @@
1
1
  require "bundler/gem_tasks"
2
+
3
+ require "cucumber/rake/task"
4
+ Cucumber::Rake::Task.new(:features) do |t|
5
+ t.cucumber_opts = "--format pretty"
6
+ end
7
+
8
+ task :default => :features
@@ -4,6 +4,7 @@ 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
+
7
8
  Scenario Outline: CRITICAL, WARNING and OK
8
9
  Given a file named "check_foo" with:
9
10
  """
@@ -16,11 +17,8 @@ Feature: Plugin Output
16
17
  """
17
18
  When I run `ruby check_foo`
18
19
  Then the exit status should be <code>
19
- And the stdout should contain:
20
- """
21
- FOO <status>
22
-
23
- """
20
+ And the stdout should contain "FOO <status>"
21
+
24
22
  Examples:
25
23
  | crit | warn | code | status |
26
24
  | true | true | 2 | CRITICAL |
@@ -28,6 +26,7 @@ Feature: Plugin Output
28
26
  | false | true | 1 | WARNING |
29
27
  | false | false | 0 | OK |
30
28
 
29
+
31
30
  Scenario Outline: UNKNOWN when all status checks return false
32
31
  Given a file named "check_bar" with:
33
32
  """
@@ -41,17 +40,13 @@ Feature: Plugin Output
41
40
  """
42
41
  When I run `ruby check_bar`
43
42
  Then the exit status should be <code>
44
- # And the stdout should contain exactly:
45
- And the stdout should contain:
46
- """
47
- BAR <status>
48
-
49
- """
43
+ And the stdout should contain "BAR <status>"
44
+
50
45
  Examples:
51
46
  | ok | code | status |
52
47
  | true | 0 | OK |
53
- | false | 3 | UNKNOWN |
54
- # | false | 3 | UNKNOWN: All status checks returned false! |
48
+ | false | 3 | UNKNOWN: All status checks returned false! |
49
+
55
50
 
56
51
  Scenario: UNKNOWN when an exception was raised
57
52
  Given a file named "check_baz" with:
@@ -66,7 +61,5 @@ Feature: Plugin Output
66
61
  """
67
62
  When I run `ruby check_baz`
68
63
  Then the exit status should be 3
69
- And the stdout should contain:
70
- """
71
- BAZ UNKNOWN
72
- """
64
+ And the stdout should contain "BAZ UNKNOWN: OOPS!"
65
+
@@ -7,10 +7,6 @@ module NagiosPlugin
7
7
  }
8
8
 
9
9
  class Plugin
10
- def initialize
11
- @status = :unknown
12
- end
13
-
14
10
  def self.check!
15
11
  plugin = self.new
16
12
  plugin.check
@@ -22,26 +18,26 @@ module NagiosPlugin
22
18
  def check
23
19
  measure if respond_to?(:measure)
24
20
  @status = [:critical, :warning, :ok].select { |s| send("#{s}?") }.first
25
- raise if @status.nil?
26
- rescue
27
- @status = :unknown
21
+ raise "All status checks returned false!" if @status.nil?
22
+ rescue => e
23
+ @info_text = e.to_s
28
24
  raise
29
25
  end
30
26
 
31
27
  def message
32
- "#{service} #{status}"
28
+ "#{service.upcase} #{status.upcase}: #{@info_text}"
33
29
  end
34
30
 
35
31
  def service
36
- self.class.name.upcase
32
+ self.class.name
37
33
  end
38
34
 
39
35
  def status
40
- @status.upcase
36
+ @status || :unknown
41
37
  end
42
38
 
43
39
  def code
44
- EXIT_CODES[@status]
40
+ EXIT_CODES[status]
45
41
  end
46
42
 
47
43
  def ok?
@@ -1,3 +1,3 @@
1
1
  module NagiosPlugin
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
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.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2011-12-30 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
16
- requirement: &70231877033500 !ruby/object:Gem::Requirement
16
+ requirement: &70108978892680 !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: *70231877033500
24
+ version_requirements: *70108978892680
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: cucumber
27
- requirement: &70231877022080 !ruby/object:Gem::Requirement
27
+ requirement: &70108978891880 !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: *70231877022080
35
+ version_requirements: *70108978891880
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: aruba
38
- requirement: &70231877021460 !ruby/object:Gem::Requirement
38
+ requirement: &70108978891080 !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: *70231877021460
46
+ version_requirements: *70108978891080
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: guard-cucumber
49
- requirement: &70231877020820 !ruby/object:Gem::Requirement
49
+ requirement: &70108978890380 !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: *70231877020820
57
+ version_requirements: *70108978890380
58
58
  description: Yet another framework for writing Nagios Plugins
59
59
  email:
60
60
  - bjoernalbers@googlemail.com
@@ -87,18 +87,24 @@ required_ruby_version: !ruby/object:Gem::Requirement
87
87
  - - ! '>='
88
88
  - !ruby/object:Gem::Version
89
89
  version: '0'
90
+ segments:
91
+ - 0
92
+ hash: 2438389996345902943
90
93
  required_rubygems_version: !ruby/object:Gem::Requirement
91
94
  none: false
92
95
  requirements:
93
96
  - - ! '>='
94
97
  - !ruby/object:Gem::Version
95
98
  version: '0'
99
+ segments:
100
+ - 0
101
+ hash: 2438389996345902943
96
102
  requirements: []
97
103
  rubyforge_project:
98
104
  rubygems_version: 1.8.10
99
105
  signing_key:
100
106
  specification_version: 3
101
- summary: nagiosplugin-0.0.1
107
+ summary: nagiosplugin-0.0.2
102
108
  test_files:
103
109
  - features/plugin_output.feature
104
110
  - features/support/env.rb