Amanda-Users

Re: putting error warnings into seperate mail

2006-05-11 09:46:07
Subject: Re: putting error warnings into seperate mail
From: Paul Bijnens <paul.bijnens AT xplanation DOT com>
To: listrcv <listrcv AT condor-werke DOT com>
Date: Thu, 11 May 2006 15:41:27 +0200
On 2006-05-11 13:17, listrcv wrote:

You already insert blank lines to indicate sections. Would it be difficult to send each section seperately instead?

The "blank lines" are actually just a single FormFeed character,
that some MUA display as many blank lines.

The problem with deciding about the errors is more difficult when
you look closer.

- Some people leave the tape drive empty on purpose, and when enough
dumps are collected in the holdingdisk, they insert the tape, and all
the dumps get autoflushed to tape.

- Some people have laptops in their disklist, and "results missing"
is normal for those PC's.  However, results missing on your production
file server is very important.

- Many people have "file changed as we read it" warnings, and most of
these are harmless.  But sometimes NOT.
That's why I extended my list of reg.expressions to suppress those
warnings only for particular files only.

- Samba complains about a lot of files, most of which can be safely
ignored.  But missing the outlook.pst file for a complete month is
not good.  And if you don't even get a warning...

So, implementing this inside Amanda for general use is difficult.
Implementing a filter in perl for your own use should be easy enough.
Use that program as the MAILER program instead and do what you like
inside.  The program is called as  "prog -s 'subject' recipients".
Then use this program as mailer:
  make distclean
  MAILER=/usr/local/bin/mymailer; export MAILER
  ./configure --with-user=...  ...


Untested "mymailer" program, which duplicates sections of the mail:


#!/usr/bin/perl

my $MAILPROG = "/usr/bin/Mail";
my @ADM = ( 'me AT example DOT com', 'me_too AT example DOT com' );

use Getopt::Std;
getopt('s:');
   # $opt_s now contains the original subject
   # @ARGV now contains the recipients

my $errormail = "";

undef($/);
my $mail = <STDIN>;  # slurp whole file
my ($overview, @sections) =  split(/\f/, $mail);
my $nostats = $overview;
$nostats =~ s/^STATISTICS.*//ms;        # Throw away statistics

$error++  if ($nostats =~ /\*\*\*.*ERROR/);     # Some tape error?
$error++  if ($nostats =~ /^  saturn /);        # host is important!

$errormail .= $nostats  if $error;

foreach my $section (@sections) {
    if ($section =~ /FAILED AND STRANGE DUMP DETAILS/) {
        # Do something sensible with the section
        # Here I just add the FAILED section to the error report
        $errormail .= "\f" . $section;
    }
}

# The special short error mail with only errors to the ADMins
if ($error  &&  $errormail ne "") {
   my $subject = "Please fix these Amanda Problems ASAP!";
   # open(M, "| $MAILPROG -s '$subject' @ADM")    # in perl 5.6 or later
   open(M, "|-", $MAILPROG, "-s", $subject, @ADM) # only perl 5.8
        ||  die("open mailer: $!\n");
   print M $errormail;
   close(M)  ||  die("mailer: $!\n");
}

# Send the normal mail
open(M, "|-", $MAILPROG, "-s", $opt_s, @ARGV)
    ||  die("open mailer: $!\n");
print M $mail;
close(M)  ||  die("mailer: $!\n");
exit(0);


--
Paul Bijnens, xplanation Technology Services        Tel  +32 16 397.511
Technologielaan 21 bus 2, B-3001 Leuven, BELGIUM    Fax  +32 16 397.512
http://www.xplanation.com/          email:  Paul.Bijnens AT xplanation DOT com
***********************************************************************
* I think I've got the hang of it now:  exit, ^D, ^C, ^\, ^Z, ^Q, ^^, *
* F6, quit, ZZ, :q, :q!, M-Z, ^X^C, logoff, logout, close, bye, /bye, *
* stop, end, F3, ~., ^]c, +++ ATH, disconnect, halt,  abort,  hangup, *
* PF4, F20, ^X^X, :D::D, KJOB, F14-f-e, F8-e,  kill -1 $$,  shutdown, *
* init 0, kill -9 1, Alt-F4, Ctrl-Alt-Del, AltGr-NumLock, Stop-A, ... *
* ...  "Are you sure?"  ...   YES   ...   Phew ...   I'm out          *
***********************************************************************