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.
- data/features/plugin_output.feature +13 -32
- data/features/steps/dev_steps.rb +17 -0
- data/lib/nagiosplugin/plugin.rb +22 -11
- data/lib/nagiosplugin/version.rb +1 -1
- metadata +15 -13
@@ -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
|
-
|
8
|
+
When I run a plugin with the following methods:
|
10
9
|
"""
|
11
|
-
|
12
|
-
|
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
|
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
|
-
|
24
|
+
When I run a plugin with the following methods:
|
32
25
|
"""
|
33
|
-
|
34
|
-
|
35
|
-
|
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
|
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
|
-
|
39
|
+
When I run a plugin with the following methods:
|
53
40
|
"""
|
54
|
-
|
55
|
-
|
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
|
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
|
data/lib/nagiosplugin/plugin.rb
CHANGED
@@ -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
|
-
|
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
|
-
|
21
|
-
|
22
|
-
|
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
|
-
|
32
|
+
[prefix, (output if respond_to?(:output))].compact.join(' ')
|
29
33
|
end
|
30
34
|
|
31
|
-
def
|
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
|
-
|
40
|
-
|
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?
|
data/lib/nagiosplugin/version.rb
CHANGED
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.
|
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-
|
12
|
+
date: 2011-12-31 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
16
|
-
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: *
|
24
|
+
version_requirements: *70104759276640
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: cucumber
|
27
|
-
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: *
|
35
|
+
version_requirements: *70104759276020
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: aruba
|
38
|
-
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: *
|
46
|
+
version_requirements: *70104759275320
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: guard-cucumber
|
49
|
-
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: *
|
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:
|
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:
|
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.
|
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
|