From 13b42be3e52e052b04c5b1a2a2f5110e560878d1 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Sat, 31 May 2014 21:27:55 +0200 Subject: move external command functions into action_on_host / action_on_service --- bin/icli | 75 ++++++++++++++++++++++++++-------------------------------------- 1 file changed, 30 insertions(+), 45 deletions(-) diff --git a/bin/icli b/bin/icli index 79e6ed2..cf8f93a 100755 --- a/bin/icli +++ b/bin/icli @@ -939,63 +939,48 @@ sub dispatch_command { or warn("Failed to close $rw_file: $!\n"); } -sub recheck_host_all { - my ($host) = @_; - - dispatch_command( 'SCHEDULE_HOST_SVC_CHECKS', $host, time() ); - say "Scheduled check of * on '$host'"; -} - -sub recheck_service { - my ( $host, $service ) = @_; - - dispatch_command( 'SCHEDULE_SVC_CHECK', $host, $service, time() ); - say "Scheduled check of '$service' on '$host'"; -} - -sub force_recheck_host_all { - my ($host) = @_; - - dispatch_command( 'SCHEDULE_FORCED_HOST_SVC_CHECKS', $host, time() ); - say "Scheduled forced check of * on '$host'"; -} - -sub force_recheck_service { - my ( $host, $service ) = @_; - - dispatch_command( 'SCHEDULE_FORCED_SVC_CHECK', $host, $service, time() ); - say "Scheduled forced check of '$service' on '$host'"; -} - -sub acknowledge_service { - my ( $host, $service ) = @_; - - dispatch_command( 'ACKNOWLEDGE_SVC_PROBLEM', $host, $service, 2, 1, 1, - 'cli', $action_args[0] ); - say "Acknowledged $host/$service: $action_args[0]"; -} - sub action_on_host { - my ($h) = @_; + my ($host) = @_; given ($action) { - when ('recheck') { recheck_host_all($h) } - when ('force_recheck') { force_recheck_host_all($h) } - default { say STDERR "Cannot run action '${action}' on a host" } + when ('recheck') { + dispatch_command( 'SCHEDULE_HOST_SVC_CHECKS', $host, time() ); + say "Scheduled check of * on '$host'"; + } + when ('force_recheck') { + dispatch_command( 'SCHEDULE_FORCED_HOST_SVC_CHECKS', $host, time() ); + say "Scheduled forced check of * on '$host'"; + } + default { + say STDERR "Cannot run action '${action}' on a host" + } } } sub action_on_service { - my ( $h, $s ) = @_; + my ( $host, $service ) = @_; - if ( not have_service( $h, $s ) ) { + if ( not have_service( $host, $service ) ) { return; } given ($action) { - when ('recheck') { recheck_service( $h, $s ) } - when ('force_recheck') { force_recheck_service( $h, $s ) } - when ('acknowledge') { acknowledge_service( $h, $s ) } + when ('recheck') { + dispatch_command( 'SCHEDULE_SVC_CHECK', $host, $service, time() ); + say "Scheduled check of '$service' on '$host'"; + } + when ('force_recheck') { + dispatch_command( 'SCHEDULE_FORCED_SVC_CHECK', $host, $service, time() ); + say "Scheduled forced check of '$service' on '$host'"; + } + when ('Acknowledge') { + dispatch_command( 'ACKNOWLEDGE_SVC_PROBLEM', $host, $service, 2, 1, 1, + 'cli', $action_args[0] ); + say "Acknowledged $host/$service: $action_args[0]"; + } + default { + say STDERR "Cannot run action '${action}' on a service" + } } } -- cgit v1.2.3