check_backuppc: add a check on how many time an host is in backup_in_progress state

This commit is contained in:
Emmanuel Lacour 2024-10-07 11:43:02 +02:00 committed by Benjamin Renard
parent 7fdfa4d41e
commit 7f607c2c7a
Signed by: bn8
GPG key ID: 3E2E1CE1907115BC

View file

@ -47,6 +47,8 @@ use BackupPC::Lib;
my $version = '1.1.3'; my $version = '1.1.3';
my $warnDaysOld = 2; my $warnDaysOld = 2;
my $critDaysOld = 7; my $critDaysOld = 7;
my $warnDaysInProgress = 0.5;
my $critDaysInProgress = 1;
my $verbose = 0; my $verbose = 0;
my $opt_V = 0; my $opt_V = 0;
my $opt_h = 0; my $opt_h = 0;
@ -68,6 +70,8 @@ $goodOpt = GetOptions(
'v+' => \$verbose, 'verbose+' => \$verbose, 'v+' => \$verbose, 'verbose+' => \$verbose,
'c=f' => \$critDaysOld, 'critical=f' => \$critDaysOld, 'c=f' => \$critDaysOld, 'critical=f' => \$critDaysOld,
'w=f' => \$warnDaysOld, 'warning=f' => \$warnDaysOld, 'w=f' => \$warnDaysOld, 'warning=f' => \$warnDaysOld,
'C=f' => \$critDaysInProgress, 'critprog=f' => \$critDaysInProgress,
'W=f' => \$warnDaysInProgress, 'warnprog=f' => \$warnDaysInProgress,
'o=s' => \@ownerOnly, 'owner=s' => \@ownerOnly, 'o=s' => \@ownerOnly, 'owner=s' => \@ownerOnly,
'V' => \$opt_V, 'version' => \$opt_V, 'V' => \$opt_V, 'version' => \$opt_V,
'h' => \$opt_h, 'help' => \$opt_h, 'h' => \$opt_h, 'help' => \$opt_h,
@ -97,6 +101,8 @@ if ($opt_h or not $goodOpt)
print " --force,-f force check even if host is disabled\n"; print " --force,-f force check even if host is disabled\n";
print " --warning,-w days old of last good backup to cause a warning\n"; print " --warning,-w days old of last good backup to cause a warning\n";
print " --critical,-c days old of last good backup to be critical\n"; print " --critical,-c days old of last good backup to be critical\n";
print " --warnprog,-W duration (in days) for state backup_in_progress to cause a warning\n";
print " --critprog,-C duration (in days) for state backup_in_progress to be critical\n";
print " --verbose,-v increase verbosity\n"; print " --verbose,-v increase verbosity\n";
print " --version,-V display plugin version\n"; print " --version,-V display plugin version\n";
print " --help,-h display this message\n\n"; print " --help,-h display this message\n\n";
@ -108,6 +114,11 @@ if ($warnDaysOld > $critDaysOld)
print("BACKUPPC UNKNOWN - Warning threshold must be <= critical\n"); print("BACKUPPC UNKNOWN - Warning threshold must be <= critical\n");
exit $ERRORS{'UNKNOWN'}; exit $ERRORS{'UNKNOWN'};
} }
if ($warnDaysInProgress > $critDaysInProgress)
{
print("BACKUPPC UNKNOWN - Warning in progress threshold must be <= critical in progress\n");
exit $ERRORS{'UNKNOWN'};
}
# Connect to BackupPC # Connect to BackupPC
my $server; my $server;
@ -189,20 +200,29 @@ foreach my $host (sort(keys(%Status)))
$Status{$host}{statusCode} = 'WARNING' unless ( $Status{$host}{statusCode} = 'CRITICAL' ); $Status{$host}{statusCode} = 'WARNING' unless ( $Status{$host}{statusCode} = 'CRITICAL' );
$statusCode = 'WARNING' unless ( $statusCode eq 'CRITICAL' ); $statusCode = 'WARNING' unless ( $statusCode eq 'CRITICAL' );
} }
} elsif ( $Status{$host}{'lastGoodBackupDays'} > $critDaysOld ) } else {
{ if ($Status{$host}{state} eq 'Status_backup_in_progress') {
$Status{$host}{'startDays'} = difftime(time(), $Status{$host}{'startTime'}) / (3600 * 24);
if ( $Status{$host}{'startDays'} > $critDaysInProgress ) {
$Status{$host}{statusMsg} .= " for " . sprintf("%.1f", $Status{$host}{'startDays'} * 24) . " hours";
$Status{$host}{statusCode} = 'CRITICAL';
} elsif ( $Status{$host}{'startDays'} > $warnDaysInProgress ) {
$Status{$host}{statusMsg} .= " for " . sprintf("%.1f", $Status{$host}{'startDays'} * 24) . " hours";
$Status{$host}{statusCode} = 'WARNING' unless ( $Status{$host}{statusCode} eq 'CRITICAL' );
}
}
if ( $Status{$host}{'lastGoodBackupDays'} > $critDaysOld ) {
$Status{$host}{statusMsg} .= ", last good backup have ".sprintf("%.1f", $Status{$host}{'lastGoodBackupDays'})." days"; $Status{$host}{statusMsg} .= ", last good backup have ".sprintf("%.1f", $Status{$host}{'lastGoodBackupDays'})." days";
$Status{$host}{statusCode} = 'CRITICAL'; $Status{$host}{statusCode} = 'CRITICAL';
$statusCode = 'CRITICAL';
} }
elsif ( $Status{$host}{'lastGoodBackupDays'} > $warnDaysOld ) elsif ( $Status{$host}{'lastGoodBackupDays'} > $warnDaysOld ) {
{
$Status{$host}{statusMsg} .= ", last good backup have ".sprintf("%.1f",$Status{$host}{'lastGoodBackupDays'})." days"; $Status{$host}{statusMsg} .= ", last good backup have ".sprintf("%.1f",$Status{$host}{'lastGoodBackupDays'})." days";
$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 { } else {
$Status{$host}{statusMsg} .= ", last good backup have ".sprintf("%.1f",$Status{$host}{'lastGoodBackupDays'})." days"; $Status{$host}{statusMsg} .= ", last good backup have ".sprintf("%.1f",$Status{$host}{'lastGoodBackupDays'})." days";
} }
}
$ok_count++ if ( $Status{$host}{statusCode} eq 'OK' ); $ok_count++ if ( $Status{$host}{statusCode} eq 'OK' );
$unknown_count++ if ( $Status{$host}{statusCode} eq 'UNKNOWN' ); $unknown_count++ if ( $Status{$host}{statusCode} eq 'UNKNOWN' );
$warning_count++ if ( $Status{$host}{statusCode} eq 'WARNING' ); $warning_count++ if ( $Status{$host}{statusCode} eq 'WARNING' );