Class: NagiosHarder::Cli
- Inherits:
-
Object
- Object
- NagiosHarder::Cli
- Defined in:
- lib/nagiosharder/cli.rb
Instance Attribute Summary collapse
-
#command ⇒ Object
readonly
Returns the value of attribute command.
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#param ⇒ Object
readonly
Returns the value of attribute param.
-
#service ⇒ Object
readonly
Returns the value of attribute service.
-
#the_rest ⇒ Object
readonly
Returns the value of attribute the_rest.
Instance Method Summary collapse
-
#initialize(argv) ⇒ Cli
constructor
A new instance of Cli.
- #run ⇒ Object
Constructor Details
#initialize(argv) ⇒ Cli
10 11 12 13 14 15 |
# File 'lib/nagiosharder/cli.rb', line 10 def initialize(argv) = (argv) @command, @param = argv @host, @service = param.split("/") if param @the_rest = argv[2..-1] end |
Instance Attribute Details
#command ⇒ Object (readonly)
Returns the value of attribute command.
8 9 10 |
# File 'lib/nagiosharder/cli.rb', line 8 def command @command end |
#host ⇒ Object (readonly)
Returns the value of attribute host.
8 9 10 |
# File 'lib/nagiosharder/cli.rb', line 8 def host @host end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
8 9 10 |
# File 'lib/nagiosharder/cli.rb', line 8 def end |
#param ⇒ Object (readonly)
Returns the value of attribute param.
8 9 10 |
# File 'lib/nagiosharder/cli.rb', line 8 def param @param end |
#service ⇒ Object (readonly)
Returns the value of attribute service.
8 9 10 |
# File 'lib/nagiosharder/cli.rb', line 8 def service @service end |
#the_rest ⇒ Object (readonly)
Returns the value of attribute the_rest.
8 9 10 |
# File 'lib/nagiosharder/cli.rb', line 8 def the_rest @the_rest end |
Instance Method Details
#run ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/nagiosharder/cli.rb', line 17 def run return_value = case command when 'status' service_table do client.host_status(host).select do |name, s| service.nil? || service == name end.map { |name, s| s } end true when /^ack/ client.acknowledge_service(host, service, the_rest.join(' ')) when /^unack/ client.unacknowledge_service(host, service) when /^(mute|disable_notifications)$/ client.disable_service_notifications(host, service) when /^(unmute|enable_notifications)$/ client.enable_service_notifications(host, service) when 'check' if service 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) else client.schedule_host_downtime(host, :type => :fixed, :start_time => Time.now, :end_time => Time.now + the_rest.first.to_i.minutes) end when 'problems' service_table do if param client.service_status(:all_problems, :group => param) else client.service_status(:all_problems) end end true when /^(triage|unhandled)/ service_table do if param client.service_status(:all_problems, :group => param, :hoststatustypes => 3, :serviceprops => 42, :servicestatustypes => 28) else client.service_status(:all_problems, :hoststatustypes => 3, :serviceprops => 42, :servicestatustypes => 28) end end true else raise ArgumentError, help end if return_value 0 else puts "Sorry, bro, nagios didn't like that." 1 end end |