+

Migration to gogs.zionetrix.net

Benjamin Renard [2018-02-17 23:05:30]
Migration to gogs.zionetrix.net
Filename
README
check_backuppc
check_backuppc_du
diff --git a/README b/README
new file mode 100644
index 0000000..28e2ae1
--- /dev/null
+++ b/README
@@ -0,0 +1,6 @@
+Repo migrated to https://gogs.zionetrix.net/bn8/check_backuppc :
+
+Git URLs :
+
+https://gogs.zionetrix.net/bn8/check_backuppc.git
+gogs@gogs.zionetrix.net:bn8/check_backuppc.git
diff --git a/check_backuppc b/check_backuppc
deleted file mode 100755
index b72f7fc..0000000
--- a/check_backuppc
+++ /dev/null
@@ -1,237 +0,0 @@
-#!/usr/bin/perl
-#
-# check_backuppc: a Nagios plugin to check the status of BackupPC
-#
-# Tested against BackupPC 3.2.1 and Nagios 3
-#   <http://backuppc.sourceforge.net>
-#   <http://nagios.org>
-#
-# AUTHORS
-#   Benjamin Renard  <brenard@easter-eggs.com>
-#
-# Fork from check_backuppc 1.1.0 write by Seneca Cunningham
-# <tetragon@users.sourceforge.net>.
-#
-# COPYRIGHT
-#   Copyright (C) 2013       Easter-eggs
-#
-#   This program 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 of the License, or
-#   (at your option) any later version.
-#
-#   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
-#
-
-use strict;
-no utf8;
-
-# Nagios
-use lib "/usr/lib/nagios/plugins";
-use utils qw(%ERRORS $TIMEOUT);
-use POSIX qw(strftime difftime);
-use Getopt::Long;
-Getopt::Long::Configure('bundling');
-
-# BackupPC
-use lib "/usr/share/backuppc/lib";
-use BackupPC::Lib;
-
-my $version = '1.1.2';
-my $warnDaysOld = 2;
-my $critDaysOld = 7;
-my $verbose = 0;
-my $opt_V = 0;
-my $opt_h = 0;
-my $goodOpt = 0;
-my @ownerOnly;
-my @hostsDesired;
-my @hostsExcluded;
-my %Status;
-my $statusCode = 'OK';
-my $ok_count = 0;
-my $unknown_count = 0;
-my $warning_count = 0;
-my $critical_count = 0;
-
-
-# Process options
-$goodOpt = GetOptions(
-	'v+' => \$verbose, 'verbose+' => \$verbose,
-	'c=f' => \$critDaysOld, 'critical=f' => \$critDaysOld,
-	'w=f' => \$warnDaysOld, 'warning=f' => \$warnDaysOld,
-	'o=s' => \@ownerOnly, 'owner=s' => \@ownerOnly,
-	'V' => \$opt_V, 'version' => \$opt_V,
-	'h' => \$opt_h, 'help' => \$opt_h,
-	'H=s' => \@hostsDesired, 'hostname=s' => \@hostsDesired,
-	'x=s' => \@hostsExcluded, 'exclude=s' => \@hostsExcluded);
-
-@hostsDesired = () if $#hostsDesired < 0;
-@hostsExcluded = () if $#hostsExcluded < 0;
-
-if ($opt_V)
-{
-	print "check_backuppc - " . $version . "\n";
-	exit $ERRORS{'OK'};
-}
-if ($opt_h or not $goodOpt)
-{
-	print "check_backuppc - " . $version . "\n";
-	print "A Nagios plugin to check on BackupPC backup status.\n\n";
-	print "Options:\n";
-	print "  --hostname,-H      only 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 "  --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 "  --verbose,-v       increase verbosity\n";
-	print "  --version,-V       display plugin version\n";
-	print "  --help,-h          display this message\n\n";
-	exit $ERRORS{'OK'} if $goodOpt;
-	exit $ERRORS{'UNKNOWN'};
-}
-if ($warnDaysOld > $critDaysOld)
-{
-	print("BACKUPPC UNKNOWN - Warning threshold must be <= critical\n");
-	exit $ERRORS{'UNKNOWN'};
-}
-
-# Connect to BackupPC
-my $server;
-if (!($server = BackupPC::Lib->new))
-{
-	print "BACKUPPC CRITICAL - Couldn't connect to BackupPC\n";
-	exit $ERRORS{'CRITICAL'};
-}
-my %Conf = $server->Conf();
-
-$server->ChildInit();
-
-my $err = $server->ServerConnect($Conf{ServerHost}, $Conf{ServerPort});
-if ($err)
-{
-	print("BACKUPPC UNKNOWN - Can't connect to server ($err)\n");
-	exit $ERRORS{'UNKNOWN'};
-}
-
-# query the BackupPC server for host status
-my $status_raw = $server->ServerMesg('status hosts');
-my $hosts_infos = $server->HostInfoRead();
-
-# undump the output... BackupPC uses Data::Dumper
-eval $status_raw;
-
-# check the dumped output
-my $hostCount = 0;
-
-foreach my $host (@hostsDesired, @hostsExcluded)
-{
-	if (not grep {/^$host$/} keys(%Status))
-	{
-		print("BACKUPPC UNKNOWN - Unknown host ($host)\n");
-		exit $ERRORS{'UNKNOWN'};
-	}
-}
-
-# host status checks
-foreach my $host (sort(keys(%Status)))
-{
-	next if $host =~ /^ /;
-	my $owner = $hosts_infos->{$host}->{user};
-	next if (@ownerOnly and not grep {/$owner/} @ownerOnly);
-	my %host_conf = %{$server->ConfigDataRead($host)};
-	$Status{$host}{BackupsDisable} = $host_conf{BackupsDisable};
-	next if ( $Status{$host}{BackupsDisable} );
-	next if (@hostsDesired and not grep {/^$host$/} @hostsDesired);
-	next if (@hostsExcluded and grep {/^$host$/} @hostsExcluded);
-	next if ($Status{$host}{'type'} eq 'archive');
-	$Status{$host}{'statusCode'} = 'OK';
-	$hostCount++;
-	# Debug
-	if ($verbose == 2)
-	{
-		print "Host $host state " . $Status{$host}{'state'} . "\n";
-		print "  with reason: " . $Status{$host}{'reason'} . "\n";
-		print "  with error: " . $Status{$host}{'error'} . "\n";
-		print "  with owner: $owner\n\n";
-	}
-	# Check host error
-	if ($Status{$host}{'error'})
-	{
-		$Status{$host}{statusMsg} = "error: ".$Status{$host}{'error'}." / ".$Status{$host}{'reason'};
-	} else {
-		$Status{$host}{statusMsg} = "status: ".$Status{$host}{'state'};
-	}
-
-	# Check last good backup time
-	$Status{$host}{'lastGoodBackupDays'} = difftime(time(), $Status{$host}{'lastGoodBackupTime'}) / (3600 * 24) if ( defined $Status{$host}{'lastGoodBackupTime'} );
-	if ( ! $Status{$host}{'lastGoodBackupDays'} ) {
-		$Status{$host}{'startDays'} = difftime(time(), $Status{$host}{'startTime'}) / (3600 * 24);
-		if ( $Status{$host}{'startDays'} > $critDaysOld ) {
-			$Status{$host}{statusMsg} .= ", no backups";
-			$Status{$host}{statusCode} = 'CRITICAL';
-			$statusCode = 'CRITICAL';
-		} elsif ( $Status{$host}{'startDays'} > $warnDaysOld ) {
-			$Status{$host}{statusMsg} .= ", no backups";
-			$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";
-	}
-	$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' );
-}
-
-
-my $statusMsg = "BACKUPPC $statusCode";
-
-if ( $statusCode eq 'OK' ) {
-	if ( $verbose && scalar(@hostsDesired) == 1 ) {
-		$statusMsg .= " (".$Status{$hostsDesired[0]}{statusMsg}.")";
-	} else {
-		$statusMsg .= " ($ok_count OK)";
-	}
-} else {
-	if ( $verbose ) {
-		$statusMsg .= " (";
-		my $first_host = 1;
-		foreach my $host ( keys %Status ) {
-			next if (@hostsDesired and not grep {/^$host$/} @hostsDesired);
-			next if (@hostsExcluded and grep {/^$host$/} @hostsExcluded);
-			next if ( $Status{$host}{BackupsDisable} );
-			next if ($Status{$host}{'type'} eq 'archive');
-			if ( $Status{$host}{statusCode} ne 'OK' ) {
-				$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)";
-	}
-}
-
-print "$statusMsg\n";
-exit $ERRORS{$statusCode};
diff --git a/check_backuppc_du b/check_backuppc_du
deleted file mode 100755
index 5935101..0000000
--- a/check_backuppc_du
+++ /dev/null
@@ -1,181 +0,0 @@
-#!/usr/bin/perl
-#
-# check_backuppc_du: a Nagios plugin to check the compressed disk usage of BackupPC hosts
-#
-# Tested against BackupPC 3.2.1 and Nagios 3
-#   <http://backuppc.sourceforge.net>
-#   <http://nagios.org>
-#
-# AUTHORS
-#   Benjamin Renard  <brenard@easter-eggs.com>
-#   Emmanuel Lacour  <elacour@easter-eggs.com>
-#
-# Fork from check_backuppc 1.1.0 write by Seneca Cunningham
-# <tetragon@users.sourceforge.net>.
-#
-# COPYRIGHT
-#   Copyright (C) 2014       Easter-eggs
-#
-#   This program 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 of the License, or
-#   (at your option) any later version.
-#
-#   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
-#
-
-use strict;
-no utf8;
-
-# Nagios
-use lib "/usr/lib/nagios/plugins";
-use utils qw(%ERRORS $TIMEOUT);
-use POSIX qw(strftime difftime);
-use Getopt::Long;
-Getopt::Long::Configure('bundling');
-
-# BackupPC
-use lib "/usr/share/backuppc/lib";
-use BackupPC::Lib;
-
-my $version = '1.0';
-# Default quota (GB)
-my $quota = 100;
-my $opt_V = 0;
-my $opt_h = 0;
-my $host;
-my @hostlist;
-my %Status;
-my $statusCode = 'OK';
-
-
-# Process options
-my $goodOpt = GetOptions(
-	'q=f' => \$quota, 'quota=f' => \$quota,
-	'V' => \$opt_V, 'version' => \$opt_V,
-	'h' => \$opt_h, 'help' => \$opt_h,
-	'H=s' => \$host, 'hostname=s' => \$host,
-	'L=s' => \@hostlist, 'hostlist=s' => \@hostlist,
-	);
-
-if ($opt_V)
-{
-	print "check_backuppc_du - " . $version . "\n";
-	exit $ERRORS{'OK'};
-}
-if ($opt_h or not $goodOpt)
-{
-	print "check_backuppc_du - " . $version . "\n";
-	print "A Nagios plugin to check on BackupPC backup status.\n\n";
-	print "Options:\n";
-	print "  --hostname,-H      perl regexp to match hostnames\n";
-	print "  --quota,-q         quota size (GB)\n";
-	print "  --version,-V       display plugin version\n";
-	print "  --help,-h          display this message\n\n";
-	exit $ERRORS{'OK'} if $goodOpt;
-	exit $ERRORS{'UNKNOWN'};
-}
-
-# Connect to BackupPC
-my $server;
-if (!($server = BackupPC::Lib->new))
-{
-	print "BACKUPPC CRITICAL - Couldn't connect to BackupPC\n";
-	exit $ERRORS{'CRITICAL'};
-}
-my %Conf = $server->Conf();
-
-$server->ChildInit();
-
-my $err = $server->ServerConnect($Conf{ServerHost}, $Conf{ServerPort});
-if ($err)
-{
-	print("BACKUPPC UNKNOWN - Can't connect to server ($err)\n");
-	exit $ERRORS{'UNKNOWN'};
-}
-
-# query the BackupPC server for host status
-my $status_raw = $server->ServerMesg('status hosts');
-my $hosts_infos = $server->HostInfoRead();
-
-# undump the output... BackupPC uses Data::Dumper
-eval $status_raw;
-
-# Allow hostname separeted by comma
-@hostlist = split(/,/,join(',',@hostlist));
-
-my $per_host_detail;
-my $total_usage = 0;
-my $total_count = 0;
-my $host_count = 0;
-foreach my $hostname ( sort(keys %Status) ) {
-
-	next if $hostname =~ /^\s*$/;
-	next if $hostname =~ /^ /;
-	next if ( $host && $hostname !~ m/$host/ );
-	next if ( scalar(@hostlist) > 0 && not ($hostname ~~ @hostlist) );
-
-	my %HostStatus = %{$Status{$hostname}};
-	my %host_conf = %{$server->ConfigDataRead($hostname)};
-	$HostStatus{BackupsDisable} = $host_conf{BackupsDisable};
-	next if ( $HostStatus{BackupsDisable} );
-	next if ($HostStatus{'type'} eq 'archive');
-
-	$host_count++;
-
-	# Backups
-	my @Backups = $server->BackupInfoRead($hostname);
-
-	# Get aggregate of compressed used size (octets)
-	my $full_size = 0;
-	my $backups_count = 0;
-	foreach my $Backup (sort {$Backups[$a]->{num} cmp $Backups[$b]->{num}} @Backups) {
-		if ( $full_size == 0 ) {
-			$full_size += $Backup->{sizeExistComp};
-			$full_size += $Backup->{sizeNewComp};
-		} else {
-			$full_size += $Backup->{sizeNewComp};
-		}
-		$backups_count++;
-	}
-
-	$total_usage += $full_size;
-	$total_count += $backups_count;
-
-	# Convert to Go
-	$full_size = sprintf("%0.2f", $full_size / 1024 / 1024 / 1024);
-
-	# Output size
-	$per_host_detail .= "$hostname: $backups_count backups / $full_size Go\n";
-}
-
-unless ( $host_count ) {
-	print "BACKUPPC UNKNOWN - no host matching $host\n";
-	exit $ERRORS{'UNKNOWN'};
-}
-
-$total_usage = sprintf("%0.2f", $total_usage / 1024 / 1024 / 1024);
-
-if ( $total_usage >= $quota ) {
-	print "BACKUPPC CRITICAL - $total_usage Go used / $quota Go allocated\n";
-	$statusCode = 'CRITICAL';
-} elsif ( $total_usage >= $quota * 0.90 ) {
-	print "BACKUPPC WARNING - $total_usage Go used / $quota Go allocated\n";
-	$statusCode = 'WARNING';
-} else {
-	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 $per_host_detail;
-
-
-exit $ERRORS{$statusCode};
-
ViewGit