nagi 0.2.2 → 0.2.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/NEWS +3 -0
- data/README.md +3 -0
- data/lib/nagi/dsl.rb +10 -0
- data/lib/nagi/plugin.rb +3 -3
- data/lib/nagi/version.rb +1 -1
- data/spec/nagi/dsl_spec.rb +12 -0
- data/spec/nagi/plugin_spec.rb +34 -0
- metadata +23 -7
data/NEWS
CHANGED
data/README.md
CHANGED
@@ -181,6 +181,9 @@ These describe the program, and are usually given first, if necessary.
|
|
181
181
|
returning. *type* can be either `:severe` or `:all` - `:severe` will
|
182
182
|
return the last, most severe status, and `:all` will use the most severe
|
183
183
|
status but join all the status messages together into one.
|
184
|
+
* `fallback` *status*, *message*: a default status to return if the check
|
185
|
+
doesn't explicitly return one. *status* can be `:ok`, `:warning`, `:critical`,
|
186
|
+
or `:unknown`.
|
184
187
|
|
185
188
|
### Command-line arguments
|
186
189
|
|
data/lib/nagi/dsl.rb
CHANGED
@@ -50,6 +50,16 @@ module Nagi
|
|
50
50
|
return Nagi::Utility.execute(command)
|
51
51
|
end
|
52
52
|
|
53
|
+
def fallback(status, message)
|
54
|
+
@plugin.fallback = case status
|
55
|
+
when :ok then Nagi::Status::OK.new(message)
|
56
|
+
when :warning then Nagi::Status::Warning.new(message)
|
57
|
+
when :critical then Nagi::Status::Critical.new(message)
|
58
|
+
when :unknown then Nagi::Status::Unknown.new(message)
|
59
|
+
else raise "Unknown fallback status #{status}"
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
53
63
|
def name(name)
|
54
64
|
@plugin.name = name
|
55
65
|
end
|
data/lib/nagi/plugin.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
module Nagi
|
2
2
|
class Plugin
|
3
|
-
attr_accessor :name, :optionparser, :prefix, :version
|
3
|
+
attr_accessor :fallback, :name, :optionparser, :prefix, :version
|
4
4
|
|
5
5
|
def initialize
|
6
6
|
@optionparser = Nagi::OptionParser.new
|
@@ -22,8 +22,8 @@ module Nagi
|
|
22
22
|
rescue StandardError => e
|
23
23
|
status = Nagi::Status::Unknown.new(e.message)
|
24
24
|
end
|
25
|
-
|
26
|
-
|
25
|
+
unless status.is_a?Nagi::Status::Status
|
26
|
+
status = @fallback || Nagi::Status::Unknown.new('Check did not provide a status')
|
27
27
|
end
|
28
28
|
return status
|
29
29
|
end
|
data/lib/nagi/version.rb
CHANGED
data/spec/nagi/dsl_spec.rb
CHANGED
@@ -120,6 +120,18 @@ describe Nagi::DSL do
|
|
120
120
|
end
|
121
121
|
end
|
122
122
|
|
123
|
+
describe '.fallback' do
|
124
|
+
it 'sets plugin fallback' do
|
125
|
+
@dsl.fallback(:ok, 'Fallback')
|
126
|
+
@dsl.plugin.fallback.class.should eq Nagi::Status::OK
|
127
|
+
@dsl.plugin.fallback.message.should eq 'Fallback'
|
128
|
+
end
|
129
|
+
|
130
|
+
it 'raises exception on unknown status' do
|
131
|
+
lambda{ @dsl.fallback(:invalid, 'Invalid') }.should raise_error
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
123
135
|
describe '.name' do
|
124
136
|
it 'sets plugin name' do
|
125
137
|
@dsl.name('name')
|
data/spec/nagi/plugin_spec.rb
CHANGED
@@ -5,6 +5,13 @@ describe Nagi::Plugin do
|
|
5
5
|
@plugin = Nagi::Plugin.new
|
6
6
|
end
|
7
7
|
|
8
|
+
describe '#fallback' do
|
9
|
+
it 'sets fallback' do
|
10
|
+
@plugin.fallback = 'test'
|
11
|
+
@plugin.fallback.should eq 'test'
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
8
15
|
describe '#optionparser' do
|
9
16
|
it 'contains OptionParser' do
|
10
17
|
@plugin.optionparser.class.should eq Nagi::OptionParser
|
@@ -70,6 +77,25 @@ describe Nagi::Plugin do
|
|
70
77
|
@plugin.run([]).class.should eq Nagi::Status::OK
|
71
78
|
end
|
72
79
|
|
80
|
+
it 'returns check status even when fallback is set' do
|
81
|
+
@plugin.fallback = Nagi::Status::Unknown.new('Fallback')
|
82
|
+
class << @plugin
|
83
|
+
def check(options)
|
84
|
+
return Nagi::Status::OK.new('ok')
|
85
|
+
end
|
86
|
+
end
|
87
|
+
@plugin.run([]).class.should eq Nagi::Status::OK
|
88
|
+
end
|
89
|
+
|
90
|
+
it 'returns fallback status if set and no other status' do
|
91
|
+
@plugin.fallback = Nagi::Status::OK.new('Fallback')
|
92
|
+
class << @plugin
|
93
|
+
def check(options)
|
94
|
+
end
|
95
|
+
end
|
96
|
+
@plugin.run([]).should eq @plugin.fallback
|
97
|
+
end
|
98
|
+
|
73
99
|
it 'returns unknown status on check exception' do
|
74
100
|
class << @plugin
|
75
101
|
def check(options)
|
@@ -79,6 +105,14 @@ describe Nagi::Plugin do
|
|
79
105
|
@plugin.run([]).class.should eq Nagi::Status::Unknown
|
80
106
|
end
|
81
107
|
|
108
|
+
it 'returns unknown status if no status' do
|
109
|
+
class << @plugin
|
110
|
+
def check(options)
|
111
|
+
end
|
112
|
+
end
|
113
|
+
@plugin.run([]).class.should eq Nagi::Status::Unknown
|
114
|
+
end
|
115
|
+
|
82
116
|
it 'doesnt catch errors from optionparser' do
|
83
117
|
lambda { @plugin.run(['--invalid']) }.should raise_error ArgumentError
|
84
118
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nagi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.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:
|
12
|
+
date: 2013-02-19 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
16
|
-
requirement:
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,15 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements:
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
25
30
|
- !ruby/object:Gem::Dependency
|
26
31
|
name: rspec
|
27
|
-
requirement:
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
28
33
|
none: false
|
29
34
|
requirements:
|
30
35
|
- - ! '>='
|
@@ -32,7 +37,12 @@ dependencies:
|
|
32
37
|
version: '0'
|
33
38
|
type: :development
|
34
39
|
prerelease: false
|
35
|
-
version_requirements:
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
36
46
|
description: A DSL for writing Nagios plugins
|
37
47
|
email:
|
38
48
|
- erik@bengler.no
|
@@ -71,15 +81,21 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
71
81
|
- - ! '>='
|
72
82
|
- !ruby/object:Gem::Version
|
73
83
|
version: '0'
|
84
|
+
segments:
|
85
|
+
- 0
|
86
|
+
hash: -1119432202314492190
|
74
87
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
75
88
|
none: false
|
76
89
|
requirements:
|
77
90
|
- - ! '>='
|
78
91
|
- !ruby/object:Gem::Version
|
79
92
|
version: '0'
|
93
|
+
segments:
|
94
|
+
- 0
|
95
|
+
hash: -1119432202314492190
|
80
96
|
requirements: []
|
81
97
|
rubyforge_project:
|
82
|
-
rubygems_version: 1.8.
|
98
|
+
rubygems_version: 1.8.24
|
83
99
|
signing_key:
|
84
100
|
specification_version: 3
|
85
101
|
summary: A DSL for writing Nagios plugins
|