Compare commits

...

8 commits

Author SHA1 Message Date
Benjamin Renard
80aa2de86e
Add Debian package building files 2024-10-07 12:39:38 +02:00
Benjamin Renard
b477cb7a55
Add some pre-commit hooks 2024-10-07 12:04:13 +02:00
Emmanuel Lacour
a18b4d6ae9
check_backuppc: improve debug output 2024-10-07 12:04:12 +02:00
Emmanuel Lacour
6c048b83b7
check_backuppc: critical output if no host was checked 2024-10-07 12:04:12 +02:00
Emmanuel Lacour
7f607c2c7a
check_backuppc: add a check on how many time an host is in backup_in_progress state 2024-10-07 12:04:11 +02:00
Emmanuel Lacour
7fdfa4d41e
check_backuppc: force check on disabled host if host is specified 2024-10-07 12:04:11 +02:00
Emmanuel Lacour
9bed5546ee
check_backuppc: Use UNKNOWN as default state 2024-10-07 12:04:11 +02:00
Benjamin Renard
4bd371ea80
Use spaces instead of tabs for indentation 2024-10-07 12:04:10 +02:00
14 changed files with 418 additions and 205 deletions

15
.editorconfig Normal file
View file

@ -0,0 +1,15 @@
root = true
[*]
indent_style = space
indent_size = 4
trim_trailing_whitespace = true
insert_final_newline = true
charset = utf-8
end_of_line = lf
[*.{yaml,yml}]
indent_size = 2
[Makefile]
indent_style = tab

1
.gitignore vendored
View file

@ -1 +1,2 @@
*~ *~
/dist

29
.pre-commit-config.yaml Normal file
View file

@ -0,0 +1,29 @@
# Pre-commit hooks to run tests and ensure code is cleaned.
# See https://pre-commit.com for more information
---
repos:
- repo: https://github.com/codespell-project/codespell
rev: v2.2.2
hooks:
- id: codespell
args:
- --ignore-words-list=exten
- --skip="./.*,*.csv,*.json,*.ini,*.subject,*.txt,*.html,*.log,*.conf"
- --quiet-level=2
- --ignore-regex=.*codespell-ignore$
# - --write-changes # Uncomment to write changes
exclude_types: [csv, json]
- repo: https://github.com/pre-commit/mirrors-prettier
rev: v2.7.1
hooks:
- id: prettier
args: ["--print-width", "100"]
- repo: https://github.com/adrienverge/yamllint
rev: v1.32.0
hooks:
- id: yamllint
ignore: .github/
- repo: https://github.com/shellcheck-py/shellcheck-py
rev: v0.10.0.1
hooks:
- id: shellcheck

View file

