App-Icli
view release on metacpan or search on metacpan
my $digit = $h->{current_state};
if ( not $checked ) {
return ' PENDING ';
}
given ($digit) {
when (0) { return with_colour( ' OK ', 'black on_green' ) }
when (1) { return with_colour( ' DOWN ', 'white on_red' ) }
when (2) { return with_colour( 'UNREACHABLE', 'white on_blue' ) }
default { croak("Unknown host state: $digit\n") }
}
}
sub display_queue {
my @queue = map { $_->[0] }
sort { $a->[1] <=> $b->[1] }
map { [ $_, $_->{next_check} ] } (
values %{ $data->{hosts} },
map { @{$_} } values %{ $data->{services} }
);
@queue = grep { $_->{host_name} ~~ \@list_hosts } @queue;
if (@list_services) {
@queue = grep { $_->{service_description} ~~ \@list_services } @queue;
}
printf( "%-25.25s %-20.20s %-19s %-19s\n",
'Host', 'Service', 'Last Check', 'Next Check', );
for my $e (@queue) {
if ( $e->{next_check} == 0 ) {
next;
}
printf(
"%-25.25s %-20.20s %-19s %-19s\n",
$e->{host_name},
$e->{service_description} // q{},
pretty_date( $e->{last_check} ),
pretty_date( $e->{next_check} ),
);
}
}
sub display_downtime {
my ($d) = @_;
my $v = $verbosity;
my $format = "%-10s : %s\n";
if ( $v > 2 ) {
printf( $format, 'Host', $d->{host_name} );
if ( $d->{service_description} ) {
printf( $format, 'Service', $d->{service_description} );
}
printf( $format,
'Start',
$d->{is_in_effect}
? with_colour( pretty_date( $d->{start_time} ), 'bold' )
: pretty_date( $d->{start_time} ) );
printf( $format,
'End',
$d->{is_in_effect}
? with_colour( pretty_date( $d->{end_time} ), 'bold' )
: pretty_date( $d->{end_time} ) );
printf( $format,
'Duration',
$d->{fixed} ? 'Fixed' : pretty_duration_abs( $d->{duration} ) );
if ( $v > 3 ) {
printf( $format, 'ID', $d->{downtime_id} );
if ( $d->{trigger_time} ) {
printf( $format,
'Trigger',
$d->{triggered_by}
. ' (active since '
. pretty_date( $d->{trigger_time} )
. ')' );
}
else {
printf( $format, 'Trigger', $d->{triggered_by} || 'None' );
}
}
printf( $format, 'Author', $d->{author} );
printf( $format, 'Comment', break_str( $d->{comment}, 19 ) );
}
else {
if ( $d->{service_description} ) {
printf( '%-25.25s %-25.25s',
$d->{'host_name'}, $d->{service_description} );
}
else {
printf( '%-25.25s', $d->{'host_name'} );
}
if ( $v >= 3 ) {
printf( ' %s %-10.10s',
pretty_date( $d->{'entry_time'} ),
$d->{'author'}, );
}
if ( $d->{is_in_effect} ) {
printf( ' %-28s %-28s',
with_colour( pretty_date( $d->{'start_time'} ), 'bold' ),
with_colour( pretty_date( $d->{'end_time'} ), 'bold' ),
);
}
else {
printf(
' %-20.20s %-20.20s',
pretty_date( $d->{'start_time'} ),
pretty_date( $d->{'end_time'} ),
);
}
if ( $v >= 2 ) {
printf( '%-17.17s',
$d->{'fixed'}
? ' Fixed'
: ' ' . pretty_duration_abs( $d->{duration} ) );
}
if ( $v >= 2 ) {
print( $d->{comment} );
}
}
print "\n";
}
sub display_x_verbose {
my ( $x, $format ) = @_;
my $v = $verbosity;
if ( $v > 2 ) {
printf( $format, 'Host', $x->{'host_name'}, );
if ( $x->{'service_description'} ) {
printf( $format, 'Service', $x->{'service_description'}, );
printf(
"%-16s : %s (for %s)%s\n",
'Status',
service_state($x),
pretty_duration( $x->{'last_state_change'} ),
(
$x->{'problem_has_been_acknowledged'}
? ' (Acknowledged)'
: q{}
),
);
}
else {
printf(
"%-16s : %s (for %s)%s\n",
'Status',
host_state($x),
pretty_duration( $x->{'last_state_change'} ),
(
$x->{'problem_has_been_acknowledged'}
? ' (Acknowledged)'
: q{}
),
);
}
printf( $format,
'Plugin Output',
break_str( $x->{'plugin_output'}, 19 ),
'Notifications', pretty_yesno( $x->{'notifications_enabled'} ),
);
printf( $format,
'Event Handler',
pretty_yesno( $x->{'event_handler_enabled'} ),
);
printf( $format,
'Flap Detection',
pretty_yesno( $x->{'flap_detection_enabled'} ),
);
for my $c ( @{ $x->{comments} // [] } ) {
printf( $format, 'Comment', break_str( $c->{comment_data}, 19 ) );
}
}
}
sub display_service {
my ( $s, $tab ) = @_;
my $v = $verbosity;
my $flags = q{};
my $format = "%-16s : %s\n";
my $n_width;
if ( $v < 3 ) {
$n_width = 20 + 8 + 2;
if ($tab) {
$n_width += 8;
}
printf( '%-20.20s', $s->{service_description} );
if ( $v >= 2 ) {
$n_width += 5;
if ( $s->{'problem_has_been_acknowledged'} ) {
$flags .= 'A';
}
if ( $s->{'is_flapping'} ) {
$flags .= 'F';
}
if ( $s->{'notifications_enabled'} == 0 ) {
$flags .= 'N';
}
if ( $s->{'active_checks_enabled'} == 0
and $s->{'passive_checks_enabled'} == 1 )
{
$flags .= 'P';
}
if (
not( $s->{'active_checks_enabled'}
or $s->{'passive_checks_enabled'} )
)
{
$flags .= '!';
}
$flags = sprintf( ' %-3s', $flags );
print with_colour( $flags, 'bold' );
}
printf( ' %s', service_state($s) );
if ( $v >= 2 ) {
printf( ' %d/%d', $s->{'current_attempt'}, $s->{'max_attempts'} );
$n_width += 4;
}
print ' ';
print break_str( $s->{plugin_output}, $n_width );
}
else {
display_x_verbose( $s, $format );
}
print "\n";
}
sub display_host_services {
my ( $host, $all ) = @_;
my @services;
my $h = $data->{hosts}->{$host};
@services = grep { filter_service($_) } @{ $data->{'services'}->{$host} };
if ( $all and @services and $verbosity < 3 ) {
print "\n$host";
if ( $h->{'current_state'} ) {
print q{ };
}
if ( $h->{'current_state'} == 1 ) {
print with_colour( 'DOWN', 'white on_red' );
}
elsif ( $h->{'current_state'} == 2 ) {
print with_colour( 'UNREACHABLE', 'white on_blue' );
}
print "\n";
}
foreach my $service (@services) {
if ( $all and $verbosity < 3 ) {
print "\t";
}
elsif ($all) {
print "\n";
}
display_service( $service, $all );
}
}
sub display_host_single {
my ($host) = @_;
( run in 1.207 second using v1.01-cache-2.11-cpan-cdf2f3d4e48 )