nagiosplugin 2.0.0 → 2.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/README.md +16 -8
- data/features/nagiosplugin_usage.feature +1 -1
- data/lib/nagiosplugin/plugin.rb +21 -17
- data/lib/nagiosplugin/version.rb +1 -1
- data/spec/nagiosplugin/plugin_spec.rb +19 -18
- metadata +5 -5
data/README.md
CHANGED
@@ -1,14 +1,22 @@
|
|
1
1
|
# NagiosPlugin
|
2
2
|
|
3
|
-
The one
|
4
|
-
fires of Mount Doom.
|
3
|
+
The one Nagios Plugin framework, forged in the fires of Mount Doom.
|
5
4
|
|
6
|
-
[](http://travis-ci.org/bjoernalbers/nagiosplugin)
|
5
|
+
[](http://travis-ci.org/bjoernalbers/nagiosplugin)
|
8
6
|
|
9
|
-
**NOTE: The API has changed since version 2.
|
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
|
81
|
+
In your binary then call the build-in class method `check` and you're done:
|
74
82
|
|
75
83
|
```Ruby
|
76
|
-
MyFancyPlugin.
|
84
|
+
MyFancyPlugin.check
|
77
85
|
```
|
78
86
|
|
79
87
|
This will output the check result and exits in compliance with the
|
data/lib/nagiosplugin/plugin.rb
CHANGED
@@ -7,12 +7,27 @@ module NagiosPlugin
|
|
7
7
|
:ok => 0
|
8
8
|
}
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
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
|
data/lib/nagiosplugin/version.rb
CHANGED
@@ -4,49 +4,50 @@ module NagiosPlugin
|
|
4
4
|
describe Plugin do
|
5
5
|
let(:plugin) { Plugin.new }
|
6
6
|
|
7
|
-
describe '
|
7
|
+
describe '.check' do
|
8
8
|
before do
|
9
|
-
plugin.stub(:
|
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).
|
17
|
-
|
18
|
-
|
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
|
-
|
24
|
-
|
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
|
-
|
33
|
+
Plugin.stub(:new).and_return { raise 'Oops!' }
|
32
34
|
end
|
33
35
|
|
34
36
|
it 'rescues the exception' do
|
35
|
-
expect {
|
37
|
+
expect { Plugin.check }.to_not raise_error
|
36
38
|
end
|
37
39
|
|
38
40
|
it 'exits with exit code unknown' do
|
39
|
-
|
40
|
-
|
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(
|
47
|
-
|
48
|
-
with("PLUGIN UNKNOWN: Oops!\n\nChunky
|
49
|
-
|
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.
|
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-
|
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:
|
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:
|
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.
|
163
|
+
summary: nagiosplugin-2.1.0
|
164
164
|
test_files:
|
165
165
|
- features/nagiosplugin_usage.feature
|
166
166
|
- features/support/env.rb
|