@ -1,28 +1,24 @@
Nagios/Icinga check plugins for BackupPC # Nagios/Icinga check plugins for BackupPC
========================================
This repository compile some usefull Nagios/Icinga check plugins for BackupPC : This repository compile some useful Nagios/Icinga check plugins for BackupPC :
* *check_backuppc\* :* Check the age of the last backup - _check_backuppc\* :_ Check the age of the last backup
* *check_backuppc_du :* Check disk space use by backups - _check_backuppc_du :_ Check disk space use by backups
\* This check plugins was fork from [_check_backuppc_](https://sourceforge.net/projects/n-backuppc/) (version 1.1.0) write by Seneca Cunningham <tetragon@users.sourceforge.net>. \* This check plugins was fork from [_check_backuppc_](https://sourceforge.net/projects/n-backuppc/) (version 1.1.0) write by Seneca Cunningham <tetragon@users.sourceforge.net>.
Compatibility ## Compatibility
-------------
This check plugins have been successfully test with BackupPC 3 (3.2.1) and 4 (4.1.5). This check plugins have been successfully test with BackupPC 3 (3.2.1) and 4 (4.1.5).
Copyright ## Copyright
---------
Copyright (c) 2018 Easter-eggs Copyright (c) 2018 Easter-eggs
License ## License
-------
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License version 3 as published by the Free Software Foundation. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License version 3 as published by the Free Software Foundation.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

76
build.sh Executable file
View file

@ -0,0 +1,76 @@
#!/bin/bash
QUIET_ARG=""
[[ "$1" == "--quiet" ]] && QUIET_ARG="--quiet"
# Enter source directory
cd "$( dirname "$0" )" || exit
mapfile -t FILES < <( awk '{print $1}' < "debian/install" )
[[ "${#FILES[@]}" -eq 0 ]] && echo "No file found in debian/install file!" && exit 1
PACKAGE_NAME="$( basename "$( head -n1 <<< "$FILES" )" | tr '_' '-' )"
echo "Clean previous build..."
rm -fr dist
echo "Detect version using git describe..."
VERSION="$( git describe --tags|sed 's/^[^0-9]*//' )"
echo "Create building environemt..."
BDIR="dist/$PACKAGE_NAME-$VERSION"
mkdir -p "$BDIR"
RSYNC_ARG=""
[[ -z "$QUIET_ARG" ]] && RSYNC_ARG="-v"
rsync -a "$RSYNC_ARG" debian/ "$BDIR/debian/"
cp "${FILES[@]}" "$BDIR/"
echo "Set version $VERSION in files..."
for FILE in "${FILES[@]}"; do
case "$( mimetype -b "$FILE" )" in
application/x-perl)
echo " - in $FILE (perl)"
sed -i "s/^my \$version *=.*$/my \$version = '$VERSION';/" "$BDIR/$( basename "$FILE" )"
;;
application/x-shellscript)
echo " - in $FILE (shellscript)"
sed -i "s/^VERSION *=.*$/VERSION = '$VERSION'/" "$BDIR/$( basename "$FILE" )"
;;
esac
done
if [[ -z "$DEBIAN_CODENAME" ]]; then
echo "Retrieve debian codename using lsb_release..."
DEBIAN_CODENAME=$( lsb_release -c -s )
else
echo "Use debian codename from environment ($DEBIAN_CODENAME)"
fi
echo "Generate debian changelog using gitdch..."
GITDCH_ARGS=('--verbose')
[[ -n "$QUIET_ARG" ]] && GITDCH_ARGS=('--warning')
if [[ -n "$MAINTAINER_NAME" ]]; then
echo "Use maintainer name from environment ($MAINTAINER_NAME)"
GITDCH_ARGS+=("--maintainer-name" "${MAINTAINER_NAME}")
fi
if [[ -n "$MAINTAINER_EMAIL" ]]; then
echo "Use maintainer email from environment ($MAINTAINER_EMAIL)"
GITDCH_ARGS+=("--maintainer-email" "$MAINTAINER_EMAIL")
fi
gitdch \
--package-name "$PACKAGE_NAME" \
--version "${VERSION}" \
--code-name "$DEBIAN_CODENAME" \
--output "$BDIR"/debian/changelog \
--release-notes dist/release_notes.md \
"${GITDCH_ARGS[@]}"
if [[ -n "$MAINTAINER_NAME" ]] && [[ -n "$MAINTAINER_EMAIL" ]]; then
echo "Set Maintainer field in debian control file ($MAINTAINER_NAME <$MAINTAINER_EMAIL>)..."
sed -i "s/^Maintainer: .*$/Maintainer: $MAINTAINER_NAME <$MAINTAINER_EMAIL>/" \
"$BDIR"/debian/control
fi
echo "Build debian package..."
cd "$BDIR" || exit
dpkg-buildpackage
# vim:set sw=4 ts=4 sts=4 ft=bash expandtab:

View file

