Blame SOURCES/logwatch-journald.patch

a8c837
3 upstreamed patches.
a8c837
a8c837
Resolves: #1504984
a8c837
a8c837
From 63c05d4ea2f90fd54770d2487e9d18ee8c77823d Mon Sep 17 00:00:00 2001
a8c837
From: bjorn <bjorn1@users.sourceforge.net>
a8c837
Date: Sun, 15 May 2016 13:45:33 -0700
a8c837
Subject: [PATCH] - Initialized hostlimit variable to default empty string. -
a8c837
 Allow the use of /dev/null as logfile.
a8c837
a8c837
---
a8c837
 scripts/logwatch.pl | 5 +++--
a8c837
 1 file changed, 3 insertions(+), 2 deletions(-)
a8c837
a8c837
diff --git a/scripts/logwatch.pl b/scripts/logwatch.pl
a8c837
index 6fcb5cb..0f863dc 100755
a8c837
--- a/scripts/logwatch.pl
a8c837
+++ b/scripts/logwatch.pl
a8c837
@@ -93,6 +93,7 @@ $Config{'encode'} = "none"; #8.0
a8c837
 $Config{'hostformat'} = "none"; #8.0
a8c837
 $Config{'html_wrap'} = 80;
a8c837
 $Config{'supress_ignores'} = 0;
a8c837
+$Config{'hostlimit'} = "";
a8c837
 
