0

How does one go about including rsnapshot's log file in logwatch's configuration?

Logwatch is software that will parse logs and check for important information and email it to someone. How can one have logwatch look over rsnapshot's log file.

1
  • 2
    As a general rule, being rude to the people doing their best to help keep the site useful is not going to improve your chances of getting your question reopened. The "how to ask page" (serverfault.com/help/how-to-ask) is linked in the On Hold-reason. If you do want the question reopened, it would be nice if you'd read the page and then consider what could be done to actually improve the question. (Hint: Further accusations of self-importance are not it.)
    – Jenny D
    Feb 7, 2014 at 8:41

1 Answer 1

2

Some files must be created in order for the rsnapshot.log file to be included in the logwatch report. Examples for Debian are below.

Edited: Recently, a patch was submitted to the logwatch mailing list that added support for rsnapshot. The files below have been udpated to reflect that.

/etc/logwatch/conf/logfiles/rsnapshot.conf

# rsnapshot backup tool logfile

# default logfile location (relative to /var/log)
# don't forget to change this if changed in /etc/rsnapshot.conf
LogFile = rsnapshot.log
Archive = rsnapshot.log.*.gz

# parse & remove date tag
*ApplyStdDate = "\[%d/%b/%Y:%H:%M:%S\]"
*RemoveHeaders = "\[\d\d/\w{3}/\d{4}:\d\d:\d\d:\d\d\] "

/etc/logwatch/conf/services/rsnapshot.conf

# rsnapshot backup tool service

# just one logfile format
LogFile = rsnapshot

Title = "rsnapshot"

/etc/logwatch/scripts/services/rsnapshot

#!/usr/bin/perl

# rsnapshot backup tool log parsing script
# Hayden Lau, July 2016

use strict;
my $Debug = $ENV{'LOGWATCH_DEBUG'} || 0;
my $Detail = $ENV{'LOGWATCH_DETAIL_LEVEL'} || 0;
my %Error;
my %Warning;
my %Started;
my %Successful;
my %OtherList;

while (defined(my $ThisLine = <STDIN>)) {
   chomp($ThisLine);
   if ($Debug) {
      print "$ThisLine\n";
   }
   if ($ThisLine =~ /ERROR: (\N+)/) {
      $Error{$1}++;
   } elsif ($ThisLine =~ /WARNING: (\N+)/) {
      $Warning{$1}++;
   } elsif ($ThisLine =~ / (\S+): started/) {
      $Started{$1}++;
   } elsif ($ThisLine =~ / (\S+): completed successfully/) {
      $Successful{$1}++;
   } else {
      $OtherList{$ThisLine}++;
   }
}

if (keys %Error) {
   print "ERRORS:\n";
   foreach my $line (sort {$a cmp $b} keys %Error) {
      print "    $line: $Error{$line} Time(s)\n";
   }
}

if (keys %Warning) {
   print "Warnings:\n";
   foreach my $line (sort {$a cmp $b} keys %Warning) {
      print "    $line: $Warning{$line} Time(s)\n";
   }
}

if (($Detail > 5) and keys %Started) {
   print "Started:\n";
   foreach my $retain (sort { $Started{$b} <=> $Started{$a} } keys %Started) {
      print "    $retain: $Started{$retain} Time(s)\n";
   }
}

if ($Detail and keys %Successful) {
   print "Completed Successfully:\n";
   foreach my $retain (sort { $Successful{$b} <=> $Successful{$a} } keys Successful) {
      print "    $retain: $Successful{$retain} Time(s)\n";
   }
}

if (keys %OtherList) {
   print "\n**Unmatched Entries**\n";
   foreach my $line (sort {$a cmp $b} keys %OtherList) {
      print "    $line: $OtherList{$line} Time(s)\n";
   }
}

exit(0);

Not the answer you're looking for? Browse other questions tagged .