nagiosplugin 2.1.1 → 2.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +8 -19
- data/lib/nagiosplugin/plugin.rb +2 -2
- data/lib/nagiosplugin/version.rb +1 -1
- data/nagiosplugin.gemspec +2 -2
- data/spec/nagiosplugin/plugin_spec.rb +51 -32
- metadata +23 -43
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 5bb7500269428bb2869fb2d1a2c072fb4211f98d
|
4
|
+
data.tar.gz: 68082b3cf61bb359310cd5503b0131a403632f80
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b0d12d8f990dd210ea2927d76c3727a5ff1d24c490a30489e8b986f3fb3dc585f6994d137fa790f291adc110897fd96800ecbc97e22bc3ed162115f70a4a2655
|
7
|
+
data.tar.gz: 4e8046957f75bac17ae00b663fdfc635da11eb244339dac15874c8f820845955be581952af3953a1d06710e169f136d8517f8473c86ff176030ceb89fa696056
|
data/README.md
CHANGED
@@ -2,13 +2,9 @@
|
|
2
2
|
|
3
3
|
The one Nagios Plugin framework, forged in the fires of Mount Doom.
|
4
4
|
|
5
|
+
[![Gem Version](https://badge.fury.io/rb/nagiosplugin.svg)](http://badge.fury.io/rb/nagiosplugin)
|
5
6
|
[![Build Status](https://secure.travis-ci.org/bjoernalbers/nagiosplugin.png)](http://travis-ci.org/bjoernalbers/nagiosplugin)
|
6
7
|
|
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
|
-
|
12
8
|
## Introduction
|
13
9
|
|
14
10
|
NagiosPlugin is an
|
@@ -66,7 +62,7 @@ doesn't use that either), parse CLI options, etc.
|
|
66
62
|
### Step 2: Provide some context via status message (optionally).
|
67
63
|
|
68
64
|
Ask yourself what might be important to know (and fits into a text
|
69
|
-
message) when Nagios
|
65
|
+
message) when Nagios send you an alert in the middle of the night.
|
70
66
|
|
71
67
|
```Ruby
|
72
68
|
def message
|
@@ -78,12 +74,16 @@ end
|
|
78
74
|
|
79
75
|
### Step 3: Perform the actual check.
|
80
76
|
|
81
|
-
In your binary then call the build-in class method `check` and you're done:
|
77
|
+
In your binary then just call the build-in class method `check` and you're done:
|
82
78
|
|
83
79
|
```Ruby
|
84
|
-
MyFancyPlugin.check
|
80
|
+
MyFancyPlugin.check(options)
|
85
81
|
```
|
86
82
|
|
83
|
+
(Optional arguments, i.e. from your favorite [CLI option
|
84
|
+
parser](https://www.ruby-toolbox.com/categories/CLI_Option_Parsers), will be
|
85
|
+
forwarded to you initializer method.)
|
86
|
+
|
87
87
|
This will output the check result and exits in compliance with the
|
88
88
|
official
|
89
89
|
[Nagios plug-in development
|
@@ -93,17 +93,6 @@ If anything funky happens in your code: NagiosPlugin does a "blind
|
|
93
93
|
rescue mission" and transforms any execptions to an unknown status.
|
94
94
|
|
95
95
|
|
96
|
-
## One more thing...
|
97
|
-
|
98
|
-
The API changed completely compared to v1.3 as well as the default command
|
99
|
-
line options (they are gone).
|
100
|
-
I suggest that you use 3rd party [CLI Option
|
101
|
-
Parsers](https://www.ruby-toolbox.com/categories/CLI_Option_Parsers)
|
102
|
-
because everyone has different preferences on this.
|
103
|
-
|
104
|
-
Please let me know if you find this usefull or if you want to contribute!
|
105
|
-
|
106
|
-
|
107
96
|
## Note on Patches/Pull Requests
|
108
97
|
|
109
98
|
* Fork the project and run `bundle install` to resolve all development
|
data/lib/nagiosplugin/plugin.rb
CHANGED
data/lib/nagiosplugin/version.rb
CHANGED
data/nagiosplugin.gemspec
CHANGED
@@ -7,7 +7,7 @@ Gem::Specification.new do |spec|
|
|
7
7
|
spec.name = 'nagiosplugin'
|
8
8
|
spec.version = NagiosPlugin::VERSION
|
9
9
|
spec.authors = ['Björn Albers']
|
10
|
-
spec.email = ['bjoernalbers@
|
10
|
+
spec.email = ['bjoernalbers@gmail.com']
|
11
11
|
spec.homepage = 'https://github.com/bjoernalbers/nagiosplugin'
|
12
12
|
spec.summary = "#{spec.name}-#{spec.version}"
|
13
13
|
spec.description = 'The one Nagios Plugin framework, forged in the fires of Mount Doom.'
|
@@ -22,6 +22,6 @@ Gem::Specification.new do |spec|
|
|
22
22
|
spec.add_development_dependency 'cucumber'
|
23
23
|
spec.add_development_dependency 'aruba'
|
24
24
|
spec.add_development_dependency 'guard-cucumber'
|
25
|
-
spec.add_development_dependency 'rspec'
|
25
|
+
spec.add_development_dependency 'rspec', '~> 3.1'
|
26
26
|
spec.add_development_dependency 'guard-rspec'
|
27
27
|
end
|
@@ -6,31 +6,38 @@ module NagiosPlugin
|
|
6
6
|
|
7
7
|
describe '.check' do
|
8
8
|
before do
|
9
|
-
plugin.
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
9
|
+
allow(plugin).to receive_messages(
|
10
|
+
nagios_plugin_exit_code: nil,
|
11
|
+
nagios_plugin_output: nil)
|
12
|
+
allow(Plugin).to receive_messages(
|
13
|
+
puts: nil,
|
14
|
+
exit: nil,
|
15
|
+
new: plugin)
|
14
16
|
end
|
15
17
|
|
16
18
|
it 'displays the plugin output on stdout' do
|
17
|
-
plugin.
|
19
|
+
allow(plugin).to receive(:nagios_plugin_output).
|
18
20
|
and_return('chunky bacon')
|
19
|
-
Plugin.should_receive(:puts).with('chunky bacon')
|
20
21
|
Plugin.check
|
22
|
+
expect(Plugin).to have_received(:puts).with('chunky bacon')
|
21
23
|
end
|
22
24
|
|
23
25
|
it 'exits with the status exit code' do
|
24
|
-
plugin.
|
25
|
-
Plugin.should_receive(:exit).with(42)
|
26
|
+
allow(plugin).to receive(:nagios_plugin_exit_code).and_return(42)
|
26
27
|
Plugin.check
|
28
|
+
expect(Plugin).to have_received(:exit).with(42)
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'passed all arguments to the initializer' do
|
32
|
+
Plugin.check(42, fancy: true)
|
33
|
+
expect(Plugin).to have_received(:new).with(42, fancy: true)
|
27
34
|
end
|
28
35
|
|
29
36
|
context 'when an exception was raised' do
|
30
|
-
let(:exception) { StandardError.new }
|
37
|
+
let(:exception) { StandardError.new('Oops!') }
|
31
38
|
|
32
39
|
before do
|
33
|
-
Plugin.
|
40
|
+
allow(Plugin).to receive(:new).and_raise(exception)
|
34
41
|
end
|
35
42
|
|
36
43
|
it 'rescues the exception' do
|
@@ -38,16 +45,16 @@ module NagiosPlugin
|
|
38
45
|
end
|
39
46
|
|
40
47
|
it 'exits with exit code unknown' do
|
41
|
-
Plugin.should_receive(:exit).with(3)
|
42
48
|
Plugin.check
|
49
|
+
expect(Plugin).to have_received(:exit).with(3)
|
43
50
|
end
|
44
51
|
|
45
52
|
it 'displays the exception and backtrace on stdout' do
|
46
|
-
StandardError.
|
47
|
-
|
48
|
-
Plugin.should_receive(:puts).
|
49
|
-
with("PLUGIN UNKNOWN: Oops!\n\nChunky\nBacon")
|
53
|
+
allow(StandardError).to receive(:new).and_return(exception)
|
54
|
+
allow(exception).to receive(:backtrace).and_return(%w(Chunky Bacon))
|
50
55
|
Plugin.check
|
56
|
+
expect(Plugin).to have_received(:puts).
|
57
|
+
with("PLUGIN UNKNOWN: Oops!\n\nChunky\nBacon")
|
51
58
|
end
|
52
59
|
end
|
53
60
|
end
|
@@ -68,28 +75,40 @@ module NagiosPlugin
|
|
68
75
|
|
69
76
|
describe '#nagios_plugin_status' do
|
70
77
|
it 'returns unknown when not critical, warning or ok' do
|
71
|
-
plugin.
|
78
|
+
allow(plugin).to receive_messages(
|
79
|
+
critical?: false,
|
80
|
+
warning?: false,
|
81
|
+
ok?: false)
|
72
82
|
expect(plugin.send(:nagios_plugin_status)).to eq(:unknown)
|
73
83
|
end
|
74
84
|
|
75
85
|
it 'returns critical when critical' do
|
76
|
-
plugin.
|
86
|
+
allow(plugin).to receive_messages(
|
87
|
+
critical?: true,
|
88
|
+
warning?: true,
|
89
|
+
ok?: true)
|
77
90
|
expect(plugin.send(:nagios_plugin_status)).to eq(:critical)
|
78
91
|
end
|
79
92
|
|
80
93
|
it 'returns warning when warning but not critical' do
|
81
|
-
plugin.
|
94
|
+
allow(plugin).to receive_messages(
|
95
|
+
critical?: false,
|
96
|
+
warning?: true,
|
97
|
+
ok?: true)
|
82
98
|
expect(plugin.send(:nagios_plugin_status)).to eq(:warning)
|
83
99
|
end
|
84
100
|
|
85
101
|
it 'returns ok when ok but not critical or warning' do
|
86
|
-
plugin.
|
102
|
+
allow(plugin).to receive_messages(
|
103
|
+
critical?: false,
|
104
|
+
warning?: false,
|
105
|
+
ok?: true)
|
87
106
|
expect(plugin.send(:nagios_plugin_status)).to eq(:ok)
|
88
107
|
end
|
89
108
|
|
90
|
-
it '
|
109
|
+
it 'caches the status' do
|
91
110
|
[:critical?, :warning?, :ok?].each do |check|
|
92
|
-
plugin.
|
111
|
+
allow(plugin).to receive(check).once.and_return(false)
|
93
112
|
end
|
94
113
|
expect(plugin.send(:nagios_plugin_status)).to eq(:unknown)
|
95
114
|
expect(plugin.send(:nagios_plugin_status)).to eq(:unknown)
|
@@ -98,44 +117,44 @@ module NagiosPlugin
|
|
98
117
|
|
99
118
|
describe '#nagios_plugin_exit_code' do
|
100
119
|
it 'returns 3 when unknown' do
|
101
|
-
plugin.
|
120
|
+
allow(plugin).to receive(:nagios_plugin_status).and_return(:unknown)
|
102
121
|
expect(plugin.send(:nagios_plugin_exit_code)).to eq(3)
|
103
122
|
end
|
104
123
|
|
105
124
|
it 'returns 2 when critical' do
|
106
|
-
plugin.
|
125
|
+
allow(plugin).to receive(:nagios_plugin_status).and_return(:critical)
|
107
126
|
expect(plugin.send(:nagios_plugin_exit_code)).to eq(2)
|
108
127
|
end
|
109
128
|
|
110
129
|
it 'returns 1 when warning' do
|
111
|
-
plugin.
|
130
|
+
allow(plugin).to receive(:nagios_plugin_status).and_return(:warning)
|
112
131
|
expect(plugin.send(:nagios_plugin_exit_code)).to eq(1)
|
113
132
|
end
|
114
133
|
|
115
134
|
it 'returns 0 when ok' do
|
116
|
-
plugin.
|
135
|
+
allow(plugin).to receive(:nagios_plugin_status).and_return(:ok)
|
117
136
|
expect(plugin.send(:nagios_plugin_exit_code)).to eq(0)
|
118
137
|
end
|
119
138
|
end
|
120
139
|
|
121
140
|
describe '#nagios_plugin_output' do
|
122
141
|
before do
|
123
|
-
plugin.
|
142
|
+
allow(plugin).to receive(:nagios_plugin_status)
|
124
143
|
end
|
125
144
|
|
126
145
|
it 'joins the service name and the upcased status' do
|
127
|
-
plugin.
|
128
|
-
plugin.
|
146
|
+
allow(plugin).to receive(:nagios_plugin_service).and_return('FRIED')
|
147
|
+
allow(plugin).to receive(:nagios_plugin_status).and_return(:chicken)
|
129
148
|
expect(plugin.send(:nagios_plugin_output)).to match(/^FRIED CHICKEN$/)
|
130
149
|
end
|
131
150
|
|
132
151
|
it 'includes a custom plugin message if present' do
|
133
|
-
plugin.
|
152
|
+
allow(plugin).to receive(:message).and_return('ALL U CAN EAT!')
|
134
153
|
expect(plugin.send(:nagios_plugin_output)).to match(/: ALL U CAN EAT!$/)
|
135
154
|
end
|
136
155
|
|
137
|
-
it '
|
138
|
-
plugin.
|
156
|
+
it 'does not append message if message is empty' do
|
157
|
+
allow(plugin).to receive(:message).and_return('')
|
139
158
|
expect(plugin.send(:nagios_plugin_output)).not_to match(/:/)
|
140
159
|
end
|
141
160
|
|
metadata
CHANGED
@@ -1,115 +1,102 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nagiosplugin
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
5
|
-
prerelease:
|
4
|
+
version: 2.2.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Björn Albers
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2014-11-09 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: rake
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - ">="
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: '0'
|
22
20
|
type: :development
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
|
-
- -
|
24
|
+
- - ">="
|
28
25
|
- !ruby/object:Gem::Version
|
29
26
|
version: '0'
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: cucumber
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
|
-
- -
|
31
|
+
- - ">="
|
36
32
|
- !ruby/object:Gem::Version
|
37
33
|
version: '0'
|
38
34
|
type: :development
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
|
-
- -
|
38
|
+
- - ">="
|
44
39
|
- !ruby/object:Gem::Version
|
45
40
|
version: '0'
|
46
41
|
- !ruby/object:Gem::Dependency
|
47
42
|
name: aruba
|
48
43
|
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
44
|
requirements:
|
51
|
-
- -
|
45
|
+
- - ">="
|
52
46
|
- !ruby/object:Gem::Version
|
53
47
|
version: '0'
|
54
48
|
type: :development
|
55
49
|
prerelease: false
|
56
50
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
51
|
requirements:
|
59
|
-
- -
|
52
|
+
- - ">="
|
60
53
|
- !ruby/object:Gem::Version
|
61
54
|
version: '0'
|
62
55
|
- !ruby/object:Gem::Dependency
|
63
56
|
name: guard-cucumber
|
64
57
|
requirement: !ruby/object:Gem::Requirement
|
65
|
-
none: false
|
66
58
|
requirements:
|
67
|
-
- -
|
59
|
+
- - ">="
|
68
60
|
- !ruby/object:Gem::Version
|
69
61
|
version: '0'
|
70
62
|
type: :development
|
71
63
|
prerelease: false
|
72
64
|
version_requirements: !ruby/object:Gem::Requirement
|
73
|
-
none: false
|
74
65
|
requirements:
|
75
|
-
- -
|
66
|
+
- - ">="
|
76
67
|
- !ruby/object:Gem::Version
|
77
68
|
version: '0'
|
78
69
|
- !ruby/object:Gem::Dependency
|
79
70
|
name: rspec
|
80
71
|
requirement: !ruby/object:Gem::Requirement
|
81
|
-
none: false
|
82
72
|
requirements:
|
83
|
-
- -
|
73
|
+
- - "~>"
|
84
74
|
- !ruby/object:Gem::Version
|
85
|
-
version: '
|
75
|
+
version: '3.1'
|
86
76
|
type: :development
|
87
77
|
prerelease: false
|
88
78
|
version_requirements: !ruby/object:Gem::Requirement
|
89
|
-
none: false
|
90
79
|
requirements:
|
91
|
-
- -
|
80
|
+
- - "~>"
|
92
81
|
- !ruby/object:Gem::Version
|
93
|
-
version: '
|
82
|
+
version: '3.1'
|
94
83
|
- !ruby/object:Gem::Dependency
|
95
84
|
name: guard-rspec
|
96
85
|
requirement: !ruby/object:Gem::Requirement
|
97
|
-
none: false
|
98
86
|
requirements:
|
99
|
-
- -
|
87
|
+
- - ">="
|
100
88
|
- !ruby/object:Gem::Version
|
101
89
|
version: '0'
|
102
90
|
type: :development
|
103
91
|
prerelease: false
|
104
92
|
version_requirements: !ruby/object:Gem::Requirement
|
105
|
-
none: false
|
106
93
|
requirements:
|
107
|
-
- -
|
94
|
+
- - ">="
|
108
95
|
- !ruby/object:Gem::Version
|
109
96
|
version: '0'
|
110
97
|
description: The one Nagios Plugin framework, forged in the fires of Mount Doom.
|
111
98
|
email:
|
112
|
-
- bjoernalbers@
|
99
|
+
- bjoernalbers@gmail.com
|
113
100
|
executables: []
|
114
101
|
extensions: []
|
115
102
|
extra_rdoc_files: []
|
@@ -130,34 +117,27 @@ files:
|
|
130
117
|
homepage: https://github.com/bjoernalbers/nagiosplugin
|
131
118
|
licenses:
|
132
119
|
- MIT
|
120
|
+
metadata: {}
|
133
121
|
post_install_message:
|
134
122
|
rdoc_options: []
|
135
123
|
require_paths:
|
136
124
|
- lib
|
137
125
|
required_ruby_version: !ruby/object:Gem::Requirement
|
138
|
-
none: false
|
139
126
|
requirements:
|
140
|
-
- -
|
127
|
+
- - ">="
|
141
128
|
- !ruby/object:Gem::Version
|
142
129
|
version: '0'
|
143
|
-
segments:
|
144
|
-
- 0
|
145
|
-
hash: -4572774117514092169
|
146
130
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
147
|
-
none: false
|
148
131
|
requirements:
|
149
|
-
- -
|
132
|
+
- - ">="
|
150
133
|
- !ruby/object:Gem::Version
|
151
134
|
version: '0'
|
152
|
-
segments:
|
153
|
-
- 0
|
154
|
-
hash: -4572774117514092169
|
155
135
|
requirements: []
|
156
136
|
rubyforge_project:
|
157
|
-
rubygems_version:
|
137
|
+
rubygems_version: 2.2.2
|
158
138
|
signing_key:
|
159
|
-
specification_version:
|
160
|
-
summary: nagiosplugin-2.
|
139
|
+
specification_version: 4
|
140
|
+
summary: nagiosplugin-2.2.0
|
161
141
|
test_files:
|
162
142
|
- features/nagiosplugin_usage.feature
|
163
143
|
- features/support/env.rb
|