nagios-manage 0.5.1 → 0.5.2

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. data/bin/check_check.rb +4 -2
  2. data/lib/nagios/status.rb +70 -1
  3. metadata +4 -4
data/bin/check_check.rb CHANGED
@@ -37,6 +37,9 @@ class Nagios::Status::Model
37
37
  hostinfo["servicestatus"].each do |name, status|
38
38
  next if service_pattern and !service_pattern.match(name)
39
39
 
40
+ # Skip myself, if we are a check running from nagios.
41
+ next if name == ENV["NAGIOS_SERVICEDESC"]
42
+
40
43
  # Skip silenced or checks in scheduled downtime.
41
44
  next if status["notifications_enabled"].to_i == 0
42
45
  next if status["scheduled_downtime_depth"].to_i > 0
@@ -58,8 +61,7 @@ class Nagios::Status::Model
58
61
 
59
62
  def hosts(pattern=nil)
60
63
  if pattern
61
- return @status.status["hosts"]
62
- #.reject { |name,hostinfo| !pattern.match(name) }
64
+ return @status.status["hosts"].reject { |name,hostinfo| !pattern.match(name) }
63
65
  else
64
66
  return @status.status["hosts"]
65
67
  end # if pattern
data/lib/nagios/status.rb CHANGED
@@ -228,14 +228,83 @@ module Nagios
228
228
 
229
229
  # Parses a servicestatus block
230
230
  def handle_contactstatus(lines)
231
+ @status['contacts'] ||= {}
232
+ contact = get_contact_name(lines)
233
+ @status['contacts'][contact] ||= {}
234
+ lines.each do |line|
235
+ match = line.match(/^\s*(.+)=(.*)$/)
236
+ @status['contacts'][contact][match[1]] = match[2] unless match[1] == 'contact_name'
237
+ end
231
238
  end
232
-
239
+
240
+ def get_contact_name(lines)
241
+ if h = lines.grep(/\s+contact_name=(\w+)/).first
242
+ if h =~ /contact_name=(.*)$/
243
+ contact_name = $1
244
+ else
245
+ raise("Can't parse contact_name in block: #{h}")
246
+ end
247
+ else
248
+ raise("Can't parse contactstatus block")
249
+ end
250
+ return contact_name
251
+ end
252
+
233
253
  # Parses a servicecomment block
234
254
  def handle_servicecomment(lines)
255
+ host = get_host_name(lines)
256
+ service = get_service_name(lines)
257
+ @status["hosts"][host]['servicecomments'] ||= {}
258
+ @status["hosts"][host]['servicecomments'][service] ||= []
259
+ comment = {}
260
+ lines.each do |line|
261
+ match = line.match(/^\s*(.+)=(.*)$/)
262
+ comment[match[1]] = match[2] unless match[1] == 'service_name'
263
+ end
264
+ @status['hosts'][host]['servicecomments'][service] << comment
235
265
  end
236
266
 
237
267
  # Parses hostcomment block
238
268
  def handle_hostcomment(lines)
269
+ host = get_host_name(lines)
270
+ @status['hosts'][host]['hostcomments'] ||= []
271
+ comment = {}
272
+ lines.each do |line|
273
+ match = line.match(/^\s*(.+)=(.*)$/)
274
+ comment[match[1]] = match[2] unless match[1] == 'host_name'
275
+ end
276
+ @status['hosts'][host]['hostcomments'] << comment
277
+ end
278
+
279
+ # Parses servicedowntime block
280
+ def handle_servicedowntime(lines)
281
+ host = get_host_name(lines)
282
+ service = get_service_name(lines)
283
+ downtime_id = get_downtime_id(lines)
284
+ @status["hosts"][host]["servicedowntime"] = {} unless @status["hosts"][host]["servicedowntime"]
285
+ @status["hosts"][host]["servicedowntime"][service] = downtime_id
286
+ end
287
+
288
+ # Parses hostdowntime block
289
+ def handle_hostdowntime(lines)
290
+ host = get_host_name(lines)
291
+ downtime_id = get_downtime_id(lines)
292
+ @status["hosts"][host]["hostdowntime"] = downtime_id
293
+ end
294
+
295
+ # Parse the downtime_id out of a block
296
+ def get_downtime_id(lines)
297
+ if h = lines.grep(/\s+downtime_id=(.*)$/).first
298
+ if h =~ /downtime_id=(.+)$/
299
+ downtime_id = $1
300
+ else
301
+ raise("Can't parse downtime_id in block: #{h}")
302
+ end
303
+ else
304
+ raise("Can't find downtime_id in block")
305
+ end
306
+
307
+ return downtime_id
239
308
  end
240
309
 
241
310
  # Parses a programstatus block
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nagios-manage
3
3
  version: !ruby/object:Gem::Version
4
- hash: 9
4
+ hash: 15
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 5
9
- - 1
10
- version: 0.5.1
9
+ - 2
10
+ version: 0.5.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - R.I. Pienaar, Jordan Sissel
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-11-30 00:00:00 -08:00
18
+ date: 2010-12-16 00:00:00 -08:00
19
19
  default_executable:
20
20
  dependencies: []
21
21