nagiosharder 0.2.4 → 0.3.0

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.
@@ -39,7 +39,20 @@ Query and command a Nagios install using the power of ruby.
39
39
  # or unacknowledge
40
40
  site.unacknowledge_service('myhost', 'myservice')
41
41
 
42
- #
42
+ # disable notifications for a service:
43
+ site.disable_service_notifications('myhost', 'myservice')
44
+
45
+ # check if notifications are disabled:
46
+ site.service_notifications_disabled?('myhost', 'myservice')
47
+
48
+ # enable notifications for a service:
49
+ site.enable_service_notifications('myhost', 'myservice')
50
+
51
+ # disable notifications, and wait for nagios to process it:
52
+ site.disable_service_notifications('myhost', 'myservice')
53
+ until site.service_notifications_disabled?('myhost', 'myservice')
54
+ sleep 3
55
+ end
43
56
 
44
57
  To be continue?
45
58
 
data/Rakefile CHANGED
@@ -5,7 +5,7 @@ begin
5
5
  require 'jeweler'
6
6
  Jeweler::Tasks.new do |gem|
7
7
  gem.name = "nagiosharder"
8
- gem.version = "0.2.4"
8
+ gem.version = "0.3.0"
9
9
  gem.summary = %Q{Nagios access at your ruby fingertips}
10
10
  gem.description = %Q{Nagios access at your ruby fingertips}
11
11
  gem.email = "josh@technicalpickles.com"
@@ -21,7 +21,7 @@ require 'httparty'
21
21
 
22
22
  class NagiosHarder
23
23
  class Site
24
- attr_accessor :nagios_url, :user, :password, :default_options, :default_cookies, :version
24
+ attr_accessor :nagios_url, :user, :password, :default_options, :default_cookies, :version, :nagios_time_format
25
25
  include HTTParty::ClassMethods
26
26
 
27
27
  def initialize(nagios_url, user, password, version = 3)
@@ -32,6 +32,12 @@ class NagiosHarder
32
32
  @default_cookies = {}
33
33
  @version = version
34
34
  basic_auth(@user, @password) if @user && @password
35
+
36
+ @nagios_time_format = if @version.to_i < 3
37
+ "%m-%d-%Y %H:%M:%S"
38
+ else
39
+ "%Y-%m-%d %H:%M:%S"
40
+ end
35
41
  end
36
42
 
37
43
  def acknowledge_service(host, service, comment)
@@ -243,10 +249,55 @@ class NagiosHarder
243
249
  parse_status_html(response) do |status|
244
250
  services[status[:service]] = status
245
251
  end
246
-
252
+
247
253
  services
248
254
  end
249
255
 
256
+ def disable_service_notifications(host, service, options = {})
257
+ request = {
258
+ :cmd_mod => 2,
259
+ :cmd_typ => 23,
260
+ :host => host,
261
+ :service => service,
262
+ }
263
+
264
+ response = post(cmd_url, :body => request)
265
+ if response.code == 200 && response.body =~ /successful/
266
+ # TODO enable waiting. seems to hang intermittently
267
+ #if options[:wait]
268
+ # sleep(3) until service_notifications_disabled?(host, service)
269
+ #end
270
+ true
271
+ else
272
+ false
273
+ end
274
+ end
275
+
276
+ def enable_service_notifications(host, service, options = {})
277
+ request = {
278
+ :cmd_mod => 2,
279
+ :cmd_typ => 22,
280
+ :host => host,
281
+ :service => service,
282
+ }
283
+
284
+ response = post(cmd_url, :body => request)
285
+ if response.code == 200 && response.body =~ /successful/
286
+ # TODO enable waiting. seems to hang intermittently
287
+ #if options[:wait]
288
+ # sleep(3) while service_notifications_disabled?(host, service)
289
+ #end
290
+ true
291
+ else
292
+ false
293
+ end
294
+ end
295
+
296
+ def service_notifications_disabled?(host, service)
297
+ self.host_status(host)[service].notifications_disabled
298
+ end
299
+
300
+
250
301
  def status_url
251
302
  "#{nagios_url}/status.cgi"
252
303
  end
@@ -261,15 +312,6 @@ class NagiosHarder
261
312
 
262
313
  private
263
314
 
264
-
265
- def nagios_time_format
266
- if @version.to_i < 3
267
- "%m-%d-%Y %H:%M:%S"
268
- else
269
- "%Y-%m-%d %H:%M:%S"
270
- end
271
- end
272
-
273
315
  def formatted_time_for(time)
274
316
  time.strftime(nagios_time_format)
275
317
  end
@@ -282,7 +324,7 @@ class NagiosHarder
282
324
  rows.each do |row|
283
325
  columns = Nokogiri::HTML(row.inner_html).css('body > td').to_a
284
326
  if columns.any?
285
-
327
+
286
328
  host = columns[0].inner_text.gsub(/\n/, '')
287
329
 
288
330
  # for a given host, the host details are blank after the first row
@@ -310,6 +352,9 @@ class NagiosHarder
310
352
  acknowledged = other_links.any? do |link|
311
353
  link.css('img').attribute('src').to_s =~ /ack\.gif/
312
354
  end
355
+ notifications_disabled = other_links.any? do |link|
356
+ link.css('img').attribute('src').to_s =~ /ndisabled\.gif/
357
+ end
313
358
 
314
359
  extra_service_notes_link = other_links.detect do |link|
315
360
  link.css('img').any? do |img|
@@ -357,7 +402,8 @@ class NagiosHarder
357
402
  :service_extinfo_url => service_extinfo_url,
358
403
  :flapping => flapping,
359
404
  :comments_url => comments_url,
360
- :extra_service_notes_url => extra_service_notes_url
405
+ :extra_service_notes_url => extra_service_notes_url,
406
+ :notifications_disabled => notifications_disabled
361
407
 
362
408
  yield status
363
409
  end
@@ -366,7 +412,7 @@ class NagiosHarder
366
412
 
367
413
  nil
368
414
  end
369
-
415
+
370
416
  end
371
417
 
372
418
  end
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{nagiosharder}
8
- s.version = "0.2.4"
8
+ s.version = "0.3.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Joshua Nichols"]
12
- s.date = %q{2011-04-22}
12
+ s.date = %q{2011-05-05}
13
13
  s.description = %q{Nagios access at your ruby fingertips}
14
14
  s.email = %q{josh@technicalpickles.com}
15
15
  s.extra_rdoc_files = [
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nagiosharder
3
3
  version: !ruby/object:Gem::Version
4
- hash: 31
4
+ hash: 19
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 2
9
- - 4
10
- version: 0.2.4
8
+ - 3
9
+ - 0
10
+ version: 0.3.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Joshua Nichols
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-04-22 00:00:00 -04:00
18
+ date: 2011-05-05 00:00:00 -04:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency