Compare commits
6 commits
80aa2de86e
...
76a91c37e5
Author | SHA1 | Date | |
---|---|---|---|
|
76a91c37e5 | ||
|
ad909157e9 | ||
|
bb7b6969f7 | ||
|
e0714b51dc | ||
|
969b0ca1e3 | ||
|
a97930fdca |
2 changed files with 223 additions and 176 deletions
|
@ -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;
|
||||||
|
@ -56,7 +58,7 @@ my @hostsDesired;
|
||||||
my @hostsExcluded;
|
my @hostsExcluded;
|
||||||
my $forceCheckOnDisabledHosts;
|
my $forceCheckOnDisabledHosts;
|
||||||
my %Status;
|
my %Status;
|
||||||
my $statusCode = 'OK';
|
my $statusCode = 'UNKNOWN';
|
||||||
my $ok_count = 0;
|
my $ok_count = 0;
|
||||||
my $unknown_count = 0;
|
my $unknown_count = 0;
|
||||||
my $warning_count = 0;
|
my $warning_count = 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,
|
||||||
|
@ -78,6 +82,9 @@ $goodOpt = GetOptions(
|
||||||
@hostsDesired = () if $#hostsDesired < 0;
|
@hostsDesired = () if $#hostsDesired < 0;
|
||||||
@hostsExcluded = () if $#hostsExcluded < 0;
|
@hostsExcluded = () if $#hostsExcluded < 0;
|
||||||
|
|
||||||
|
# Always check disabled host if a named host is provided (when backup is trigerred by cron)
|
||||||
|
$forceCheckOnDisabledHosts = 1 if ( @hostsDesired && scalar(@hostsDesired) );
|
||||||
|
|
||||||
if ($opt_V)
|
if ($opt_V)
|
||||||
{
|
{
|
||||||
print "check_backuppc - " . $version . "\n";
|
print "check_backuppc - " . $version . "\n";
|
||||||
|
@ -94,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";
|
||||||
|
@ -105,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;
|
||||||
|
@ -151,7 +165,7 @@ foreach my $host (sort(keys(%Status)))
|
||||||
next if (@ownerOnly and not grep {/$owner/} @ownerOnly);
|
next if (@ownerOnly and not grep {/$owner/} @ownerOnly);
|
||||||
my %host_conf = %{$server->ConfigDataRead($host)};
|
my %host_conf = %{$server->ConfigDataRead($host)};
|
||||||
$Status{$host}{BackupsDisable} = $host_conf{BackupsDisable};
|
$Status{$host}{BackupsDisable} = $host_conf{BackupsDisable};
|
||||||
next if ( $Status{$host}{BackupsDisable} eq 2 and not $forceCheckOnDisabledHosts);
|
next if ( $Status{$host}{BackupsDisable} && $Status{$host}{BackupsDisable} == 2 and not $forceCheckOnDisabledHosts );
|
||||||
next if (@hostsDesired and not grep {/^$host$/} @hostsDesired);
|
next if (@hostsDesired and not grep {/^$host$/} @hostsDesired);
|
||||||
next if (@hostsExcluded and grep {/^$host$/} @hostsExcluded);
|
next if (@hostsExcluded and grep {/^$host$/} @hostsExcluded);
|
||||||
next if ($Status{$host}{'type'} eq 'archive');
|
next if ($Status{$host}{'type'} eq 'archive');
|
||||||
|
@ -160,6 +174,9 @@ foreach my $host (sort(keys(%Status)))
|
||||||
# Debug
|
# Debug
|
||||||
if ($verbose == 2)
|
if ($verbose == 2)
|
||||||
{
|
{
|
||||||
|
while (my ($key, $value) = each %{$Status{$host}}) {
|
||||||
|
print "$key:\t$value\n";
|
||||||
|
}
|
||||||
print "Host $host state " . $Status{$host}{'state'} . "\n";
|
print "Host $host state " . $Status{$host}{'state'} . "\n";
|
||||||
print " with reason: " . $Status{$host}{'reason'} . "\n";
|
print " with reason: " . $Status{$host}{'reason'} . "\n";
|
||||||
print " with error: " . $Status{$host}{'error'} . "\n";
|
print " with error: " . $Status{$host}{'error'} . "\n";
|
||||||
|
@ -168,7 +185,10 @@ foreach my $host (sort(keys(%Status)))
|
||||||
# Check host error
|
# Check host error
|
||||||
if ($Status{$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 {
|
} else {
|
||||||
$Status{$host}{statusMsg} = "status: ".$Status{$host}{'state'};
|
$Status{$host}{statusMsg} = "status: ".$Status{$host}{'state'};
|
||||||
}
|
}
|
||||||
|
@ -180,26 +200,35 @@ foreach my $host (sort(keys(%Status)))
|
||||||
if ( $Status{$host}{'startDays'} > $critDaysOld ) {
|
if ( $Status{$host}{'startDays'} > $critDaysOld ) {
|
||||||
$Status{$host}{statusMsg} .= ", no backups";
|
$Status{$host}{statusMsg} .= ", no backups";
|
||||||
$Status{$host}{statusCode} = 'CRITICAL';
|
$Status{$host}{statusCode} = 'CRITICAL';
|
||||||
$statusCode = 'CRITICAL';
|
|
||||||
} elsif ( $Status{$host}{'startDays'} > $warnDaysOld ) {
|
} elsif ( $Status{$host}{'startDays'} > $warnDaysOld ) {
|
||||||
$Status{$host}{statusMsg} .= ", no backups";
|
$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' );
|
$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' );
|
||||||
|
@ -207,6 +236,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";
|
my $statusMsg = "BACKUPPC $statusCode";
|
||||||
|
|
||||||
if ( $statusCode eq 'OK' ) {
|
if ( $statusCode eq 'OK' ) {
|
||||||
|
@ -219,10 +261,13 @@ if ( $statusCode eq 'OK' ) {
|
||||||
if ( $verbose ) {
|
if ( $verbose ) {
|
||||||
$statusMsg .= " (";
|
$statusMsg .= " (";
|
||||||
my $first_host = 1;
|
my $first_host = 1;
|
||||||
|
if ($hostCount == 0 || !scalar(keys %Status)) {
|
||||||
|
$statusMsg .= "no host checked";
|
||||||
|
} else {
|
||||||
foreach my $host ( keys %Status ) {
|
foreach my $host ( keys %Status ) {
|
||||||
next if (@hostsDesired and not grep {/^$host$/} @hostsDesired);
|
next if (@hostsDesired and not grep {/^$host$/} @hostsDesired);
|
||||||
next if (@hostsExcluded and grep {/^$host$/} @hostsExcluded);
|
next if (@hostsExcluded and grep {/^$host$/} @hostsExcluded);
|
||||||
next if ( $Status{$host}{BackupsDisable} );
|
next if ( $Status{$host}{BackupsDisable} && $Status{$host}{BackupsDisable} == 2 and not $forceCheckOnDisabledHosts );
|
||||||
next if ($Status{$host}{'type'} eq 'archive');
|
next if ($Status{$host}{'type'} eq 'archive');
|
||||||
if ( $Status{$host}{statusCode} && $Status{$host}{statusCode} ne 'OK' ) {
|
if ( $Status{$host}{statusCode} && $Status{$host}{statusCode} ne 'OK' ) {
|
||||||
$statusMsg .= ", " unless ( $first_host );
|
$statusMsg .= ", " unless ( $first_host );
|
||||||
|
@ -230,6 +275,7 @@ if ( $statusCode eq 'OK' ) {
|
||||||
$first_host = 0 if ( $first_host );
|
$first_host = 0 if ( $first_host );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
$statusMsg .= ")";
|
$statusMsg .= ")";
|
||||||
} else {
|
} else {
|
||||||
$statusMsg .= " ( $ok_count OK, $unknown_count UNKNOWN, $warning_count WARNING, $critical_count CRITICAL)";
|
$statusMsg .= " ( $ok_count OK, $unknown_count UNKNOWN, $warning_count WARNING, $critical_count CRITICAL)";
|
||||||
|
@ -238,3 +284,4 @@ if ( $statusCode eq 'OK' ) {
|
||||||
|
|
||||||
print "$statusMsg\n";
|
print "$statusMsg\n";
|
||||||
exit $ERRORS{$statusCode};
|
exit $ERRORS{$statusCode};
|
||||||
|
# vim:set sw=4 ts=4 sts=4 ft=perl expandtab:
|
||||||
|
|
|
@ -175,4 +175,4 @@ print $per_host_detail;
|
||||||
|
|
||||||
|
|
||||||
exit $ERRORS{$statusCode};
|
exit $ERRORS{$statusCode};
|
||||||
|
# vim:set sw=4 ts=4 sts=4 ft=perl expandtab:
|
||||||
|
|
Loading…
Reference in a new issue