--- a/check_rsnapshot.pl Wed Jun 15 13:39:14 2011 +0200
+++ b/check_rsnapshot.pl Tue Nov 01 15:28:38 2011 +0100
@@ -20,6 +20,7 @@
use strict;
use File::Basename;
use Getopt::Long;
+use Compress::Zlib;
use Date::Manip;
use Pod::Usage;
use if $ENV{DEBUG} => "Smart::Comments";
@@ -37,7 +38,7 @@
sub version($$);
my $ME = basename $0;
-my $VERSION = "2.2";
+my $VERSION = "2.3";
my %opt = (
binary => "/usr/bin/rsnapshot",
@@ -69,6 +70,10 @@
exit $ERRORS{CRITICAL};
}
+ if ( (localtime)[3] == 1 ) {
+ $opt{logfile} = "$opt{logfile}.1.gz";
+ }
+
if ( -z $opt{logfile} ) {
print "RSNAPSHOT WARNING: logfile $opt{logfile} - has zero size\n";
exit $ERRORS{WARNING};
@@ -94,17 +99,33 @@
exit $ERRORS{CRITICAL};
}
- open( FH, $logfile )
- or print "RSNAPSHOT CRITICAL: $logfile - $!\n" and exit $ERRORS{CRITICAL};
- while (<FH>) {
- next unless (/^\[$date/);
- if (/^\[$date:.*ERROR/) {
- $error = $_;
- last;
- }
- $found_date = 1;
- }
- close(FH);
+ if ($logfile =~ /\.gz$/) {
+ my $gz = gzopen($logfile, "rb")
+ or print "RSNAPSHOT CRITICAL: Cannot open $logfile: $gzerrno\n" and exit $ERRORS{CRITICAL};
+ while ($gz->gzreadline($_) > 0) {
+ next unless (/^\[$date/);
+ if (/^\[$date:.*ERROR/) {
+ $error = $_;
+ last;
+ }
+ $found_date = 1;
+ }
+ print "RSNAPSHOT CRITICAL: Error reading from $logfile: $gzerrno\n" and exit $ERRORS{CRITICAL}
+ if $gzerrno != Z_STREAM_END;
+ $gz->gzclose();
+ } else {
+ open( FH, $logfile )
+ or print "RSNAPSHOT CRITICAL: $logfile - $!\n" and exit $ERRORS{CRITICAL};
+ while (<FH>) {
+ next unless (/^\[$date/);
+ if (/^\[$date:.*ERROR/) {
+ $error = $_;
+ last;
+ }
+ $found_date = 1;
+ }
+ close(FH);
+ }
unless ($found_date) {
$error = "can't find rsnapshot run from [$date]\n";
@@ -192,7 +213,7 @@
=head1 VERSION
-This man page is current for version 2.2 of check_rsnapshot.
+This man page is current for version 2.3 of check_rsnapshot.
=head1 AUTHOR