diff -r f36f557048be -r 83a045204b8e check_rsnapshot.pl --- a/check_rsnapshot.pl Tue Nov 01 15:28:38 2011 +0100 +++ b/check_rsnapshot.pl Wed Nov 02 16:05:50 2011 +0100 @@ -38,7 +38,7 @@ sub version($$); my $ME = basename $0; -my $VERSION = "2.3"; +my $VERSION = "2.4"; my %opt = ( binary => "/usr/bin/rsnapshot", @@ -70,19 +70,21 @@ exit $ERRORS{CRITICAL}; } - if ( (localtime)[3] == 1 ) { - $opt{logfile} = "$opt{logfile}.1.gz"; - } + if ( (localtime)[3] == 1 || (localtime)[3] == 2 ) { + $opt{logfile} = "$opt{logfile}.1.gz"; + } if ( -z $opt{logfile} ) { print "RSNAPSHOT WARNING: logfile $opt{logfile} - has zero size\n"; exit $ERRORS{WARNING}; } - if ( ( time() - ( stat( $opt{logfile} ) )[9] ) > $opt{seconds} ) { - print + if ( !$opt{logfile} =~ /\.gz$/ ) { + if ( ( time() - ( stat( $opt{logfile} ) )[9] ) > $opt{seconds} ) { + print "RSNAPSHOT CRITICAL: logfile $opt{logfile} - last modification is longer than $opt{seconds} seconds ago\n"; - exit $ERRORS{CRITICAL}; + exit $ERRORS{CRITICAL}; + } } my $status = get_status( $opt{logfile} ); @@ -99,33 +101,37 @@ exit $ERRORS{CRITICAL}; } - 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 () { - 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 () { + 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"; @@ -213,7 +219,7 @@ =head1 VERSION -This man page is current for version 2.3 of check_rsnapshot. +This man page is current for version 2.4 of check_rsnapshot. =head1 AUTHOR