* fixed logrotate problem
authorChristia Arnold
Tue, 01 Nov 2011 15:28:38 +0100
changeset 3 f36f557048be
parent 2 8a45104fe330
child 4 83a045204b8e
* fixed logrotate problem * fixed lintian errors and warnings
check_rsnapshot.pl
debian/changelog
debian/control
debian/rules
--- 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
 
--- a/debian/changelog	Wed Jun 15 13:39:14 2011 +0200
+++ b/debian/changelog	Tue Nov 01 15:28:38 2011 +0100
@@ -1,3 +1,9 @@
+nagios-plugin-rsnapshot (2.3) stable; urgency=low
+
+  * fixed logrotate problem
+
+ -- Christian Arnold <arnold@schlittermann.de>  Tue, 01 Nov 2011 15:00:48 +0100
+
 nagios-plugin-rsnapshot (2.2) lenny squeeze; urgency=low
 
   * add version function 
--- a/debian/control	Wed Jun 15 13:39:14 2011 +0200
+++ b/debian/control	Tue Nov 01 15:28:38 2011 +0100
@@ -3,11 +3,11 @@
 Priority: extra
 Maintainer: Christian Arnold <arnold@schlittermann.de>
 Build-Depends: debhelper (>= 7)
-Standards-Version: 3.7.3
+Standards-Version: 3.9.1
 
 Package: nagios-plugin-rsnapshot
 Architecture: all
-Depends: perl-base, perl-doc, libdate-manip-perl
+Depends: ${misc:Depends}, ${perl:Depends}, perl-doc, libdate-manip-perl
 Suggests: libsmart-comments-perl
 Description: nagios plugin to check rsnapshot
  This is a nagios plugin to check rsnapshot logfile.
--- a/debian/rules	Wed Jun 15 13:39:14 2011 +0200
+++ b/debian/rules	Tue Nov 01 15:28:38 2011 +0100
@@ -9,83 +9,5 @@
 # Uncomment this to turn on verbose mode.
 #export DH_VERBOSE=1
 
-
-
-
-
-configure: configure-stamp
-configure-stamp:
-	dh_testdir
-	# Add here commands to configure the package.
-
-	touch configure-stamp
-
-
-build: build-stamp
-
-build-stamp: configure-stamp  
-	dh_testdir
-
-	# Add here commands to compile the package.
-	$(MAKE)
-	#docbook-to-man debian/nagios-plugin-rsnapshot.sgml > nagios-plugin-rsnapshot.1
-
-	touch $@
-
-clean: 
-	dh_testdir
-	dh_testroot
-	rm -f build-stamp configure-stamp
-
-	# Add here commands to clean up after the build process.
-	$(MAKE) clean
-
-	dh_clean 
-
-install: build
-	dh_testdir
-	dh_testroot
-	dh_clean -k 
-	dh_installdirs
-
-	# Add here commands to install the package into debian/nagios-plugin-rsnapshot.
-	$(MAKE) DESTDIR=$(CURDIR)/debian/nagios-plugin-rsnapshot install
-
-
-# Build architecture-independent files here.
-binary-indep: build install
-# We have nothing to do by default.
-
-# Build architecture-dependent files here.
-binary-arch: build install
-	dh_testdir
-	dh_testroot
-	dh_installchangelogs 
-	dh_installdocs
-	dh_installexamples
-#	dh_install
-#	dh_installmenu
-#	dh_installdebconf	
-#	dh_installlogrotate
-#	dh_installemacsen
-#	dh_installpam
-#	dh_installmime
-#	dh_python
-#	dh_installinit
-#	dh_installcron
-#	dh_installinfo
-	dh_installman
-	dh_link
-	dh_strip
-	dh_compress
-	dh_fixperms
-#	dh_perl
-#	dh_makeshlibs
-	dh_installdeb
-	dh_shlibdeps
-	dh_gencontrol
-	dh_md5sums
-	dh_builddeb
-
-binary: binary-indep binary-arch
-.PHONY: build clean binary-indep binary-arch binary install configure
+%:
+	dh $@