@ -44,9 +44,11 @@ Getopt::Long::Configure('bundling');
use lib "/usr/share/backuppc/lib"; use lib "/usr/share/backuppc/lib";
use BackupPC::Lib; use BackupPC::Lib;
my $version = '1.1.3'; my $version = 'dev';
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;
@ -65,53 +67,65 @@ 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,
'o=s' => \@ownerOnly, 'owner=s' => \@ownerOnly, 'C=f' => \$critDaysInProgress, 'critprog=f' => \$critDaysInProgress,
'V' => \$opt_V, 'version' => \$opt_V, 'W=f' => \$warnDaysInProgress, 'warnprog=f' => \$warnDaysInProgress,
'h' => \$opt_h, 'help' => \$opt_h, 'o=s' => \@ownerOnly, 'owner=s' => \@ownerOnly,
'H=s' => \@hostsDesired, 'hostname=s' => \@hostsDesired, 'V' => \$opt_V, 'version' => \$opt_V,
'x=s' => \@hostsExcluded, 'exclude=s' => \@hostsExcluded, 'h' => \$opt_h, 'help' => \$opt_h,
'f' => \$forceCheckOnDisabledHosts, 'force=s' => \$forceCheckOnDisabledHosts); 'H=s' => \@hostsDesired, 'hostname=s' => \@hostsDesired,
'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 triggered 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 " --verbose,-v increase verbosity\n"; print " --warnprog,-W duration (in days) for state backup_in_progress to cause a warning\n";
print " --version,-V display plugin version\n"; print " --critprog,-C duration (in days) for state backup_in_progress to be critical\n";
print " --help,-h display this message\n\n"; print " --verbose,-v increase verbosity\n";
exit $ERRORS{'OK'} if $goodOpt; print " --version,-V display plugin version\n";
exit $ERRORS{'UNKNOWN'}; print " --help,-h display this message\n\n";
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();
@ -120,8 +134,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
@ -136,105 +150,138 @@ 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} 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');
$Status{$host}{'statusCode'} = 'OK'; $Status{$host}{'statusCode'} = 'OK';
$hostCount++; $hostCount++;
# Debug # Debug
if ($verbose == 2) if ($verbose == 2)
{ {
print "Host $host state " . $Status{$host}{'state'} . "\n"; while (my ($key, $value) = each %{$Status{$host}}) {
print " with reason: " . $Status{$host}{'reason'} . "\n"; print "$key:\t$value\n";
print " with error: " . $Status{$host}{'error'} . "\n"; }
print " with owner: $owner\n\n"; print "Host $host state " . $Status{$host}{'state'} . "\n";
} print " with reason: " . $Status{$host}{'reason'} . "\n";
# Check host error print " with error: " . $Status{$host}{'error'} . "\n";
if ($Status{$host}{'error'}) print " with owner: $owner\n\n";
{ }
$Status{$host}{statusMsg} = "error: ".$Status{$host}{'error'}." / ".$Status{$host}{'reason'}; # Check host error
} else { if ($Status{$host}{'error'})
$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';
$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);
$Status{$host}{statusMsg} .= ", last good backup have ".sprintf("%.1f", $Status{$host}{'lastGoodBackupDays'})." days"; if ( $Status{$host}{'startDays'} > $critDaysInProgress ) {
$Status{$host}{statusCode} = 'CRITICAL'; $Status{$host}{statusMsg} .= " for " . sprintf("%.1f", $Status{$host}{'startDays'} * 24) . " hours";
$statusCode = 'CRITICAL'; $Status{$host}{statusCode} = 'CRITICAL';
} } elsif ( $Status{$host}{'startDays'} > $warnDaysInProgress ) {
elsif ( $Status{$host}{'lastGoodBackupDays'} > $warnDaysOld ) $Status{$host}{statusMsg} .= " for " . sprintf("%.1f", $Status{$host}{'startDays'} * 24) . " hours";
{ $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' );
} else { 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';
$ok_count++ if ( $Status{$host}{statusCode} eq 'OK' ); }
$unknown_count++ if ( $Status{$host}{statusCode} eq 'UNKNOWN' ); elsif ( $Status{$host}{'lastGoodBackupDays'} > $warnDaysOld ) {
$warning_count++ if ( $Status{$host}{statusCode} eq 'WARNING' ); $Status{$host}{statusMsg} .= ", last good backup have ".sprintf("%.1f",$Status{$host}{'lastGoodBackupDays'})." days";
$critical_count++ if ( $Status{$host}{statusCode} eq 'CRITICAL' ); $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' );
$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;
foreach my $host ( keys %Status ) { if ($hostCount == 0 || !scalar(keys %Status)) {
next if (@hostsDesired and not grep {/^$host$/} @hostsDesired); $statusMsg .= "no host checked";
next if (@hostsExcluded and grep {/^$host$/} @hostsExcluded); } else {
next if ( $Status{$host}{BackupsDisable} ); foreach my $host ( keys %Status ) {
next if ($Status{$host}{'type'} eq 'archive'); next if (@hostsDesired and not grep {/^$host$/} @hostsDesired);
if ( $Status{$host}{statusCode} && $Status{$host}{statusCode} ne 'OK' ) { next if (@hostsExcluded and grep {/^$host$/} @hostsExcluded);
$statusMsg .= ", " unless ( $first_host ); next if ( $Status{$host}{BackupsDisable} && $Status{$host}{BackupsDisable} == 2 and not $forceCheckOnDisabledHosts );
$statusMsg .= "$host: ".$Status{$host}{statusCode}." - ".$Status{$host}{statusMsg}; next if ($Status{$host}{'type'} eq 'archive');
$first_host = 0 if ( $first_host ); if ( $Status{$host}{statusCode} && $Status{$host}{statusCode} ne 'OK' ) {
} $statusMsg .= ", " unless ( $first_host );
} $statusMsg .= "$host: ".$Status{$host}{statusCode}." - ".$Status{$host}{statusMsg};
$statusMsg .= ")"; $first_host = 0 if ( $first_host );
} 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

@ -42,7 +42,7 @@ Getopt::Long::Configure('bundling');
use lib "/usr/share/backuppc/lib"; use lib "/usr/share/backuppc/lib";
use BackupPC::Lib; use BackupPC::Lib;
my $version = '1.0'; my $version = 'dev';
# Default quota (GB) # Default quota (GB)
my $quota = 100; my $quota = 100;
my $opt_V = 0; my $opt_V = 0;
@ -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
@ -105,7 +105,7 @@ my $hosts_infos = $server->HostInfoRead();
# undump the output... BackupPC uses Data::Dumper # undump the output... BackupPC uses Data::Dumper
eval $status_raw; eval $status_raw;
# Allow hostname separeted by comma # Allow hostname separated by comma
@hostlist = split(/,/,join(',',@hostlist)); @hostlist = split(/,/,join(',',@hostlist));
my $per_host_detail; my $per_host_detail;
@ -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:

View file

@ -1,6 +1,12 @@
#!/bin/bash #!/bin/bash
cd /var/lib/backuppc/pc VERSION=dev
[[ ! -d /var/lib/backuppc/pc ]] && echo "BackupPC directory not found (/var/lib/backuppc/pc)." && exit 1
if ! cd "/var/lib/backuppc/pc"; then
echo "Failed to enter in BackupPC directory (/var/lib/backuppc/pc)."
exit 1
fi
OUT="<table align=center> OUT="<table align=center>
<thead> <thead>
@ -15,18 +21,19 @@ OUT="<table align=center>
<tbody>" <tbody>"
t_v3=0 t_v3=0
t_v4=0 t_v4=0
for h in * for h in *; do
do if [[ ! -d "$h" ]] || [[ ! -e "$h/backups" ]]; then
[ ! -d "$h" -o ! -e "$h/backups" ] && continue continue
vers=$( cat $h/backups|cut -f24 ) fi
v3=$( echo -e "$vers"|grep -Ev '^4'|wc -l|cut -f1 ) vers=$( cut -f24 < "$h/backups" )
let t_v3=t_v3+v3 v3=$( grep -Evc '^4' <<< "$vers" )
[ $v3 -ne 0 ] && v3="<strong>$v3</strong>" ((t_v3=t_v3+v3))
v4=$( echo -e "$vers"|grep -Ec '^4' ) [[ "$v3" -ne 0 ]] && v3="<strong>$v3</strong>"
let t_v4=t_v4+v4 v4=$( grep -Ec '^4' <<< "$vers" )
OUT="$OUT<tr><td align=left>$h</td><td>$v3</td><td>$v4</td></tr>" ((t_v4=t_v4+v4))
OUT="$OUT<tr><td align=left>$h</td><td>$v3</td><td>$v4</td></tr>"
done done
[ $t_v3 -gt 0 ] && t_v3="<strong>$t_v3</strong>" [[ $t_v3 -gt 0 ]] && t_v3="<strong>$t_v3</strong>"
OUT="$OUT OUT="$OUT
</tbody> </tbody>
<tfooter> <tfooter>
@ -37,4 +44,5 @@ OUT="$OUT
</tr> </tr>
</tfooter> </tfooter>
</table>" </table>"
echo $OUT|lynx -stdin lynx -stdin <<< "$OUT"
# vim:set sw=4 ts=4 sts=4 ft=bash expandtab:

1
debian/compat vendored Normal file
View file

@ -0,0 +1 @@
11

12
debian/control vendored Normal file
View file

@ -0,0 +1,12 @@
Source: check-backuppc
Section: admin
Priority: optional
Maintainer: Easter-eggs <info@easter-eggs.com>
Build-Depends: debhelper (>> 11.0.0)
Standards-Version: 3.9.6
Package: check-backuppc
Architecture: all
Depends: ${misc:Depends}, backuppc, libmonitoring-plugin-perl
Description: Monitoring plugin to check BackupPC instance
This Icinga/Nagios check plugins permit to check BackupPC instance

20
debian/copyright vendored Normal file
View file

@ -0,0 +1,20 @@
This package was written by Benjamin Renard <brenard@easter-eggs.com>.
Copyright (C) 2013-2024 Easter-eggs <info@easter-eggs.com>
check-backuppc is licensed under the GNU general public license, version 2.
check-backuppc is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation; either version 2, or (at your option) any later version.
check-backuppc is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with
check-backuppc; see the file COPYING. If not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
On Debian systems, a copy of the GNU General Public License is available in
/usr/share/common-licenses/GPL-2 as part of the base-files package.

3
debian/install vendored Normal file
View file

@ -0,0 +1,3 @@
check_backuppc usr/lib/nagios/plugins
check_backuppc_du usr/lib/nagios/plugins
check_backuppc_nb_bkp_v3 usr/bin

4
debian/rules vendored Executable file
View file

@ -0,0 +1,4 @@
#!/usr/bin/make -f
#export DH_VERBOSE=1
%:
dh $@

1
debian/source/format vendored Normal file
View file

@ -0,0 +1 @@
1.0