Compare commits

..

No commits in common. "76a91c37e578769a7f851d701ba2575e2149ec1c" and "1e30357cc36af656e36894642eae411224120c9e" have entirely different histories.

2 changed files with 176 additions and 223 deletions

View file

@ -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;
@ -67,65 +65,53 @@ my $critical_count = 0;
# Process options # Process options
$goodOpt = GetOptions( $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, 'o=s' => \@ownerOnly, 'owner=s' => \@ownerOnly,
'W=f' => \$warnDaysInProgress, 'warnprog=f' => \$warnDaysInProgress, 'V' => \$opt_V, 'version' => \$opt_V,
'o=s' => \@ownerOnly, 'owner=s' => \@ownerOnly, 'h' => \$opt_h, 'help' => \$opt_h,
'V' => \$opt_V, 'version' => \$opt_V, 'H=s' => \@hostsDesired, 'hostname=s' => \@hostsDesired,
'h' => \$opt_h, 'help' => \$opt_h, 'x=s' => \@hostsExcluded, 'exclude=s' => \@hostsExcluded,
'H=s' => \@hostsDesired, 'hostname=s' => \@hostsDesired, 'f' => \$forceCheckOnDisabledHosts, 'force=s' => \$forceCheckOnDisabledHosts);
'x=s' => \@hostsExcluded, 'exclude=s' => \@hostsExcluded,
'f' => \$forceCheckOnDisabledHosts, 'force=s' => \$forceCheckOnDisabledHosts);
@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";
exit $ERRORS{'OK'}; exit $ERRORS{'OK'};
} }
if ($opt_h or not $goodOpt) if ($opt_h or not $goodOpt)
{ {
print "check_backuppc - " . $version . "\n"; print "check_backuppc - " . $version . "\n";
print "A Nagios plugin to check on BackupPC backup status.\n\n"; print "A Nagios plugin to check on BackupPC backup status.\n\n";
print "Options:\n"; print "Options:\n";
print " --hostname,-H only check the specified host\n"; print " --hostname,-H only check the specified host\n";
print " --exclude,-x do not check the specified host\n"; print " --exclude,-x do not check the specified host\n";
print " --owner,-o do only hosts of specified user\n"; print " --owner,-o do only hosts of specified user\n";
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 " --verbose,-v increase verbosity\n";
print " --critprog,-C duration (in days) for state backup_in_progress to be critical\n"; print " --version,-V display plugin version\n";
print " --verbose,-v increase verbosity\n"; print " --help,-h display this message\n\n";
print " --version,-V display plugin version\n"; exit $ERRORS{'OK'} if $goodOpt;
print " --help,-h display this message\n\n"; exit $ERRORS{'UNKNOWN'};
exit $ERRORS{'OK'} if $goodOpt;
exit $ERRORS{'UNKNOWN'};
} }
if ($warnDaysOld > $critDaysOld) 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;
if (!($server = BackupPC::Lib->new)) if (!($server = BackupPC::Lib->new))
{ {
print "BACKUPPC CRITICAL - Couldn't connect to BackupPC\n"; print "BACKUPPC CRITICAL - Couldn't connect to BackupPC\n";
exit $ERRORS{'CRITICAL'}; exit $ERRORS{'CRITICAL'};
} }
my %Conf = $server->Conf(); my %Conf = $server->Conf();
@ -134,8 +120,8 @@ $server->ChildInit();
my $err = $server->ServerConnect($Conf{ServerHost}, $Conf{ServerPort}); my $err = $server->ServerConnect($Conf{ServerHost}, $Conf{ServerPort});
if ($err) if ($err)
{ {
print("BACKUPPC UNKNOWN - Can't connect to server ($err)\n"); print("BACKUPPC UNKNOWN - Can't connect to server ($err)\n");
exit $ERRORS{'UNKNOWN'}; exit $ERRORS{'UNKNOWN'};
} }
# query the BackupPC server for host status # query the BackupPC server for host status
@ -150,138 +136,105 @@ my $hostCount = 0;
foreach my $host (@hostsDesired, @hostsExcluded) foreach my $host (@hostsDesired, @hostsExcluded)
{ {
if (not grep {/^$host$/} keys(%Status)) if (not grep {/^$host$/} keys(%Status))
{ {
print("BACKUPPC UNKNOWN - Unknown host ($host)\n"); print("BACKUPPC UNKNOWN - Unknown host ($host)\n");
exit $ERRORS{'UNKNOWN'}; exit $ERRORS{'UNKNOWN'};
} }
} }
# host status checks # host status checks
foreach my $host (sort(keys(%Status))) foreach my $host (sort(keys(%Status)))
{ {
next if $host =~ /^ /; next if $host =~ /^ /;
my $owner = $hosts_infos->{$host}->{user}; my $owner = $hosts_infos->{$host}->{user};
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');
$Status{$host}{'statusCode'} = 'OK'; $Status{$host}{'statusCode'} = 'OK';
$hostCount++; $hostCount++;
# Debug # Debug
if ($verbose == 2) if ($verbose == 2)
{ {
while (my ($key, $value) = each %{$Status{$host}}) { print "Host $host state " . $Status{$host}{'state'} . "\n";
print "$key:\t$value\n"; print " with reason: " . $Status{$host}{'reason'} . "\n";
} print " with error: " . $Status{$host}{'error'} . "\n";
print "Host $host state " . $Status{$host}{'state'} . "\n"; print " with owner: $owner\n\n";
print " with reason: " . $Status{$host}{'reason'} . "\n"; }
print " with error: " . $Status{$host}{'error'} . "\n"; # Check host error
print " with owner: $owner\n\n"; if ($Status{$host}{'error'})
} {
# Check host error $Status{$host}{statusMsg} = "error: ".$Status{$host}{'error'}." / ".$Status{$host}{'reason'};
if ($Status{$host}{'error'}) } else {
{ $Status{$host}{statusMsg} = "status: ".$Status{$host}{'state'};
$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'};
}
# Check last good backup time # Check last good backup time
$Status{$host}{'lastGoodBackupDays'} = difftime(time(), $Status{$host}{'lastGoodBackupTime'}) / (3600 * 24) if ( defined $Status{$host}{'lastGoodBackupTime'} ); $Status{$host}{'lastGoodBackupDays'} = difftime(time(), $Status{$host}{'lastGoodBackupTime'}) / (3600 * 24) if ( defined $Status{$host}{'lastGoodBackupTime'} );
if ( ! $Status{$host}{'lastGoodBackupDays'} ) { if ( ! $Status{$host}{'lastGoodBackupDays'} ) {
$Status{$host}{'startDays'} = difftime(time(), $Status{$host}{'startTime'}) / (3600 * 24); $Status{$host}{'startDays'} = difftime(time(), $Status{$host}{'startTime'}) / (3600 * 24);
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';
} elsif ( $Status{$host}{'startDays'} > $warnDaysOld ) { $statusCode = 'CRITICAL';
$Status{$host}{statusMsg} .= ", no backups"; } elsif ( $Status{$host}{'startDays'} > $warnDaysOld ) {
$Status{$host}{statusCode} = 'WARNING' unless ( $Status{$host}{statusCode} eq 'CRITICAL' ); $Status{$host}{statusMsg} .= ", no backups";
$statusCode = 'WARNING' unless ( $statusCode eq 'CRITICAL' ); $Status{$host}{statusCode} = 'WARNING' unless ( $Status{$host}{statusCode} = 'CRITICAL' );
} $statusCode = 'WARNING' unless ( $statusCode eq 'CRITICAL' );
} else { }
if ($Status{$host}{state} eq 'Status_backup_in_progress') { } elsif ( $Status{$host}{'lastGoodBackupDays'} > $critDaysOld )
$Status{$host}{'startDays'} = difftime(time(), $Status{$host}{'startTime'}) / (3600 * 24); {
if ( $Status{$host}{'startDays'} > $critDaysInProgress ) { $Status{$host}{statusMsg} .= ", last good backup have ".sprintf("%.1f", $Status{$host}{'lastGoodBackupDays'})." days";
$Status{$host}{statusMsg} .= " for " . sprintf("%.1f", $Status{$host}{'startDays'} * 24) . " hours"; $Status{$host}{statusCode} = 'CRITICAL';
$Status{$host}{statusCode} = 'CRITICAL'; $statusCode = 'CRITICAL';
} elsif ( $Status{$host}{'startDays'} > $warnDaysInProgress ) { }
$Status{$host}{statusMsg} .= " for " . sprintf("%.1f", $Status{$host}{'startDays'} * 24) . " hours"; elsif ( $Status{$host}{'lastGoodBackupDays'} > $warnDaysOld )
$Status{$host}{statusCode} = 'WARNING' unless ( $Status{$host}{statusCode} eq 'CRITICAL' ); {
} $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' );
if ( $Status{$host}{'lastGoodBackupDays'} > $critDaysOld ) { } 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";
$Status{$host}{statusCode} = 'CRITICAL'; }
} $ok_count++ if ( $Status{$host}{statusCode} eq 'OK' );
elsif ( $Status{$host}{'lastGoodBackupDays'} > $warnDaysOld ) { $unknown_count++ if ( $Status{$host}{statusCode} eq 'UNKNOWN' );
$Status{$host}{statusMsg} .= ", last good backup have ".sprintf("%.1f",$Status{$host}{'lastGoodBackupDays'})." days"; $warning_count++ if ( $Status{$host}{statusCode} eq 'WARNING' );
$Status{$host}{statusCode} = 'WARNING' unless ( $Status{$host}{statusCode} eq 'CRITICAL' ); $critical_count++ if ( $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' );
$warning_count++ if ( $Status{$host}{statusCode} eq 'WARNING' );
$critical_count++ if ( $Status{$host}{statusCode} eq 'CRITICAL' );
} }
# 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' ) {
if ( $verbose && scalar(@hostsDesired) == 1 ) { if ( $verbose && scalar(@hostsDesired) == 1 ) {
$statusMsg .= " (".$Status{$hostsDesired[0]}{statusMsg}.")"; $statusMsg .= " (".$Status{$hostsDesired[0]}{statusMsg}.")";
} else { } else {
$statusMsg .= " ($ok_count OK)"; $statusMsg .= " ($ok_count OK)";
} }
} else { } else {
if ( $verbose ) { if ( $verbose ) {
$statusMsg .= " ("; $statusMsg .= " (";
my $first_host = 1; my $first_host = 1;
if ($hostCount == 0 || !scalar(keys %Status)) { foreach my $host ( keys %Status ) {
$statusMsg .= "no host checked"; next if (@hostsDesired and not grep {/^$host$/} @hostsDesired);
} else { next if (@hostsExcluded and grep {/^$host$/} @hostsExcluded);
foreach my $host ( keys %Status ) { next if ( $Status{$host}{BackupsDisable} );
next if (@hostsDesired and not grep {/^$host$/} @hostsDesired); next if ($Status{$host}{'type'} eq 'archive');
next if (@hostsExcluded and grep {/^$host$/} @hostsExcluded); if ( $Status{$host}{statusCode} && $Status{$host}{statusCode} ne 'OK' ) {
next if ( $Status{$host}{BackupsDisable} && $Status{$host}{BackupsDisable} == 2 and not $forceCheckOnDisabledHosts ); $statusMsg .= ", " unless ( $first_host );
next if ($Status{$host}{'type'} eq 'archive'); $statusMsg .= "$host: ".$Status{$host}{statusCode}." - ".$Status{$host}{statusMsg};
if ( $Status{$host}{statusCode} && $Status{$host}{statusCode} ne 'OK' ) { $first_host = 0 if ( $first_host );
$statusMsg .= ", " unless ( $first_host ); }
$statusMsg .= "$host: ".$Status{$host}{statusCode}." - ".$Status{$host}{statusMsg}; }
$first_host = 0 if ( $first_host ); $statusMsg .= ")";
} } else {
} $statusMsg .= " ( $ok_count OK, $unknown_count UNKNOWN, $warning_count WARNING, $critical_count CRITICAL)";
} }
$statusMsg .= ")";
} else {
$statusMsg .= " ( $ok_count OK, $unknown_count UNKNOWN, $warning_count WARNING, $critical_count CRITICAL)";
}
} }
print "$statusMsg\n"; print "$statusMsg\n";
exit $ERRORS{$statusCode}; exit $ERRORS{$statusCode};
# vim:set sw=4 ts=4 sts=4 ft=perl expandtab:

