* fixed logrotate problem
authorChristia Arnold
Wed, 02 Nov 2011 16:05:50 +0100
changeset 4 83a045204b8e
parent 3 f36f557048be
child 5 8b0942b98040
* fixed logrotate problem
check_rsnapshot.pl
debian/changelog
--- 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 (<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";
@@ -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
 
--- a/debian/changelog	Tue Nov 01 15:28:38 2011 +0100
+++ b/debian/changelog	Wed Nov 02 16:05:50 2011 +0100
@@ -1,3 +1,9 @@
+nagios-plugin-rsnapshot (2.4) stable; urgency=low
+
+  * fixed logrotate problem 
+
+ -- Christian Arnold <arnold@schlittermann.de>  Wed, 02 Nov 2011 16:01:02 +0100
+
 nagios-plugin-rsnapshot (2.3) stable; urgency=low
 
   * fixed logrotate problem