This file is indexed.

/usr/lib/xymon/client/ext/backuppc is in hobbit-plugins 20141201.

This file is owned by root:root, with mode 0o755.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
#!/usr/bin/perl -w

# a Hobbit/Xymon plugin to check the status of BackupPC
#
# Based on http://n-backuppc.cvs.sf.net/viewvc/n-backuppc/check_backuppc/check_backuppc?revision=1.21
#
# Tested against BackupPC 2.1.2 and 3.1.0
#   <http://backuppc.sourceforge.net>
#
# Copyright (C) 2006, 2007 Seneca Cunningham <tetragon@users.sourceforge.net>
# Copyright (C) 2011 Axel Beckert <abe@debian.org>
#
#   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
#

my $config = "/etc/backuppc/TODO";
use strict;
use lib '/usr/share/backuppc/lib/';
use BackupPC::Lib;
use Hobbit;

$ENV{'PATH'} = '/bin:/sbin:/usr/bin:/usr/sbin';
$ENV{'LC_ALL'} = 'C';
delete @ENV{'IFS', 'CDPATH', 'ENV', 'BASH_ENV'};

my $bb = new Hobbit({ test => 'bkpc', dont_moan => 1});

#no utf8;

my %ERRORS = ( OK => 0,
	       UNKNOWN => 1,
	       WARNING => 1,
	       CRITICAL => 2 );

use POSIX qw(strftime difftime);
use Getopt::Long;
Getopt::Long::Configure('bundling');

# BackupPC
my $version = '1.1.0';
my $warnLevel = 0;
my $daysOld = 7;
my $verbose = 1;
my $opt_V = 0;
my $opt_h = 0;
my $goodOpt = 0;
my $reduce = 0;
my $backupOnly = 0;
my $archiveOnly = 0;
my $statusOnly = 0;
my @hostsDesired;
my @hostsExcluded;