a8c837
 if (-e "$ConfigDir/conf/html/header.html") {
a8c837
    $Config{'html_header'} = "$ConfigDir/conf/html/header.html";
a8c837
@@ -778,8 +779,8 @@ foreach $LogFile (@LogFileList) {
a8c837
    my $FileText = "";
a8c837
 
a8c837
    foreach my $ThisFile (@FileList) {
a8c837
-      #Existence check for files -mgt
a8c837
-      next unless (-f $ThisFile);
a8c837
+      #Existence check for files and character devices such as /dev/null
a8c837
+      next unless (-f $ThisFile || -c $ThisFile );
a8c837
       if ($ThisFile =~ /'/) {
a8c837
          print "File $ThisFile has invalid embedded quotes.  File ignored.\n";
a8c837
 	 next;
a8c837
-- 
a8c837
2.14.0
a8c837
a8c837
From 23e714ad43285d59c5b5852ef2c6013593d64671 Mon Sep 17 00:00:00 2001
a8c837
From: bjorn <bjorn1@users.sourceforge.net>
a8c837
Date: Sun, 15 May 2016 13:49:08 -0700
a8c837
Subject: [PATCH] [journalctl] Added shared script contributed by Mark Grimes.
a8c837
a8c837
---
a8c837
 scripts/shared/journalctl | 83 +++++++++++++++++++++++++++++++++++++++++++++++
a8c837
 1 file changed, 83 insertions(+)
a8c837
 create mode 100755 scripts/shared/journalctl
a8c837
a8c837
diff --git a/scripts/shared/journalctl b/scripts/shared/journalctl
a8c837
new file mode 100755
a8c837
index 0000000..1627fd4
a8c837
--- /dev/null
a8c837
+++ b/scripts/shared/journalctl
a8c837
@@ -0,0 +1,83 @@
a8c837
+#!/usr/bin/perl
a8c837
+#
a8c837
+# The purpose of this script is to pass the output of the journalctl
a8c837
+# command to the logwatch parsers.  The corresponding conf/logfile 
a8c837
+# can be simple.  The following example shows a logfile with two lines:
a8c837
+# LogFile = /dev/null
a8c837
+# *JournalCtl = "--output=cat --unit=service_name.service"
a8c837
+#
a8c837
+# In the example above, the arguments to the JournalCtl command are
a8c837
+# passed to the journalctl system command.  It is advised to delimit
a8c837
+# the arguments in double quotes to preserve mixed case, if
a8c837
+# applicable.
a8c837
+
a8c837
+use strict;
a8c837
+use warnings;
a8c837
+
a8c837
+eval "use Date::Manip";
a8c837
+my $hasDM = $@ ? 0 : 1;
a8c837
+
a8c837
+# logwatch passes arguments as one string delimited by single quotes
a8c837
+my @args  = split(" ", $ARGV[0]);
a8c837
+my @range = get_range( $ENV{LOGWATCH_DATE_RANGE} );
a8c837
+
a8c837
+my $Debug = $ENV{'LOGWATCH_DEBUG'} || 0;
a8c837
+
a8c837
+if ($Debug > 5) {
a8c837
+   warn join " ", 'journalctl', @args, @range, "\n";
a8c837
+}
a8c837
+
a8c837
+system( 'journalctl', @args, @range );
a8c837
+
a8c837
+sub get_range {
a8c837
+    my $range = lc( shift || 'all' );
a8c837
+    my @range;
a8c837
+
a8c837
+    if ( !$range || $range eq 'all' ) {
a8c837
+        @range = ();
a8c837
+    } elsif ( $range eq 'yesterday' ) {
a8c837
+        push @range, '--since', 'yesterday', '--until', 'today';
a8c837
+    } elsif ( $range eq 'today' ) {
a8c837
+        push @range, '--since', 'today', '--until', 'tomorrow';
a8c837
+    } elsif ($hasDM) {
a8c837
+
a8c837
+        # Strip off any period
a8c837
+        $range =~
a8c837
+          s/for\s+(?:those|that|this)\s+((year|month|day|hour|minute|second)s?)\s*$//;
a8c837
+
a8c837
+        # Look for between x and y
a8c837
+        my ( $range1, $range2 ) =
a8c837
+          ( $range =~ /^between\s+(.*)\s+and\s+(.*)\s*$/ );
a8c837
+
a8c837
+        # Look for since x
a8c837
+        if ( $range =~ /^\s*since\s+/ ) {
a8c837
+            ($range1) = ( $range =~ /\s*since\s+(.*)/ );
a8c837
+            $range2 = "now";
a8c837
+        }
a8c837
+
a8c837
+        # Now convert to journalctl friendly dates
a8c837
+        if ( $range1 && $range2 ) {
a8c837
+
a8c837
+            # Parse dates
a8c837
+            my $date1 = ParseDate($range1);
a8c837
+            my $date2 = ParseDate($range2);
a8c837
+
a8c837
+            # Switch if date2 is before date1
a8c837
+            if ( $date1 && $date2 and Date_Cmp( $date1, $date2 ) > 0 ) {
a8c837
+                my $switch_date = $date1;
a8c837
+                $date1 = $date2;
a8c837
+                $date2 = $switch_date;
a8c837
+            }
a8c837
+
a8c837
+            # If we ask for 1/1 to 1/2, we mean 1/2 inclusive. DM returns
a8c837
+            # 1/2 00:00:00. So we add 1 day to the end time.
a8c837
+            $date2 = DateCalc( $date2, '1 day' );
a8c837
+
a8c837
+            my $fmt = "%Y-%m-%d %H:%M:%S";
a8c837
+            push @range, '--since', UnixDate( $date1, $fmt ), '--until',
a8c837
+              UnixDate( $date2, $fmt );
a8c837
+        }
a8c837
+    }
a8c837
+
a8c837
+    return @range;
a8c837
+}
a8c837
-- 
a8c837
2.14.0
a8c837
a8c837
Cherry picked from commit ed6eb62f40cb97f71f3df4d982682de68cdf1037.
a8c837
Related: #1504984
a8c837
a8c837
diff --git a/scripts/services/syslog-ng b/scripts/services/syslog-ng
a8c837
--- a/scripts/services/syslog-ng
a8c837
+++ b/scripts/services/syslog-ng
a8c837
@@ -163,7 +163,8 @@ while (defined($ThisLine = <STDIN>)) {
a8c837
          } elsif ($processed[$i] eq "destination") {
a8c837
             $Stats_dest{$processed[$i+1]} = 
a8c837
                $Stats_dest{$processed[$i+1]} + $processed[$i+2];
a8c837
-	      } elsif ($processed[$i] eq "source" || $processed[$i] eq "src.internal") {
a8c837
+	      } elsif ($processed[$i] eq "source" || $processed[$i] eq "src.internal" ||
a8c837
+                  $processed[$i] eq "src.journald") {
a8c837
             $Stats_source{$processed[$i+1]} = 
a8c837
                $Stats_source{$processed[$i+1]} + $processed[$i+2];
a8c837
          } elsif ($processed[$i] eq "global") {
a8c837
@@ -359,7 +360,7 @@ if (keys %Stats_center || keys %Stats_de
a8c837
 
a8c837
    if ($Stats_center{received} && %Stats_source) {
a8c837
       $lost_rcvd = 0 - $Stats_center{received};
a8c837
-      map { $lost_rcvd = $lost_rcvd + $Stats_source{$_} } keys %Stats_source;
a8c837
+      map { $lost_rcvd = $lost_rcvd + $Stats_source{$_} unless ($_ =~ /journal/); } keys %Stats_source;
a8c837
    }
a8c837
    if ($Stats_center{queued} && %Stats_dest) {
a8c837
       $lost_dest = $Stats_center{queued};
a8c837