Migration to gogs.zionetrix.net
Benjamin Renard

Benjamin Renard commited on 2018-02-17 23:05:30
Showing 3 changed files, with 6 additions and 418 deletions.

... ...
@@ -0,0 +1,6 @@
1
+Repo migrated to https://gogs.zionetrix.net/bn8/check_backuppc :
2
+
3
+Git URLs :
4
+
5
+https://gogs.zionetrix.net/bn8/check_backuppc.git
6
+gogs@gogs.zionetrix.net:bn8/check_backuppc.git
... ...
@@ -1,237 +0,0 @@
1
-#!/usr/bin/perl
2
-#
3
-# check_backuppc: a Nagios plugin to check the status of BackupPC
4
-#
5
-# Tested against BackupPC 3.2.1 and Nagios 3
6
-#   <http://backuppc.sourceforge.net>
7
-#   <http://nagios.org>
8
-#
9
-# AUTHORS
10
-#   Benjamin Renard  <brenard@easter-eggs.com>
11
-#
12
-# Fork from check_backuppc 1.1.0 write by Seneca Cunningham
13
-# <tetragon@users.sourceforge.net>.
14
-#
15
-# COPYRIGHT
16
-#   Copyright (C) 2013       Easter-eggs
17
-#
18
-#   This program is free software; you can redistribute it and/or modify
19
-#   it under the terms of the GNU General Public License as published by
20
-#   the Free Software Foundation; either version 2 of the License, or
21
-#   (at your option) any later version.
22
-#
23
-#   This program is distributed in the hope that it will be useful,
24
-#   but WITHOUT ANY WARRANTY; without even the implied warranty of
25
-#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
26
-#   GNU General Public License for more details.
27
-#
28
-#   You should have received a copy of the GNU General Public License
29
-#   along with this program; if not, write to the Free Software
30
-#   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
31
-#
32
-
33
-use strict;
34
-no utf8;
35
-
36
-# Nagios
37
-use lib "/usr/lib/nagios/plugins";
38
-use utils qw(%ERRORS $TIMEOUT);
39
-use POSIX qw(strftime difftime);
40
-use Getopt::Long;
41
-Getopt::Long::Configure('bundling');
42
-
43
-# BackupPC
44
-use lib "/usr/share/backuppc/lib";
45
-use BackupPC::Lib;
46
-
47
-my $version = '1.1.2';
48
-my $warnDaysOld = 2;
49
-my $critDaysOld = 7;
50
-my $verbose = 0;
51
-my $opt_V = 0;
52
-my $opt_h = 0;
53
-my $goodOpt = 0;
54
-my @ownerOnly;
55
-my @hostsDesired;
56
-my @hostsExcluded;
57
-my %Status;
58
-my $statusCode = 'OK';
59
-my $ok_count = 0;
60
-my $unknown_count = 0;
61
-my $warning_count = 0;
62
-my $critical_count = 0;
63
-
64
-
65
-# Process options
66
-$goodOpt = GetOptions(
67
-	'v+' => \$verbose, 'verbose+' => \$verbose, 
68
-	'c=f' => \$critDaysOld, 'critical=f' => \$critDaysOld,
69
-	'w=f' => \$warnDaysOld, 'warning=f' => \$warnDaysOld,
70
-	'o=s' => \@ownerOnly, 'owner=s' => \@ownerOnly,
71
-	'V' => \$opt_V, 'version' => \$opt_V,
72
-	'h' => \$opt_h, 'help' => \$opt_h,
73
-	'H=s' => \@hostsDesired, 'hostname=s' => \@hostsDesired,
74
-	'x=s' => \@hostsExcluded, 'exclude=s' => \@hostsExcluded);
75
-
76
-@hostsDesired = () if $#hostsDesired < 0;
77
-@hostsExcluded = () if $#hostsExcluded < 0;
78
-
79
-if ($opt_V)
80
-{
81
-	print "check_backuppc - " . $version . "\n";
82
-	exit $ERRORS{'OK'};
83
-}
84
-if ($opt_h or not $goodOpt)
85
-{
86
-	print "check_backuppc - " . $version . "\n";
87
-	print "A Nagios plugin to check on BackupPC backup status.\n\n";
88
-	print "Options:\n";
89
-	print "  --hostname,-H      only check the specified host\n";
90
-	print "  --exclude,-x       do not check the specified host\n";
91
-	print "  --owner,-o         do only hosts of specified user\n";
92
-	print "  --warning,-w       days old of last good backup to cause a warning\n";
93
-	print "  --critical,-c      days old of last good backup to be critical\n";
94
-	print "  --verbose,-v       increase verbosity\n";
95
-	print "  --version,-V       display plugin version\n";
96
-	print "  --help,-h          display this message\n\n";
97
-	exit $ERRORS{'OK'} if $goodOpt;
98
-	exit $ERRORS{'UNKNOWN'};
99
-}
100
-if ($warnDaysOld > $critDaysOld)
101
-{
102
-	print("BACKUPPC UNKNOWN - Warning threshold must be <= critical\n");
103
-	exit $ERRORS{'UNKNOWN'};
104
-}
105
-
106
-# Connect to BackupPC
107
-my $server;
108
-if (!($server = BackupPC::Lib->new))
109
-{
110
-	print "BACKUPPC CRITICAL - Couldn't connect to BackupPC\n";
111
-	exit $ERRORS{'CRITICAL'};
112
-}
113
-my %Conf = $server->Conf();
114
-
115
-$server->ChildInit();
116
-
117
-my $err = $server->ServerConnect($Conf{ServerHost}, $Conf{ServerPort});
118
-if ($err)
119
-{
120
-	print("BACKUPPC UNKNOWN - Can't connect to server ($err)\n");
121
-	exit $ERRORS{'UNKNOWN'};
122
-}
123
-
124
-# query the BackupPC server for host status
125
-my $status_raw = $server->ServerMesg('status hosts');
126
-my $hosts_infos = $server->HostInfoRead();
127
-
128
-# undump the output... BackupPC uses Data::Dumper
129
-eval $status_raw;
130
-
131
-# check the dumped output
132
-my $hostCount = 0;
133
-
134
-foreach my $host (@hostsDesired, @hostsExcluded)
135
-{
136
-	if (not grep {/^$host$/} keys(%Status))
137
-	{
138
-		print("BACKUPPC UNKNOWN - Unknown host ($host)\n");
139
-		exit $ERRORS{'UNKNOWN'};
140
-	}
141
-}
142
-
143
-# host status checks
144
-foreach my $host (sort(keys(%Status)))
145
-{
146
-	next if $host =~ /^ /;
147
-	my $owner = $hosts_infos->{$host}->{user};
148
-	next if (@ownerOnly and not grep {/$owner/} @ownerOnly);
149
-	my %host_conf = %{$server->ConfigDataRead($host)};
150
-	$Status{$host}{BackupsDisable} = $host_conf{BackupsDisable};
151
-	next if ( $Status{$host}{BackupsDisable} );
152
-	next if (@hostsDesired and not grep {/^$host$/} @hostsDesired);
153
-	next if (@hostsExcluded and grep {/^$host$/} @hostsExcluded);
154
-	next if ($Status{$host}{'type'} eq 'archive');
155
-	$Status{$host}{'statusCode'} = 'OK';
156
-	$hostCount++;
157
-	# Debug
158
-	if ($verbose == 2)
159
-	{
160
-		print "Host $host state " . $Status{$host}{'state'} . "\n";
161
-		print "  with reason: " . $Status{$host}{'reason'} . "\n";
162
-		print "  with error: " . $Status{$host}{'error'} . "\n";
163
-		print "  with owner: $owner\n\n";
164
-	}
165
-	# Check host error
166
-	if ($Status{$host}{'error'})
167
-	{
168
-		$Status{$host}{statusMsg} = "error: ".$Status{$host}{'error'}." / ".$Status{$host}{'reason'};
169
-	} else {
170
-		$Status{$host}{statusMsg} = "status: ".$Status{$host}{'state'};
171
-	}
172
-
173
-	# Check last good backup time
174
-	$Status{$host}{'lastGoodBackupDays'} = difftime(time(), $Status{$host}{'lastGoodBackupTime'}) / (3600 * 24) if ( defined $Status{$host}{'lastGoodBackupTime'} );
175
-	if ( ! $Status{$host}{'lastGoodBackupDays'} ) {
176
-		$Status{$host}{'startDays'} = difftime(time(), $Status{$host}{'startTime'}) / (3600 * 24);
177
-		if ( $Status{$host}{'startDays'} > $critDaysOld ) {
178
-			$Status{$host}{statusMsg} .= ", no backups";
179
-			$Status{$host}{statusCode} = 'CRITICAL';
180
-			$statusCode = 'CRITICAL';
181
-		} elsif ( $Status{$host}{'startDays'} > $warnDaysOld ) {
182
-			$Status{$host}{statusMsg} .= ", no backups";
183
-			$Status{$host}{statusCode} = 'WARNING' unless ( $Status{$host}{statusCode} = 'CRITICAL' );
184
-			$statusCode = 'WARNING' unless ( $statusCode eq 'CRITICAL' );
185
-		}
186
-	} elsif ( $Status{$host}{'lastGoodBackupDays'} > $critDaysOld )
187
-	{
188
-		$Status{$host}{statusMsg} .= ", last good backup have ".sprintf("%.1f", $Status{$host}{'lastGoodBackupDays'})." days";
189
-		$Status{$host}{statusCode} = 'CRITICAL';
190
-		$statusCode = 'CRITICAL';
191
-	} 
192
-	elsif ( $Status{$host}{'lastGoodBackupDays'} > $warnDaysOld )
193
-	{
194
-		$Status{$host}{statusMsg} .= ", last good backup have ".sprintf("%.1f",$Status{$host}{'lastGoodBackupDays'})." days";
195
-		$Status{$host}{statusCode} = 'WARNING' unless ( $Status{$host}{statusCode} = 'CRITICAL' );
196
-		$statusCode = 'WARNING' unless ( $statusCode eq 'CRITICAL' );
197
-	} else {
198
-		$Status{$host}{statusMsg} .= ", last good backup have ".sprintf("%.1f",$Status{$host}{'lastGoodBackupDays'})." days";
199
-	}
200
-	$ok_count++ if ( $Status{$host}{statusCode} eq 'OK' );
201
-	$unknown_count++ if ( $Status{$host}{statusCode} eq 'UNKNOWN' );
202
-	$warning_count++ if ( $Status{$host}{statusCode} eq 'WARNING' );
203
-	$critical_count++ if ( $Status{$host}{statusCode} eq 'CRITICAL' );
204
-}
205
-
206
-
207
-my $statusMsg = "BACKUPPC $statusCode";
208
-
209
-if ( $statusCode eq 'OK' ) {
210
-	if ( $verbose && scalar(@hostsDesired) == 1 ) {
211
-		$statusMsg .= " (".$Status{$hostsDesired[0]}{statusMsg}.")";
212
-	} else {
213
-		$statusMsg .= " ($ok_count OK)";
214
-	}
215
-} else {
216
-	if ( $verbose ) {
217
-		$statusMsg .= " (";
218
-		my $first_host = 1;
219
-		foreach my $host ( keys %Status ) {
220
-			next if (@hostsDesired and not grep {/^$host$/} @hostsDesired);
221
-			next if (@hostsExcluded and grep {/^$host$/} @hostsExcluded);
222
-			next if ( $Status{$host}{BackupsDisable} );
223
-			next if ($Status{$host}{'type'} eq 'archive');
224
-			if ( $Status{$host}{statusCode} ne 'OK' ) {
225
-				$statusMsg .= ", " unless ( $first_host );
226
-				$statusMsg .= "$host: ".$Status{$host}{statusCode}." - ".$Status{$host}{statusMsg};
227
-				$first_host = 0 if ( $first_host );
228
-			}
229
-		}
230
-		$statusMsg .= ")";
231
-	} else {
232
-		$statusMsg .= " ( $ok_count OK, $unknown_count UNKNOWN, $warning_count WARNING, $critical_count CRITICAL)";
233
-	}
234
-}
235
-
236
-print "$statusMsg\n";
237
-exit $ERRORS{$statusCode};
... ...
@@ -1,181 +0,0 @@
1
-#!/usr/bin/perl
2
-#
3
-# check_backuppc_du: a Nagios plugin to check the compressed disk usage of BackupPC hosts
4
-#
5
-# Tested against BackupPC 3.2.1 and Nagios 3
6
-#   <http://backuppc.sourceforge.net>
7
-#   <http://nagios.org>
8
-#
9
-# AUTHORS
10
-#   Benjamin Renard  <brenard@easter-eggs.com>
11
-#   Emmanuel Lacour  <elacour@easter-eggs.com>
12
-#
13
-# Fork from check_backuppc 1.1.0 write by Seneca Cunningham
14
-# <tetragon@users.sourceforge.net>.
15
-#
16
-# COPYRIGHT
17
-#   Copyright (C) 2014       Easter-eggs
18
-#
19
-#   This program is free software; you can redistribute it and/or modify
20
-#   it under the terms of the GNU General Public License as published by
21
-#   the Free Software Foundation; either version 2 of the License, or
22
-#   (at your option) any later version.
23
-#
24
-#   This program is distributed in the hope that it will be useful,
25
-#   but WITHOUT ANY WARRANTY; without even the implied warranty of
26
-#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
27
-#   GNU General Public License for more details.
28
-#
29
-#   You should have received a copy of the GNU General Public License
30
-#   along with this program; if not, write to the Free Software
31
-#   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
32
-#
33
-
34
-use strict;
35
-no utf8;
36
-
37
-# Nagios
38
-use lib "/usr/lib/nagios/plugins";
39
-use utils qw(%ERRORS $TIMEOUT);
40
-use POSIX qw(strftime difftime);
41
-use Getopt::Long;
42
-Getopt::Long::Configure('bundling');
43
-
44
-# BackupPC
45
-use lib "/usr/share/backuppc/lib";
46
-use BackupPC::Lib;
47
-
48
-my $version = '1.0';
49
-# Default quota (GB)
50
-my $quota = 100;
51
-my $opt_V = 0;
52
-my $opt_h = 0;
53
-my $host;
54
-my @hostlist;
55
-my %Status;
56
-my $statusCode = 'OK';
57
-
58
-
59
-# Process options
60
-my $goodOpt = GetOptions(
61
-	'q=f' => \$quota, 'quota=f' => \$quota,
62
-	'V' => \$opt_V, 'version' => \$opt_V,
63
-	'h' => \$opt_h, 'help' => \$opt_h,
64
-	'H=s' => \$host, 'hostname=s' => \$host,
65
-	'L=s' => \@hostlist, 'hostlist=s' => \@hostlist,
66
-	);	
67
-
68
-if ($opt_V)
69
-{
70
-	print "check_backuppc_du - " . $version . "\n";
71
-	exit $ERRORS{'OK'};
72
-}
73
-if ($opt_h or not $goodOpt)
74
-{
75
-	print "check_backuppc_du - " . $version . "\n";
76
-	print "A Nagios plugin to check on BackupPC backup status.\n\n";
77
-	print "Options:\n";
78
-	print "  --hostname,-H      perl regexp to match hostnames\n";
79
-	print "  --quota,-q         quota size (GB)\n";
80
-	print "  --version,-V       display plugin version\n";
81
-	print "  --help,-h          display this message\n\n";
82
-	exit $ERRORS{'OK'} if $goodOpt;
83
-	exit $ERRORS{'UNKNOWN'};
84
-}
85
-
86
-# Connect to BackupPC
87
-my $server;
88
-if (!($server = BackupPC::Lib->new))
89
-{
90
-	print "BACKUPPC CRITICAL - Couldn't connect to BackupPC\n";
91
-	exit $ERRORS{'CRITICAL'};
92
-}
93
-my %Conf = $server->Conf();
94
-
95
-$server->ChildInit();
96
-
97
-my $err = $server->ServerConnect($Conf{ServerHost}, $Conf{ServerPort});
98
-if ($err)
99
-{
100
-	print("BACKUPPC UNKNOWN - Can't connect to server ($err)\n");
101
-	exit $ERRORS{'UNKNOWN'};
102
-}
103
-
104
-# query the BackupPC server for host status
105
-my $status_raw = $server->ServerMesg('status hosts');
106
-my $hosts_infos = $server->HostInfoRead();
107
-
108
-# undump the output... BackupPC uses Data::Dumper
109
-eval $status_raw;
110
-
111
-# Allow hostname separeted by comma
112
-@hostlist = split(/,/,join(',',@hostlist));
113
-
114
-my $per_host_detail;
115
-my $total_usage = 0;
116
-my $total_count = 0;
117
-my $host_count = 0;
118
-foreach my $hostname ( sort(keys %Status) ) {
119
-
120
-	next if $hostname =~ /^\s*$/;
121
-	next if $hostname =~ /^ /;
122
-	next if ( $host && $hostname !~ m/$host/ );
123
-	next if ( scalar(@hostlist) > 0 && not ($hostname ~~ @hostlist) );
124
-
125
-	my %HostStatus = %{$Status{$hostname}};
126
-	my %host_conf = %{$server->ConfigDataRead($hostname)};
127
-	$HostStatus{BackupsDisable} = $host_conf{BackupsDisable};
128
-	next if ( $HostStatus{BackupsDisable} );
129
-	next if ($HostStatus{'type'} eq 'archive');
130
-
131
-	$host_count++;
132
-
133
-	# Backups
134
-	my @Backups = $server->BackupInfoRead($hostname);
135
-
136
-	# Get aggregate of compressed used size (octets)
137
-	my $full_size = 0;
138
-	my $backups_count = 0;
139
-	foreach my $Backup (sort {$Backups[$a]->{num} cmp $Backups[$b]->{num}} @Backups) {
140
-		if ( $full_size == 0 ) {
141
-			$full_size += $Backup->{sizeExistComp};
142
-			$full_size += $Backup->{sizeNewComp};
143
-		} else {
144
-			$full_size += $Backup->{sizeNewComp};
145
-		}
146
-		$backups_count++;
147
-	}
148
-
149
-	$total_usage += $full_size;
150
-	$total_count += $backups_count;
151
-
152
-	# Convert to Go
153
-	$full_size = sprintf("%0.2f", $full_size / 1024 / 1024 / 1024);
154
-
155
-	# Output size
156
-	$per_host_detail .= "$hostname: $backups_count backups / $full_size Go\n";
157
-}
158
-
159
-unless ( $host_count ) {
160
-	print "BACKUPPC UNKNOWN - no host matching $host\n";
161
-	exit $ERRORS{'UNKNOWN'};
162
-}
163
-
164
-$total_usage = sprintf("%0.2f", $total_usage / 1024 / 1024 / 1024);
165
-
166
-if ( $total_usage >= $quota ) {
167
-	print "BACKUPPC CRITICAL - $total_usage Go used / $quota Go allocated\n";
168
-	$statusCode = 'CRITICAL';
169
-} elsif ( $total_usage >= $quota * 0.90 ) {
170
-	print "BACKUPPC WARNING - $total_usage Go used / $quota Go allocated\n";
171
-	$statusCode = 'WARNING';
172
-} else {
173
-	print "BACKUPPC OK - $total_usage Go used / $quota Go allocated\n";
174
-}
175
-
176
-print "Total of $total_count backups with cumulative compressed size of $total_usage Go for $host_count active hosts\n";
177
-print $per_host_detail;
178
-
179
-
180
-exit $ERRORS{$statusCode};
181
-
182 0