nagi 0.2.0 → 0.2.1
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 +17 -6
- data/lib/nagi/dsl.rb +8 -8
- data/lib/nagi/version.rb +1 -1
- data/spec/nagi/dsl_spec.rb +36 -0
- metadata +7 -7
data/NEWS
CHANGED
data/README.md
CHANGED
@@ -121,6 +121,10 @@ is given. It can be set to either `:severe`, in which case the most severe
|
|
121
121
|
status will be returned at the end, or `:all` which will use the most severe
|
122
122
|
status code but also combine all status messages into one.
|
123
123
|
|
124
|
+
However, one can still force a status to return from the check, and ignore
|
125
|
+
the collected statues, by setting the second parameter (`force`) to `true`
|
126
|
+
for the status methods.
|
127
|
+
|
124
128
|
This example checks used space on all disk drives, and returns critical if
|
125
129
|
any of the drives are above a threshold:
|
126
130
|
|
@@ -136,7 +140,12 @@ Nagi do
|
|
136
140
|
collect :all
|
137
141
|
|
138
142
|
check do |args|
|
139
|
-
|
143
|
+
begin
|
144
|
+
output = execute('df')
|
145
|
+
rescue StandardError => e
|
146
|
+
critical "df failed: #{e.message}", true
|
147
|
+
end
|
148
|
+
output.lines.each do |line|
|
140
149
|
if line =~ /^.*?(\d+)%\s*(.*)$/
|
141
150
|
if $1.to_i > args[:percentage].to_i
|
142
151
|
critical "#{$2} #{$1}% used"
|
@@ -193,14 +202,16 @@ parsed command-line arguments as a hash. It should use one of the methods `ok`,
|
|
193
202
|
or the block raises an unhandled exception, an Unknown status will be returned.
|
194
203
|
|
195
204
|
The `collect` setting (see above) can be used to collect statuses and continue
|
196
|
-
the check, rather than returning the first status encountered.
|
205
|
+
the check, rather than returning the first status encountered. However, if
|
206
|
+
`true` is passed as the second parameter of the status method, it will
|
207
|
+
return the status regardless of the `collect` setting.
|
197
208
|
|
198
209
|
* `check` *block*: the code block the the check. Parsed command-line arguments
|
199
210
|
are passed as a hash.
|
200
|
-
* `ok` *message*: returns an OK status.
|
201
|
-
* `warning` *message*: returns a Warning status.
|
202
|
-
* `critical` *message*: returns a Critical status.
|
203
|
-
* `unknown` *message*: returns an Unknown status.
|
211
|
+
* `ok` *message*, *force=false*: returns an OK status.
|
212
|
+
* `warning` *message*, *force=false*: returns a Warning status.
|
213
|
+
* `critical` *message*, *force=false*: returns a Critical status.
|
214
|
+
* `unknown` *message*, *force=false*: returns an Unknown status.
|
204
215
|
* `execute` *command*: executes a shell command, and returns any output (both
|
205
216
|
stdout and stderr). If the command exits with a non-zero status, it will
|
206
217
|
throw an exception. The shell is set to use the `pipefail` option, so non-zero
|
data/lib/nagi/dsl.rb
CHANGED
@@ -39,9 +39,9 @@ module Nagi
|
|
39
39
|
@collect = type
|
40
40
|
end
|
41
41
|
|
42
|
-
def critical(message)
|
42
|
+
def critical(message, force=false)
|
43
43
|
status = Nagi::Status::Critical.new(message)
|
44
|
-
throw :status, status
|
44
|
+
throw :status, status if force or not @collect
|
45
45
|
@collected.push(status)
|
46
46
|
return status
|
47
47
|
end
|
@@ -54,9 +54,9 @@ module Nagi
|
|
54
54
|
@plugin.name = name
|
55
55
|
end
|
56
56
|
|
57
|
-
def ok(message)
|
57
|
+
def ok(message, force=false)
|
58
58
|
status = Nagi::Status::OK.new(message)
|
59
|
-
throw :status, status
|
59
|
+
throw :status, status if force or not @collect
|
60
60
|
@collected.push(status)
|
61
61
|
return status
|
62
62
|
end
|
@@ -69,9 +69,9 @@ module Nagi
|
|
69
69
|
@plugin.optionparser.switch(name, *args)
|
70
70
|
end
|
71
71
|
|
72
|
-
def unknown(message)
|
72
|
+
def unknown(message, force=false)
|
73
73
|
status = Nagi::Status::Unknown.new(message)
|
74
|
-
throw :status, status
|
74
|
+
throw :status, status if force or not @collect
|
75
75
|
@collected.push(status)
|
76
76
|
return status
|
77
77
|
end
|
@@ -80,9 +80,9 @@ module Nagi
|
|
80
80
|
@plugin.version = version
|
81
81
|
end
|
82
82
|
|
83
|
-
def warning(message)
|
83
|
+
def warning(message, force=false)
|
84
84
|
status = Nagi::Status::Warning.new(message)
|
85
|
-
throw :status, status
|
85
|
+
throw :status, status if force or not @collect
|
86
86
|
@collected.push(status)
|
87
87
|
return status
|
88
88
|
end
|
data/lib/nagi/version.rb
CHANGED
data/spec/nagi/dsl_spec.rb
CHANGED
@@ -96,6 +96,7 @@ describe Nagi::DSL do
|
|
96
96
|
it 'throws :status with critical status' do
|
97
97
|
catch(:status) do
|
98
98
|
@dsl.critical('message')
|
99
|
+
nil
|
99
100
|
end.class.should eq Nagi::Status::Critical
|
100
101
|
end
|
101
102
|
|
@@ -103,6 +104,14 @@ describe Nagi::DSL do
|
|
103
104
|
@dsl.collect(:all)
|
104
105
|
@dsl.critical('message').class.should eq Nagi::Status::Critical
|
105
106
|
end
|
107
|
+
|
108
|
+
it 'throws :status when collection is enabled if forced' do
|
109
|
+
@dsl.collect(:all)
|
110
|
+
catch(:status) do
|
111
|
+
@dsl.critical('message', true)
|
112
|
+
nil
|
113
|
+
end.class.should eq Nagi::Status::Critical
|
114
|
+
end
|
106
115
|
end
|
107
116
|
|
108
117
|
describe '.execute' do
|
@@ -122,6 +131,7 @@ describe Nagi::DSL do
|
|
122
131
|
it 'throws :status with ok status' do
|
123
132
|
catch(:status) do
|
124
133
|
@dsl.ok('message')
|
134
|
+
nil
|
125
135
|
end.class.should eq Nagi::Status::OK
|
126
136
|
end
|
127
137
|
|
@@ -129,6 +139,14 @@ describe Nagi::DSL do
|
|
129
139
|
@dsl.collect(:all)
|
130
140
|
@dsl.ok('message').class.should eq Nagi::Status::OK
|
131
141
|
end
|
142
|
+
|
143
|
+
it 'throws :status when collection is enabled if forced' do
|
144
|
+
@dsl.collect(:all)
|
145
|
+
catch(:status) do
|
146
|
+
@dsl.ok('message', true)
|
147
|
+
nil
|
148
|
+
end.class.should eq Nagi::Status::OK
|
149
|
+
end
|
132
150
|
end
|
133
151
|
|
134
152
|
describe '.prefix' do
|
@@ -150,6 +168,7 @@ describe Nagi::DSL do
|
|
150
168
|
it 'throws :status with unknown status' do
|
151
169
|
catch(:status) do
|
152
170
|
@dsl.unknown('message')
|
171
|
+
nil
|
153
172
|
end.class.should eq Nagi::Status::Unknown
|
154
173
|
end
|
155
174
|
|
@@ -157,6 +176,14 @@ describe Nagi::DSL do
|
|
157
176
|
@dsl.collect(:all)
|
158
177
|
@dsl.unknown('message').class.should eq Nagi::Status::Unknown
|
159
178
|
end
|
179
|
+
|
180
|
+
it 'throws :status when collection is enabled if forced' do
|
181
|
+
@dsl.collect(:all)
|
182
|
+
catch(:status) do
|
183
|
+
@dsl.unknown('message', true)
|
184
|
+
nil
|
185
|
+
end.class.should eq Nagi::Status::Unknown
|
186
|
+
end
|
160
187
|
end
|
161
188
|
|
162
189
|
describe '.version' do
|
@@ -170,6 +197,7 @@ describe Nagi::DSL do
|
|
170
197
|
it 'throws :status with warning status' do
|
171
198
|
catch(:status) do
|
172
199
|
@dsl.warning('message')
|
200
|
+
nil
|
173
201
|
end.class.should eq Nagi::Status::Warning
|
174
202
|
end
|
175
203
|
|
@@ -177,5 +205,13 @@ describe Nagi::DSL do
|
|
177
205
|
@dsl.collect(:all)
|
178
206
|
@dsl.warning('message').class.should eq Nagi::Status::Warning
|
179
207
|
end
|
208
|
+
|
209
|
+
it 'throws :status when collection is enabled if forced' do
|
210
|
+
@dsl.collect(:all)
|
211
|
+
catch(:status) do
|
212
|
+
@dsl.warning('message', true)
|
213
|
+
nil
|
214
|
+
end.class.should eq Nagi::Status::Warning
|
215
|
+
end
|
180
216
|
end
|
181
217
|
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.1
|
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: 2012-05-31 00:00:00.
|
12
|
+
date: 2012-05-31 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
16
|
-
requirement: &
|
16
|
+
requirement: &70118921103600 !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: *70118921103600
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rspec
|
27
|
-
requirement: &
|
27
|
+
requirement: &70118921102940 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,7 +32,7 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70118921102940
|
36
36
|
description: A DSL for writing Nagios plugins
|
37
37
|
email:
|
38
38
|
- erik@bengler.no
|
@@ -79,7 +79,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
79
79
|
version: '0'
|
80
80
|
requirements: []
|
81
81
|
rubyforge_project:
|
82
|
-
rubygems_version: 1.8.
|
82
|
+
rubygems_version: 1.8.11
|
83
83
|
signing_key:
|
84
84
|
specification_version: 3
|
85
85
|
summary: A DSL for writing Nagios plugins
|