App-Icli
view release on metacpan or search on metacpan
);
( $action, @raw_args ) = split( /:/, $action );
@action_args = split( /,/, join( ':', @raw_args ) );
$list_type = q{};
if ( exists $actionmap{$action} ) {
$action = $actionmap{$action};
}
elsif ( length($action) <= 2 ) {
say STDERR "Note: Action shortcut '${action}' is unknown";
}
}
sub compute_hostlist {
for my $arg (@ARGV) {
my ( $host, $service ) = split( qr{/}, $arg );
if ( not any { $host } @for_hosts ) {
push( @for_hosts, $host );
}
$command = 'SCHEDULE_AND_PROPAGATE_HOST_DOWNTIME';
$addendum = ' and its children';
}
if ( 'trigger_children' ~~ \@opts ) {
$command = 'SCHEDULE_AND_PROPAGATE_TRIGGERED_HOST_DOWNTIME';
$addendum = ' and its children (triggered)';
}
dispatch_command( $command, $host, $dt_start->epoch, $dt_end->epoch,
$fixed, 0, $duration, 'cli', $comment );
say "Scheduled host downtime for '$host'$addendum";
}
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 ( $host, $service ) = @_;
if ( not have_service( $host, $service ) ) {
return;
}
my $dt_start = $strp->parse_datetime($start);
my $dt_end = $strp->parse_datetime($end);
my $fixed = $duration ? 0 : 1;
$duration = parse_duration($duration);
dispatch_command( 'SCHEDULE_SVC_DOWNTIME', $host, $service,
$dt_start->epoch, $dt_end->epoch,
$fixed, 0, $duration, 'cli', $comment );
say "Scheduled service downtime for '$service' on '$host'";
}
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"
}
}
}
GetOptions(
'a|action=s' => \$action,
'c|config=s' => \$config_file,
'C|no-colours' => sub { $colours = 0 },
'f|status-file=s' => \$status_file,
'F|rw-file=s' => \$rw_file,
'g|hostgroup=s' => sub { push( @for_groups, split( /,/, $_[1] ) ) },
'h|host=s' => sub { push( @for_hosts, split( /,/, $_[1] ) ) },
'l|list=s' => sub { $list_type = substr( $_[1], 0, 1 ) },
'm|match=s' => sub { $match_output = qr{$_[1]}i },
'o|overview' => \$overview,
's|service=s' => sub { push( @for_services, split( /,/, $_[1] ) ) },
'U|as-contact=s' => \$as_contact,
'v|verbose+' => \$verbosity,
'V|version' => sub { say "icli version $VERSION"; exit 0 },
'x|cut-mode=s' => sub { $cut_mode = substr( $_[1], 0, 1 ) },
'z|filter=s' => sub { push( @filters, split( /,/, $_[1] ) ) },
) or die("Please see perldoc -F $0 for help\n");
read_objects( $status_file, \$data, 'icinga status_file', '--status-file' );
read_objects( $config_file, \$config, 'icinga object_cache_file', '--config' );
enhance_status();
parse_action();
compute_hostlist();
elsif ( $list_type ~~ [qw[s h]] ) {
for my $host (@list_hosts) {
display_host( $host, ( @list_hosts > 1 ) );
}
}
elsif ( $list_type eq 'q' ) {
display_queue();
}
elsif ( $list_type eq 'd' ) {
if ( exists $data->{hostdowntimes} ) {
say "Host downtimes:";
if ( $verbosity == 1 ) {
printf( "%-25.25s %-20.20s %-20.20s\n", 'Host', 'start', 'stop' );
}
elsif ( $verbosity == 2 ) {
printf( "%-25.25s %-20.20s %-20.20s %-17.17s %s\n",
'Host', 'start', 'stop', 'duration', 'comment' );
}
foreach my $downtime ( @{ $data->{hostdowntimes} } ) {
display_downtime($downtime);
}
}
else {
say "No host downtimes";
}
if ( exists $data->{servicedowntimes} ) {
say "\nService downtimes:";
if ( $verbosity == 1 ) {
printf( "%-25.25s %-25.25s %-20.20s %-20.20s\n",
'Host', 'Service', 'start', 'stop' );
}
elsif ( $verbosity == 2 ) {
printf( "%-25.25s %-25.25s %-20.20s %-20.20s %-17.17s %s\n",
'Host', 'Service', 'start', 'stop', 'duration', 'comment' );
}
foreach my $downtime ( @{ $data->{servicedowntimes} } ) {
display_downtime($downtime);
}
}
else {
say "\nNo service downtimes";
}
}
elsif ($action) {
foreach my $host (@list_hosts) {
if ( not @list_services and not @filters ) {
action_on_host($host);
}
elsif ( not @list_services and @filters ) {
foreach my $service ( grep { filter_service($_) }
( run in 1.220 second using v1.01-cache-2.11-cpan-d7a12ab2c7f )