rnagios 0.0.4 → 0.0.5

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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/rnagios/plugin.rb +33 -7
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ccc2b6228857341c8852cbd7fae32795c2456a96
4
- data.tar.gz: 57cc3cbe0a9d47aefb9f12d614bd33db10c18d78
3
+ metadata.gz: 88ca321fd55063124516f59aae279cb493116805
4
+ data.tar.gz: e5ab19f6e4a6d7f67697b7e8601228642e356cfa
5
5
  SHA512:
6
- metadata.gz: cbbcd31d3f14a7fe2391b48c82519af9ade376dac30693b3b6dd5d9519dc5d50297c9cfd98a818069ce72acf0c75033aabdaf93e8deadb7caaddef892976e0c1
7
- data.tar.gz: 93747faba10d44d4ff00c25024e1b687bbee621568dca3ad4c245a13f8ef0948450a2125247d27b97cd7b1849efbac490b71978a49b9b277884f5606a424323c
6
+ metadata.gz: f06b79ec7a24528f5ef3ff8c756acd93c70606c74be1e9fec1307a63625a9c0b5f9dc83a78c7bf096e8772ec22ead916482186c4104317e227a20182dd1c2f5f
7
+ data.tar.gz: f3239d00aa645c363c6043ff10cefbc44fabacaf52b1424c0a9fb2a14f0726693b29c130c724821c39da49bde667b0af2f5c53f5f228039a66b4852bc2c64ce5
@@ -119,8 +119,8 @@ class Plugin
119
119
  #
120
120
  # Scripts should call this method at the very end. The general
121
121
  # flow of a script running on UNIX/Linux should be as follows:
122
- #
123
- # class MyCheck < Nagios::Plugin
122
+ #
123
+ # class MyCheck < Plugin
124
124
  # def measure
125
125
  # stat = ActiveStatus.new
126
126
  # stat.status = <...service check code goes here, returns Nagios::Status::<constant> status...>
@@ -161,7 +161,8 @@ class Plugin
161
161
  status = measure
162
162
 
163
163
  # Mark the end time for Nagios performance stats
164
- end_time = Time.now
164
+ end_time = Time.now
165
+ time_took = end_time - start_time
165
166
 
166
167
  # Since we can't effectively check for exceptions, we make
167
168
  # sure we get a good Status
@@ -173,7 +174,7 @@ class Plugin
173
174
  raise NagiosError.new('Status passive code is invalid')
174
175
  elsif status.is_a? ActiveStatus
175
176
  if status.is_a? NscaServiceStatus
176
- if !valid_passive_code? status
177
+ if !valid_passive_code? status
177
178
  raise NagiosError.new('Status passive code is invalid')
178
179
  end
179
180
  elsif !valid_exit_code? status
@@ -183,13 +184,31 @@ class Plugin
183
184
  raise NagiosError.new('Status message must not be nil or empty')
184
185
  end
185
186
 
186
- # Status checks out as valid -- we now format the output based on
187
- # the type of Status received
187
+ # Status checks out as valid -- we now check the warning and critical
188
+ # times and format the output based on the type of Status received
188
189
  if status.is_a? NscaHostStatus
189
190
  status.message = format_passive_host_check(status)
190
191
  elsif status.is_a? NscaServiceStatus
192
+ if valid_value_w && valid_value_c
193
+ if time_took >= @w && time_took < @c && status.status != ActiveStatus::WARNING
194
+ status.status = ActiveStatus::WARNING
195
+ status.message += '; check time >= ' + @w
196
+ elsif time_took >= @c && status.status != ActiveStatus::CRITICAL
197
+ status.status = ActiveStatus::CRITICAL
198
+ status.message += '; check time >= ' + @c
199
+ end
200
+ end
191
201
  status.message = format_passive_service_check(status)
192
202
  else
203
+ if valid_value_w && valid_value_c
204
+ if time_took >= @w && time_took < @c && status.status != ActiveStatus::WARNING
205
+ status.status = ActiveStatus::WARNING
206
+ status.message += '; check time >= ' + @w
207
+ elsif time_took >= @c && status.status != ActiveStatus::CRITICAL
208
+ status.status = ActiveStatus::CRITICAL
209
+ status.message += '; check time >= ' + @c
210
+ end
211
+ end
193
212
  status.message = format_active_service_check(status, start_time, end_time)
194
213
  end
195
214
 
@@ -215,7 +234,7 @@ class Plugin
215
234
  # message = 'Everything looks good'
216
235
  # elsif random_measure == 2
217
236
  # status = ActiveStatus::WARNING
218
- # message = 'Keep an eye on this service'
237
+ # message = 'Keep an eye on this service'
219
238
  # elsif random_measure == 3
220
239
  # status = ActiveStatus::CRITICAL
221
240
  # message = 'There''s a problem'
@@ -369,4 +388,11 @@ private
369
388
  end
370
389
  end
371
390
 
391
+ def valid_value_w()
392
+ @w.is_a?(Integer) && @w > 0
393
+ end
394
+
395
+ def valid_value_c()
396
+ @c.is_a?(Integer) && @c > 0
397
+ end
372
398
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rnagios
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Roger A. Rubio
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-25 00:00:00.000000000 Z
11
+ date: 2014-03-28 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Make your own plugins in Ruby for Nagios to run on the Nagios server
14
14
  or as NSCA plugins on remote servers.