# Process options
$goodOpt = GetOptions(
	'v+' => \$verbose, 'verbose+' => \$verbose,
	'c=f' => \$daysOld, 'critical=f' => \$daysOld,
	'w=f' => \$warnLevel, 'warning=f' => \$warnLevel,
	'V' => \$opt_V, 'version' => \$opt_V,
	'h' => \$opt_h, 'help' => \$opt_h,
	'r=i' => \$reduce, 'reduce' => \$reduce,
	'b' => \$backupOnly, 'backup-only' => \$backupOnly,
	'a' => \$archiveOnly, 'archive-only' => \$archiveOnly,
	's' => \$statusOnly, 'status-only' => \$statusOnly,
	'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 ($backupOnly and $archiveOnly)
{
	$goodOpt = 0;
	print "Cannot apply both --backup-only and --archive-only, contradictory\n\n";
}
if ($opt_h or not $goodOpt)
{
	print "check_backuppc - " . $version . "\n";
	print "A Hobbit 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 "  --archive-only,-a  only check the archive hosts\n";
	print "  --backup-only,-b   only check the backup hosts\n";
	print "  --status-only,-s   only check backup status, omit connection failures that are\n";
	print "                     less than \$Conf{FullPeriod} old\n";
	print "  --warning,-w       days old an errored host must be to cause a warning\n";
	print "  --critical,-c      number of days old an errored backup must be to be critical\n";
	print "  --reduce,-r        maximum number of failed hosts for severity reduction\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 ($warnLevel > $daysOld)
{
	$bb->color_line('red', "CONFIGURATION ERROR - Warning threshold must be <= critical\n");
}

# Connect to BackupPC
my $server;
if (!($server = BackupPC::Lib->new))
{
	$bb->color_line('red', "Couldn't connect to BackupPC\n");
	$bb->send;
	exit $ERRORS{'CRITICAL'};
}
my %Conf = $server->Conf();

$server->ChildInit();

my $err = $server->ServerConnect($Conf{ServerHost}, $Conf{ServerPort});
if ($err)
{
	$bb->color_line('red', "Can't connect to server ($err)\n");
	$bb->send;
	exit $ERRORS{'UNKNOWN'};
}

# hashes that BackupPC uses for varios status info
my %Status;
my %Jobs;
my %Info;

# query the BackupPC server for host, job, and server info
my $info_raw = $server->ServerMesg('status info');
my $jobs_raw = $server->ServerMesg('status jobs');
my $status_raw = $server->ServerMesg('status hosts');

# undump the output... BackupPC uses Data::Dumper
eval $info_raw;
eval $jobs_raw;
eval $status_raw;

# check the dumped output
my $hostCount = 0;
my @goodHost;
my @badHost;
my @tooOld;
my @notTooOld;

# host status checks
foreach my $host (sort(keys(%Status)))
{
	next if $host =~ /^ /;
	next if (@hostsDesired and not grep {/$host/} @hostsDesired);
	next if (@hostsExcluded and grep {/$host/} @hostsExcluded);
	next if ($backupOnly and $Status{$host}{'type'} eq 'archive');
	next if ($archiveOnly and $Status{$host}{'type'} ne 'archive');
	$hostCount++;
	# Debug
	if ($verbose == 3)
	{
		$bb->print("Host $host state " . $Status{$host}{'state'});
		$bb->print(" with error: " . $Status{$host}{'error'} . "\n");
	}
	if ($Status{$host}{'error'})
	{
		# Check connectivity errors with greater care
		if ($statusOnly && (
		    $Status{$host}{'error'} eq 'ping too slow' ||
		    $Status{$host}{'error'} eq 'no ping response' ||
		    $Status{$host}{'error'} eq 'host not found')) {
			if ($Status{$host}{'lastGoodBackupTime'} - $Status{$host}{'startTime'} <= $Conf{FullPeriod} * 3600 * 24) {
				push @goodHost, $host;
				next;
			}
		}
		push @badHost, $host;
		# Check bad host ages
		$Status{$host}{'lastGoodBackupTime'} = $Status{$host}{'startTime'} if (not $Status{$host}{'lastGoodBackupTime'});
		if (difftime(time(), $Status{$host}{'lastGoodBackupTime'}) > ($daysOld * 3600 * 24))
		{
			push @tooOld, $host;
		}
		elsif (difftime(time(), $Status{$host}{'lastGoodBackupTime'}) > ($warnLevel * 3600 * 24))
		{
			push @notTooOld, $host;
		}
		else
		{
			push @goodHost, $host;
			pop @badHost;
		}
		# Debug
		if ($verbose == 2)
		{
			$bb->print("Host $host state " . $Status{$host}{'state'});
			$bb->print(" with error: " . $Status{$host}{'error'} . "\n");
		}
	}
	else
	{
		push @goodHost, $host;
	}
}

if ($hostCount == @goodHost or $#badHost < $reduce and not @tooOld)
{
	$bb->color_line('green', "BackupPC OK - (" . @badHost . "/" . $hostCount . ") failures\n");
	&list_unknown_hosts;
	$bb->send;
	exit $ERRORS{'OK'};
}

&list_unknown_hosts;

# Only failures reach this far
# WARNING
if ($#tooOld < 0 or $#badHost < $reduce)
{
	#print "BACKUPPC WARNING - (";
	if ($verbose)
	{
		foreach my $host (@badHost)
		{
			$bb->color_line('yellow', $host . " (" . $Status{$host}{'error'} . ")\n");
		}
		#print ")\n";
	}
	else
	{
		$bb->color_line('yellow', $#badHost + 1  . "/" . $hostCount . ") failures\n");
	}
	$bb->send;
	exit $ERRORS{'WARNING'};
}

# CRITICAL
#print "BACKUPPC CRITICAL - (";
if ($#notTooOld >= 0 and $verbose)
{
	foreach my $host (@notTooOld)
	{
		$bb->color_line('red', $host . " (" . $Status{$host}{'error'} . ")\n");
	}
	#print "), (";
}
if ($verbose)
{
	foreach my $host (@tooOld)
	{
		$bb->color_line('red', $host . " (" . $Status{$host}{'error'} . ")\n");
	}
	#print ") critical\n";
}
else
{
	$bb->print($#badHost + 1 . "/" . $hostCount . ") failures, ");
	$bb->print(print $#tooOld + 1 . " critical\n");
}
$bb->send;
exit $ERRORS{'CRITICAL'};

sub list_unknown_hosts {
    foreach my $host (@hostsDesired, @hostsExcluded)
    {
	if (not grep {/$host/} keys(%Status))
	{
		$bb->color_line('clear', "Host expected but not configured ($host)\n");
		#exit $ERRORS{'UNKNOWN'};
	}
    }
}