check_backuppc: critical output if no host was checked
This commit is contained in:
parent
7f607c2c7a
commit
6c048b83b7
1 changed files with 32 additions and 12 deletions
|
@ -182,7 +182,10 @@ foreach my $host (sort(keys(%Status)))
|
|||
# Check host error
|
||||
if ($Status{$host}{'error'})
|
||||
{
|
||||
$Status{$host}{statusMsg} = "error: ".$Status{$host}{'error'}." / ".$Status{$host}{'reason'};
|
||||
$Status{$host}{statusCode} = 'CRITICAL';
|
||||
$Status{$host}{statusMsg} = "error: " .$Status{$host}{'error'} . " /"
|
||||
. ( $Status{$host}{reason} ne '' ? " reason: " . $Status{$host}{reason} . "/" : '' )
|
||||
. " status: " . $Status{$host}{'state'};
|
||||
} else {
|
||||
$Status{$host}{statusMsg} = "status: ".$Status{$host}{'state'};
|
||||
}
|
||||
|
@ -194,10 +197,9 @@ foreach my $host (sort(keys(%Status)))
|
|||
if ( $Status{$host}{'startDays'} > $critDaysOld ) {
|
||||
$Status{$host}{statusMsg} .= ", no backups";
|
||||
$Status{$host}{statusCode} = 'CRITICAL';
|
||||
$statusCode = 'CRITICAL';
|
||||
} elsif ( $Status{$host}{'startDays'} > $warnDaysOld ) {
|
||||
$Status{$host}{statusMsg} .= ", no backups";
|
||||
$Status{$host}{statusCode} = 'WARNING' unless ( $Status{$host}{statusCode} = 'CRITICAL' );
|
||||
$Status{$host}{statusCode} = 'WARNING' unless ( $Status{$host}{statusCode} eq 'CRITICAL' );
|
||||
$statusCode = 'WARNING' unless ( $statusCode eq 'CRITICAL' );
|
||||
}
|
||||
} else {
|
||||
|
@ -223,6 +225,7 @@ foreach my $host (sort(keys(%Status)))
|
|||
$Status{$host}{statusMsg} .= ", last good backup have ".sprintf("%.1f",$Status{$host}{'lastGoodBackupDays'})." days";
|
||||
}
|
||||
}
|
||||
|
||||
$ok_count++ if ( $Status{$host}{statusCode} eq 'OK' );
|
||||
$unknown_count++ if ( $Status{$host}{statusCode} eq 'UNKNOWN' );
|
||||
$warning_count++ if ( $Status{$host}{statusCode} eq 'WARNING' );
|
||||
|
@ -230,6 +233,19 @@ foreach my $host (sort(keys(%Status)))
|
|||
}
|
||||
|
||||
|
||||
# Ensure we checked at least one host
|
||||
if ( $hostCount == 0 || !scalar(keys %Status) ) {
|
||||
$statusCode = 'CRITICAL';
|
||||
} elsif ( grep { $Status{$_}{statusCode} eq 'CRITICAL' } keys %Status ) {
|
||||
$statusCode = 'CRITICAL';
|
||||
} elsif ( grep { $Status{$_}{statusCode} eq 'WARNING' } keys %Status ) {
|
||||
$statusCode = 'WARNING';
|
||||
} elsif ( grep { $Status{$_}{statusCode} eq 'UNKNOWN' } keys %Status ) {
|
||||
$statusCode = 'UNKNOWN';
|
||||
} else {
|
||||
$statusCode = 'OK';
|
||||
}
|
||||
|
||||
my $statusMsg = "BACKUPPC $statusCode";
|
||||
|
||||
if ( $statusCode eq 'OK' ) {
|
||||
|
@ -242,6 +258,9 @@ if ( $statusCode eq 'OK' ) {
|
|||
if ( $verbose ) {
|
||||
$statusMsg .= " (";
|
||||
my $first_host = 1;
|
||||
if ($hostCount == 0 || !scalar(keys %Status)) {
|
||||
$statusMsg .= "no host checked";
|
||||
} else {
|
||||
foreach my $host ( keys %Status ) {
|
||||
next if (@hostsDesired and not grep {/^$host$/} @hostsDesired);
|
||||
next if (@hostsExcluded and grep {/^$host$/} @hostsExcluded);
|
||||
|
@ -253,6 +272,7 @@ if ( $statusCode eq 'OK' ) {
|
|||
$first_host = 0 if ( $first_host );
|
||||
}
|
||||
}
|
||||
}
|
||||
$statusMsg .= ")";
|
||||
} else {
|
||||
$statusMsg .= " ( $ok_count OK, $unknown_count UNKNOWN, $warning_count WARNING, $critical_count CRITICAL)";
|
||||
|
|
Loading…
Reference in a new issue