Permalink
Browse files

Make schedule_downtime more flexible.

  • Loading branch information...
1 parent f178b1c commit e2a904e5787cc1b7cea93d1cfa942017d2628ce2 @technicalpickles technicalpickles committed Jan 16, 2011
Showing with 35 additions and 14 deletions.
  1. +8 −1 README.rdoc
  2. +27 −13 lib/nagiosharder.rb
View
@@ -6,10 +6,17 @@ Scrape and meander Nagios installs from ruby.
site = NagiosHarder::Site.new('http://path/to/nagios/cgi/directory', 'user', 'password', 'version')
# version defaults to 3
+ # get details back about a host's services
puts site.host_status('myhost')
+
+ # schedule a host to have services checks run again right now
site.schedule_service_check('myhost')
- site.schedule_downtime('myhost') # schedules 2 hours of downtime
+ # schedule 20 minutes of downtime, starting now
+ site.schedule_downtime('myhost', :start_time => Time.now, :end_time => Time.now + 20.minutes)
+
+ # schedule a flexible 20 minutes of downtime between now and 2 hours from now
+ site.schedule_downtime('myhost', :type => :flexible, :start_time => Time.now, :end_time => Time.now + 2.hours, :hours => 0, :minutes => 20)
To be continue?
View
@@ -33,21 +33,35 @@ def cmd_url
"#{nagios_url}/cmd.cgi"
end
- def schedule_downtime(host)
+ def schedule_downtime(host, options = {})
request = {
- :cmd_typ => 55,
- :cmd_mod => 2,
- :host => host, # host name
- :com_author => 'nagiosharder', # author
- :com_data => 'maintenance', # comment
- :trigger => '0', # n/a
- :start_time => formatted_time_for(Time.now),
- :end_time => formatted_time_for(Time.now + 7200),
- :fixed => '1', # 1 for true or 0 for false
- :hours => '2', # if flexible
- :minutes => '0' # if flexible
- }
+ :cmd_mod => 2,
+ :cmd_typ => 55,
+ :com_author => options[:author] || "#{@user} via nagiosharder",
+ :com_data => options[:comment] || 'scheduled downtime by nagiosharder',
+ :host => host,
+ :childoptions => 0,
+ :trigger => 0
+ }
+
+ # FIXME we could use some option checking...
+
+ request[:type] = case options[:type].to_sym
+ when :fixed then 1
+ when :flexible then 0
+ else 1 # default to fixed
+ end
+
+ if request[:type] == 0
+ request[:hours] = options[:hours]
+ request[:minutes] = options[:minutes]
+ end
+
+ request[:start_time] = formatted_time_for(options[:start_time])
+ request[:end_time] = formatted_time_for(options[:end_time])
+
response = post(cmd_url, :body => request)
+
response.code == 200 && response.body =~ /successful/
end

0 comments on commit e2a904e

Please sign in to comment.