: # -*- perl -*- eval "exec perl -S $0 $*" if $running_under_some_shell; #===================================================================== # errreporter - Mails interesting entries in the AIX error log # -------------------------------------------------------------------- # $Id: errreporter,v 1.8 2004/09/28 05:15:24 ssklar Exp ssklar $ #===================================================================== use strict; use File::Basename; use Getopt::Std; require 5.6.0; # these are the variables that we're gonna use ... my ($me, $hostname, $conf, $email, @ignore, $min, $hour, $day, $mon, $year, $starttime, $identifier, $timestamp, $resource, $description, $ignore, @error); # get the name of this program ... $me = basename($0); # get the name of this system ... chomp ($hostname = `/usr/bin/hostname`); # get the command-line options ... getopts('hulf:'); our ($opt_h, $opt_u, $opt_l, $opt_f); # if "-h" or "-u" specfied, show help/usage ... if ($opt_h || $opt_u) { exec "perldoc $0" }; # if "-l" specified, show the errpt template entries ... if ($opt_l) { exec "/usr/bin/errpt -t" }; # if "-f file" specified, use file as the conf file ... if ($opt_f) { $conf = $opt_f }; # if no conf file specified, use "/etc/errreporter.conf if it # exists, if not, try "/usr/local/etc/errreporter.conf", and if # that doesn't exist, die. if ( ($conf) && (-f $conf) ) { 1; } elsif ( -f "/etc/errreporter.conf" ) { $conf = "/etc/errreporter.conf" } elsif ( -f "/usr/local/etc/errreporter.conf" ) { $conf = "/usr/local/etc/errreporter.conf" } else { die "$me: no conf file specified, or found in the the default locations.\n" }; print STDERR "$me: using conf file $conf\n"; # read in the configuration file ... eval `cat $conf`; # die if an e-mail address wasn't defined ... unless (defined ($email)) { die "$me: email not defined " } # add the errpt header line to the ignore list ... push (@ignore, "IDENTIFIER"); # get the start time of this script, in the form of an # argument passable to the errpt command ... my $starttime = sprintf '%02d%02d%02d%02d%02d', sub { $_[4]+1, $_[3], $_[2], $_[1], $_[5] % 100 } -> (localtime); # open an errpt process for reading, with the starttime specified ... open (ERRPT, "/usr/bin/errpt -c -s $starttime |") or die "$me: couldn't open errpt for reading: $!"; # while the above process is open ... while () { chomp; # split the errpt entry into fields ... ($identifier, $timestamp, undef, undef, $resource, $description) = split (/\s+/, $_, 6); $ignore = "no"; foreach (@ignore) { # check to see if the entry is on the ignore list ... if ($identifier =~ /$_/) { $ignore = "yes"; last } }; unless ($ignore =~ /yes/) { # store the full error in the array @error ... @error = `/usr/bin/errpt -a -s $timestamp -N $resource -j $identifier`; # add a subject line to the @error array ... unshift (@error, "Subject: $hostname -- $resource -- $description\n"); # open a sendmail process for writing ... open (SENDMAIL, "|/usr/sbin/sendmail $email") or die "$me: couldn't open sendmail: $!"; # and print the error message to sendmail ... print SENDMAIL @error; close (SENDMAIL); }; }; #===================================================================== =pod =head1 NAME errreporter - Mails interesting entries in the AIX error log =head1 SYNOPSIS B [B<-h | -u>] B [B<-l>] B B<-f> conffile =head1 DESCRIPTION I monitors the AIX error log, checks if new error entries are listed in a configurable "ignore" list, and e-mails the error in detailed format to a specified address. -head1 OPTIONS =over 5 =item B<-h | -u> Execs "perldoc" on the I program, displaying this documentation. =item B<-l> Execs "errpt -t", which displays the error template summaries. This is useful when creating the "ignore" list of errors that you don't want to receive e-mail for. =item B<-f conffile> Uses the specified file as the configuration file. If this flag is not specified, errreporter will first look for I<"/etc/errreporter.conf">, and then I<"/usr/local/etc/errreporter.conf">, and failing that, will die. =back =head1 CONFIGURATION I uses a configuration file for the setting of two options: the e-mail address to mail errors to, and the list of errors that should be ignored. Because the configuration file is "sourced" by the I program, it must follow proper perl syntax. The two options are: =over 5 =item B<$email = "you\@your.address";> Set the variable $email to the the email address that will receive the error log entries. Don't forget to backslash the at-sign, and end the line with a semi-colon. =item B<@ignore = ("IDENTIFIER1", "IDENTIFIER2", ...);> Set the array variable @ignore to a comma-separated quoted list of error identifiers that I should not send mail for. =back =head1 AUTHOR Sandor W. Sklar =cut # $Log: errreporter,v $ # Revision 1.8 2004/09/28 05:15:24 ssklar # added hostname back into the subject of the emails being sent out # # Revision 1.7 2004/09/28 05:10:46 ssklar # fixed dumb error. # # Revision 1.6 2004/09/28 04:50:10 ssklar # Changed default location of conf file; if not specified, script will look in /etc and then in /usr/local/etc. # # Revision 1.5 2001/08/19 03:26:13 ssklar # added parameters to the 'errpt -a ...' command so that multiple entries will not be sent in a single e-mail # # Revision 1.4 2001/02/22 04:59:36 ssklar # *** empty log message *** # # Revision 1.2.1.1 2001/02/22 04:54:24 ssklar # added "require 5.6.0" # # Revision 1.2 2001/02/22 04:35:43 ssklar # changed hash-bang line to the "exec perl" thingie # # Revision 1.1 2001/02/21 20:09:09 ssklar # Initial revision #