lib/nagiosharder/cli.rb in nagiosharder-0.5.0.rc1 vs lib/nagiosharder/cli.rb in nagiosharder-0.5.0
- old
+ new
@@ -15,14 +15,28 @@
end
def run
return_value = case command
when 'status'
+ status_checks = []
+ hostnames_and_check_names = [param,*the_rest].compact
+
+ # for each hostname or checkname we got
+ hostnames_and_check_names.each do |check|
+ host,service = check.split("/")
+ check_info = client.host_status(host)
+
+ # If we were asked about a specific service, get rid of the ones
+ # that they didn't ask for
+ check_info.reject! { |name,s| service and service != name }
+
+ # accumulate our results
+ status_checks += check_info.map { |name,service| service }
+ end
+
service_table do
- client.host_status(host).select do |name, s|
- service.nil? || service == name
- end.map { |name, s| s }
+ status_checks
end
true
when /^(ack|acknowledged)$/
if service.nil?
client.acknowledge_host(host, the_rest.join(' '))
@@ -40,14 +54,19 @@
client.schedule_service_check(host, service)
else
client.schedule_host_check(host)
end
when 'downtime'
- if service
- client.schedule_service_downtime(host, service, :type => :fixed, :start_time => Time.now, :end_time => Time.now + the_rest.first.to_i.minutes)
+ if the_rest == []
+ puts "Downtime requires duration in minutes."
+ false
else
- client.schedule_host_downtime(host, :type => :fixed, :start_time => Time.now, :end_time => Time.now + the_rest.first.to_i.minutes)
+ if service
+ client.schedule_service_downtime(host, service, :type => :fixed, :start_time => Time.now, :end_time => Time.now + the_rest.first.to_i.minutes)
+ else
+ client.schedule_host_downtime(host, :type => :fixed, :start_time => Time.now, :end_time => Time.now + the_rest.first.to_i.minutes)
+ end
end
when 'problems'
service_table do
params = {
:service_status_types => [:critical, :warning, :unknown],
@@ -94,10 +113,20 @@
}
params[:group] = param
client.service_status(params)
end
true
+ when /^servicegroups/
+ groups_table do
+ client.servicegroups_summary()
+ end
+ true
+ when /^hostgroups/
+ groups_table do
+ client.hostgroups_summary()
+ end
+ true
when /^muted/
service_table do
params = {
:service_props => [
:notifications_disabled,
@@ -105,10 +134,21 @@
}
params[:group] = param
client.service_status(params)
end
true
+ when /^scheduled_downtime/
+ service_table do
+ params = {
+ :service_props => [
+ :scheduled_downtime,
+ ]
+ }
+ params[:group] = param
+ client.service_status(params)
+ end
+ true
when /^(acked|acknowledged)/
service_table do
params = {
:service_status_types => [
:critical,
@@ -128,11 +168,11 @@
raise ArgumentError, help
end
if return_value
0
else
- puts "Sorry, bro, nagios didn't like that."
+ puts "Sorry yo, nagios didn't like that."
1
end
end
protected
@@ -191,10 +231,34 @@
end
options
end
+ def groups_table
+ table = Terminal::Table.new(:headings => ['Group', 'Host Up', 'Host Down', 'Service Ok', 'Service Warning', 'Service Critical', 'Service Unknown']) do |t|
+ groups = yield
+ groups.each do |name, group|
+ t << group_row(group)
+ end
+ t
+ end
+ table.align_column(1, :right)
+ puts table
+ end
+
+ def group_row(group)
+ [
+ group['group'],
+ group['host_status_counts']['up'],
+ group['host_status_counts']['down'],
+ group['service_status_counts']['ok'],
+ group['service_status_counts']['warning'],
+ group['service_status_counts']['critical'],
+ group['service_status_counts']['unknown']
+ ]
+ end
+
def service_table
table = Terminal::Table.new(:headings => ['Service', 'Status', 'Details']) do |t|
services = yield
services.each do |service|
t << service_row(service)
@@ -206,10 +270,11 @@
end
def service_row(service)
service['status'] << "/ACK" if service['acknowledged']
service['status'] << "/MUTE" if service['notifications_disabled']
+ service['status'] << "/DOWNTIME" if service['downtime']
service['status'] << "/COMMENT" if service['comments_url']
[
service['host']+"/"+service["service"],
service['status'],
wrap_text(service['extended_info'], 40)
@@ -273,9 +338,12 @@
nagiosharder muted http-services
nagiosharder triage
nagiosharder unhandled
nagiosharder unhandled http-services
+
+ nagiosharder hostgroups
+ nagiosharder servicegroups
HELP
end
end
end