[Logcheck-commits] r1617 - in logcheck/branches/zugschlus200707/src: . detectrotate

zugschlus at users.alioth.debian.org zugschlus at users.alioth.debian.org
Sat Jul 28 08:03:39 UTC 2007


Author: zugschlus
Date: 2007-07-28 08:03:39 +0000 (Sat, 28 Jul 2007)
New Revision: 1617

Added:
   logcheck/branches/zugschlus200707/src/detectrotate/
   logcheck/branches/zugschlus200707/src/detectrotate/10-savelog.dtr
   logcheck/branches/zugschlus200707/src/detectrotate/20-logrotate.dtr
   logcheck/branches/zugschlus200707/src/detectrotate/30-logrotate-dateext.dtr
Modified:
   logcheck/branches/zugschlus200707/src/logtail2
Log:
factor out rotated file detection into "include files"


Added: logcheck/branches/zugschlus200707/src/detectrotate/10-savelog.dtr
===================================================================
--- logcheck/branches/zugschlus200707/src/detectrotate/10-savelog.dtr	                        (rev 0)
+++ logcheck/branches/zugschlus200707/src/detectrotate/10-savelog.dtr	2007-07-28 08:03:39 UTC (rev 1617)
@@ -0,0 +1,12 @@
+#!/usr/bin/perl
+
+sub {
+  my ($filename) = @_;
+  my $rotated_filename="";
+  if (-e "$filename.0" && (mtime("$filename.0") > mtime("$filename.1.gz")) ) {
+    # assume the log is rotated by savelog(8)
+    # syslog-ng leaves old files here
+    $rotated_filename="$filename.0";
+  }
+  return $rotated_filename;
+}

Added: logcheck/branches/zugschlus200707/src/detectrotate/20-logrotate.dtr
===================================================================
--- logcheck/branches/zugschlus200707/src/detectrotate/20-logrotate.dtr	                        (rev 0)
+++ logcheck/branches/zugschlus200707/src/detectrotate/20-logrotate.dtr	2007-07-28 08:03:39 UTC (rev 1617)
@@ -0,0 +1,12 @@
+#!/usr/bin/perl
+
+sub {
+  my ($filename) = @_;
+  my $rotated_filename="";
+  if (-e "$filename.1") {
+    # assume the log is rotated by logrotate(8)
+    # should also probably check if file is still fresh
+    $rotated_filename="$filename.1";
+  }
+  return $rotated_filename;
+}

Added: logcheck/branches/zugschlus200707/src/detectrotate/30-logrotate-dateext.dtr
===================================================================
--- logcheck/branches/zugschlus200707/src/detectrotate/30-logrotate-dateext.dtr	                        (rev 0)
+++ logcheck/branches/zugschlus200707/src/detectrotate/30-logrotate-dateext.dtr	2007-07-28 08:03:39 UTC (rev 1617)
@@ -0,0 +1,12 @@
+#!/usr/bin/perl
+
+sub {
+  my ($filename) = @_;
+  my $rotated_filename="";
+  # find out whether we have a dateext rotation scheme
+  my @list = glob("$filename-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]");
+  if ( @list ) {
+    $rotated_filename = (sort(glob("$filename-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]")))[-1];
+  }
+  return $rotated_filename;
+}

Modified: logcheck/branches/zugschlus200707/src/logtail2
===================================================================
--- logcheck/branches/zugschlus200707/src/logtail2	2007-07-27 18:14:52 UTC (rev 1616)
+++ logcheck/branches/zugschlus200707/src/logtail2	2007-07-28 08:03:39 UTC (rev 1617)
@@ -108,25 +108,21 @@
     # function with dateext magic added.
     
     print "determine_rotated_logfile $filename $inode\n";
-    if (-e "$filename.0" && (mtime("$filename.0") > mtime("$filename.1.gz")) ) {
-        # assume the log is rotated by savelog(8)
-        # syslog-ng leaves old files here
-	print "savelog\n";
-	$rotated_filename="$filename.0";
-    } elsif (-e "$filename.1") {
-        # assume the log is rotated by logrotate(8)
-        # should also probably check if file is still fresh
-	print "logrotate\n";
-    	$rotated_filename="$filename.1";
+    for my $codefile (glob("/usr/share/logtail/detectrotate/*.dtr")) {
+        my $func = do $codefile;
+        if (!$func) {
+	    print STDERR "cannot compile $codefile: $!";
+	    exit 68;
+	}
+        $rotated_filename = $func->($filename);
+	last if $rotated_filename;
+    }
+    if ($rotated_filename) {
+      print "rotated_filename $rotated_filename (". inode($rotated_filename). ")\n";
     } else {
-	# find out whether we have a dateext rotation scheme
-	print "dateext $filename\n";
-	my @list = glob("$filename-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]");
-	print "glob ". join(".", @list). "\n";
-	$rotated_filename = (sort(glob("$filename-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]")))[-1];
+      print "no rotated file found\n";
     }
-    print "rotated_filename $rotated_filename (". inode($rotated_filename). ")\n";
-    if (inode($rotated_filename) == $inode) {
+    if ($rotated_filename && inode($rotated_filename) == $inode) {
       return $rotated_filename;
     } else {
       return "";




More information about the Logcheck-commits mailing list