From 7f607c2c7a3f537e047f1c1cefd141fc6f5f354c Mon Sep 17 00:00:00 2001 From: Emmanuel Lacour Date: Mon, 7 Oct 2024 11:43:02 +0200 Subject: [PATCH] check_backuppc: add a check on how many time an host is in backup_in_progress state --- check_backuppc | 44 ++++++++++++++++++++++++++++++++------------ 1 file changed, 32 insertions(+), 12 deletions(-) diff --git a/check_backuppc b/check_backuppc index f09f996..146e5d1 100755 --- a/check_backuppc +++ b/check_backuppc @@ -47,6 +47,8 @@ use BackupPC::Lib; my $version = '1.1.3'; my $warnDaysOld = 2; my $critDaysOld = 7; +my $warnDaysInProgress = 0.5; +my $critDaysInProgress = 1; my $verbose = 0; my $opt_V = 0; my $opt_h = 0; @@ -68,6 +70,8 @@ $goodOpt = GetOptions( 'v+' => \$verbose, 'verbose+' => \$verbose, 'c=f' => \$critDaysOld, 'critical=f' => \$critDaysOld, 'w=f' => \$warnDaysOld, 'warning=f' => \$warnDaysOld, + 'C=f' => \$critDaysInProgress, 'critprog=f' => \$critDaysInProgress, + 'W=f' => \$warnDaysInProgress, 'warnprog=f' => \$warnDaysInProgress, 'o=s' => \@ownerOnly, 'owner=s' => \@ownerOnly, 'V' => \$opt_V, 'version' => \$opt_V, '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 " --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 " --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 " --version,-V display plugin version\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"); 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 my $server; @@ -189,19 +200,28 @@ foreach my $host (sort(keys(%Status))) $Status{$host}{statusCode} = 'WARNING' unless ( $Status{$host}{statusCode} = 'CRITICAL' ); $statusCode = 'WARNING' unless ( $statusCode eq 'CRITICAL' ); } - } elsif ( $Status{$host}{'lastGoodBackupDays'} > $critDaysOld ) - { - $Status{$host}{statusMsg} .= ", last good backup have ".sprintf("%.1f", $Status{$host}{'lastGoodBackupDays'})." days"; - $Status{$host}{statusCode} = 'CRITICAL'; - $statusCode = 'CRITICAL'; - } - elsif ( $Status{$host}{'lastGoodBackupDays'} > $warnDaysOld ) - { - $Status{$host}{statusMsg} .= ", last good backup have ".sprintf("%.1f",$Status{$host}{'lastGoodBackupDays'})." days"; - $Status{$host}{statusCode} = 'WARNING' unless ( $Status{$host}{statusCode} = 'CRITICAL' ); - $statusCode = 'WARNING' unless ( $statusCode eq 'CRITICAL' ); } else { - $Status{$host}{statusMsg} .= ", last good backup have ".sprintf("%.1f",$Status{$host}{'lastGoodBackupDays'})." days"; + 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}{statusCode} = 'CRITICAL'; + } + elsif ( $Status{$host}{'lastGoodBackupDays'} > $warnDaysOld ) { + $Status{$host}{statusMsg} .= ", last good backup have ".sprintf("%.1f",$Status{$host}{'lastGoodBackupDays'})." days"; + $Status{$host}{statusCode} = 'WARNING' unless ( $Status{$host}{statusCode} eq 'CRITICAL' ); + } else { + $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' );