Compare commits
No commits in common. "76a91c37e578769a7f851d701ba2575e2149ec1c" and "1e30357cc36af656e36894642eae411224120c9e" have entirely different histories.
76a91c37e5
...
1e30357cc3
2 changed files with 176 additions and 223 deletions
|
@ -47,8 +47,6 @@ 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;
|
||||||
|
@ -58,7 +56,7 @@ my @hostsDesired;
|
||||||
my @hostsExcluded;
|
my @hostsExcluded;
|
||||||
my $forceCheckOnDisabledHosts;
|
my $forceCheckOnDisabledHosts;
|
||||||
my %Status;
|
my %Status;
|
||||||
my $statusCode = 'UNKNOWN';
|
my $statusCode = 'OK';
|
||||||
my $ok_count = 0;
|
my $ok_count = 0;
|
||||||
my $unknown_count = 0;
|
my $unknown_count = 0;
|
||||||
my $warning_count = 0;
|
my $warning_count = 0;
|
||||||
|
@ -70,8 +68,6 @@ $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,
|
||||||
|
@ -82,9 +78,6 @@ $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";
|
||||||
|
@ -101,8 +94,6 @@ 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";
|
||||||
|
@ -114,11 +105,6 @@ 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;
|
||||||
|
@ -165,7 +151,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} && $Status{$host}{BackupsDisable} == 2 and not $forceCheckOnDisabledHosts );
|
next if ( $Status{$host}{BackupsDisable} eq 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');
|
||||||
|
@ -174,9 +160,6 @@ 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";
|
||||||
|
@ -185,10 +168,7 @@ foreach my $host (sort(keys(%Status)))
|
||||||
# Check host error
|
# Check host error
|
||||||
if ($Status{$host}{'error'})
|
if ($Status{$host}{'error'})
|
||||||
{
|
{
|
||||||
$Status{$host}{statusCode} = 'CRITICAL';
|
$Status{$host}{statusMsg} = "error: ".$Status{$host}{'error'}." / ".$Status{$host}{'reason'};
|
||||||
$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'};
|
||||||
}
|
}
|
||||||
|
@ -200,35 +180,26 @@ 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} eq 'CRITICAL' );
|
$Status{$host}{statusCode} = 'WARNING' unless ( $Status{$host}{statusCode} = 'CRITICAL' );
|
||||||
$statusCode = 'WARNING' unless ( $statusCode eq 'CRITICAL' );
|
$statusCode = 'WARNING' unless ( $statusCode eq 'CRITICAL' );
|
||||||
}
|
}
|
||||||
} else {
|
} elsif ( $Status{$host}{'lastGoodBackupDays'} > $critDaysOld )
|
||||||
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} eq 'CRITICAL' );
|
$Status{$host}{statusCode} = 'WARNING' unless ( $Status{$host}{statusCode} = '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' );
|
||||||
|
@ -236,19 +207,6 @@ 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' ) {
|
||||||
|
@ -261,13 +219,10 @@ 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} && $Status{$host}{BackupsDisable} == 2 and not $forceCheckOnDisabledHosts );
|
next if ( $Status{$host}{BackupsDisable} );
|
||||||
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 );
|
||||||
|
@ -275,7 +230,6 @@ 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)";
|
||||||
|
@ -284,4 +238,3 @@ 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