View file

@ -55,37 +55,37 @@ my $statusCode = 'OK';
# Process options # Process options
my $goodOpt = GetOptions( my $goodOpt = GetOptions(
'q=f' => \$quota, 'quota=f' => \$quota, 'q=f' => \$quota, 'quota=f' => \$quota,
'V' => \$opt_V, 'version' => \$opt_V, 'V' => \$opt_V, 'version' => \$opt_V,
'h' => \$opt_h, 'help' => \$opt_h, 'h' => \$opt_h, 'help' => \$opt_h,
'H=s' => \$host, 'hostname=s' => \$host, 'H=s' => \$host, 'hostname=s' => \$host,
'L=s' => \@hostlist, 'hostlist=s' => \@hostlist, 'L=s' => \@hostlist, 'hostlist=s' => \@hostlist,
); );
if ($opt_V) if ($opt_V)
{ {
print "check_backuppc_du - " . $version . "\n"; print "check_backuppc_du - " . $version . "\n";
exit $ERRORS{'OK'}; exit $ERRORS{'OK'};
} }
if ($opt_h or not $goodOpt) if ($opt_h or not $goodOpt)
{ {
print "check_backuppc_du - " . $version . "\n"; print "check_backuppc_du - " . $version . "\n";
print "A Nagios plugin to check on BackupPC backup status.\n\n"; print "A Nagios plugin to check on BackupPC backup status.\n\n";
print "Options:\n"; print "Options:\n";
print " --hostname,-H perl regexp to match hostnames\n"; print " --hostname,-H perl regexp to match hostnames\n";
print " --quota,-q quota size (GB)\n"; print " --quota,-q quota size (GB)\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";
exit $ERRORS{'OK'} if $goodOpt; exit $ERRORS{'OK'} if $goodOpt;
exit $ERRORS{'UNKNOWN'}; exit $ERRORS{'UNKNOWN'};
} }
# Connect to BackupPC # Connect to BackupPC
my $server; my $server;
if (!($server = BackupPC::Lib->new)) if (!($server = BackupPC::Lib->new))
{ {
print "BACKUPPC CRITICAL - Couldn't connect to BackupPC\n"; print "BACKUPPC CRITICAL - Couldn't connect to BackupPC\n";
exit $ERRORS{'CRITICAL'}; exit $ERRORS{'CRITICAL'};
} }
my %Conf = $server->Conf(); my %Conf = $server->Conf();
@ -94,8 +94,8 @@ $server->ChildInit();
my $err = $server->ServerConnect($Conf{ServerHost}, $Conf{ServerPort}); my $err = $server->ServerConnect($Conf{ServerHost}, $Conf{ServerPort});
if ($err) if ($err)
{ {
print("BACKUPPC UNKNOWN - Can't connect to server ($err)\n"); print("BACKUPPC UNKNOWN - Can't connect to server ($err)\n");
exit $ERRORS{'UNKNOWN'}; exit $ERRORS{'UNKNOWN'};
} }
# query the BackupPC server for host status # query the BackupPC server for host status
@ -114,60 +114,60 @@ my $total_count = 0;
my $host_count = 0; my $host_count = 0;
foreach my $hostname ( sort(keys %Status) ) { foreach my $hostname ( sort(keys %Status) ) {
next if $hostname =~ /^\s*$/; next if $hostname =~ /^\s*$/;
next if $hostname =~ /^ /; next if $hostname =~ /^ /;
next if ( $host && $hostname !~ m/$host/ ); next if ( $host && $hostname !~ m/$host/ );
next if ( scalar(@hostlist) > 0 && not(grep /^\Q$hostname$/, @hostlist) ); next if ( scalar(@hostlist) > 0 && not(grep /^\Q$hostname$/, @hostlist) );
my %HostStatus = %{$Status{$hostname}}; my %HostStatus = %{$Status{$hostname}};
my %host_conf = %{$server->ConfigDataRead($hostname)}; my %host_conf = %{$server->ConfigDataRead($hostname)};
$HostStatus{BackupsDisable} = $host_conf{BackupsDisable}; $HostStatus{BackupsDisable} = $host_conf{BackupsDisable};
next if ( $HostStatus{BackupsDisable} eq 2); next if ( $HostStatus{BackupsDisable} eq 2);
next if ($HostStatus{'type'} eq 'archive'); next if ($HostStatus{'type'} eq 'archive');
$host_count++; $host_count++;
# Backups # Backups
my @Backups = $server->BackupInfoRead($hostname); my @Backups = $server->BackupInfoRead($hostname);
# Get aggregate of compressed used size (octets) # Get aggregate of compressed used size (octets)
my $full_size = 0; my $full_size = 0;
my $backups_count = 0; my $backups_count = 0;
foreach my $Backup (sort {$a->{num} cmp $b->{num}} @Backups) { foreach my $Backup (sort {$a->{num} cmp $b->{num}} @Backups) {
if ( $full_size == 0 ) { if ( $full_size == 0 ) {
$full_size += $Backup->{sizeExistComp}; $full_size += $Backup->{sizeExistComp};
$full_size += $Backup->{sizeNewComp}; $full_size += $Backup->{sizeNewComp};
} else { } else {
$full_size += $Backup->{sizeNewComp}; $full_size += $Backup->{sizeNewComp};
} }
$backups_count++; $backups_count++;
} }
$total_usage += $full_size; $total_usage += $full_size;
$total_count += $backups_count; $total_count += $backups_count;
# Convert to Go # Convert to Go
$full_size = sprintf("%0.2f", $full_size / 1024 / 1024 / 1024); $full_size = sprintf("%0.2f", $full_size / 1024 / 1024 / 1024);
# Output size # Output size
$per_host_detail .= "$hostname: $backups_count backups / $full_size Go\n"; $per_host_detail .= "$hostname: $backups_count backups / $full_size Go\n";
} }
unless ( $host_count ) { unless ( $host_count ) {
print "BACKUPPC UNKNOWN - no host matching $host\n"; print "BACKUPPC UNKNOWN - no host matching $host\n";
exit $ERRORS{'UNKNOWN'}; exit $ERRORS{'UNKNOWN'};
} }
$total_usage = sprintf("%0.2f", $total_usage / 1024 / 1024 / 1024); $total_usage = sprintf("%0.2f", $total_usage / 1024 / 1024 / 1024);
if ( $total_usage >= $quota ) { if ( $total_usage >= $quota ) {
print "BACKUPPC CRITICAL - $total_usage Go used / $quota Go allocated\n"; print "BACKUPPC CRITICAL - $total_usage Go used / $quota Go allocated\n";
$statusCode = 'CRITICAL'; $statusCode = 'CRITICAL';
} elsif ( $total_usage >= $quota * 0.90 ) { } elsif ( $total_usage >= $quota * 0.90 ) {
print "BACKUPPC WARNING - $total_usage Go used / $quota Go allocated\n"; print "BACKUPPC WARNING - $total_usage Go used / $quota Go allocated\n";
$statusCode = 'WARNING'; $statusCode = 'WARNING';
} else { } else {
print "BACKUPPC OK - $total_usage Go used / $quota Go allocated\n"; print "BACKUPPC OK - $total_usage Go used / $quota Go allocated\n";
} }
print "Total of $total_count backups with cumulative compressed size of $total_usage Go for $host_count active hosts\n"; print "Total of $total_count backups with cumulative compressed size of $total_usage Go for $host_count active hosts\n";
@ -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: