: # -*- perl -*- eval "exec perl -S $0 $*" if $running_under_some_shell; #===================================================================== # errreporter - mails interesting entries from the AIX error log #===================================================================== use strict; use File::Basename; use Getopt::Std; my ($me, $hostname, %opts, $conf, $email, @ignore, $min, $hour, $day, +$mon, $year, $starttime, $identifier, $timestamp, $resource, $descriptio +n, $ignore, @error); $me = basename($0); chomp ($hostname = `/usr/bin/hostname`); getopts('hulf:', \%opts); if ($opts{h} || $opts{u}) { exec "perldoc $0" }; if ($opts{l}) { exec '/usr/bin/errpt', '-t' or die "$me: couldn't exec 'errpt -t'\n +" }; if ($opts{f}) { $conf = $opts{f} }; # if no conf file specified, use "/etc/errreporter.conf as # the default ... unless ($conf) { $conf = "/etc/errreporter.conf" }; eval `cat $conf 2> /dev/null` or die "$me: couldn't read specified conf file $conf\n"; unless (defined ($email)) { die "$me: email not defined " } # add the errpt header line to the ignore list ... push (@ignore, "IDENTIFIER"); # get the current time, in the form used by the errpt command ... (undef, $min, $hour, $day, $mon, $year) = localtime(time); $mon++; $min = sprintf("%02d", $min); $hour = sprintf("%02d", $hour); $day = sprintf("%02d", $day); $mon = sprintf("%02d", $mon); $year = sprintf("%02d", $year % 100); $starttime = "$mon"."$day"."$hour"."$min"."$year"; print STDOUT "$me: starting errreporter at $starttime, using conf file + $conf.\n"; # open an errpt process, reading the summary of errors posted # after the start time of this script ... open (ERRPT, "/usr/bin/errpt -c -s $starttime |") or die "$me: couldn't open errpt for reading: $!"; # while the above process is open ... while (<ERRPT>) { 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 entry in the array @error ... @error = `/usr/bin/errpt -a -s $timestamp`; # add a subject line to the @error array ... unshift (@error, "Subject: $hostname -- $resource -- $descript +ion\n"); # and send the e-mail ... open (SENDMAIL, "|/usr/sbin/sendmail $email") or die "$me: couldn't open sendmail: $!"; print SENDMAIL @error; close (SENDMAIL); }; }; #===================================================================== =pod =head1 NAME errreporter - e-mails interesting entries from the AIX error log =head1 SYNOPSIS B<errreporter> [B<-h | -u>] B<errreporter> [B<-l>] B<errreporter> B<-f> conffile =head1 DESCRIPTION I<errreporter> 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<errreporter> program, displaying this documen +tation. =item B<-l> Execs "errpt -t", which displays the error template summaries. This i +s useful when creating the "ignore" list of errors that you don't want to recei +ve e-mail for. =item B<-f conffile> Uses the specified file as the configuration file. If this flag is no +t specified, the default of I<"/etc/errreporter.conf"> is used. =back =head1 CONFIGURATION I<errreporter> uses a configuration file for the setting of two option +s: the e-mail address to mail errors to, and the list of errors that should be ignor +ed. Because the configuration file is "sourced" by the I<errreporter> 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 err +or identifiers that I<errreporter> should not send mail for. =back =head1 AUTHOR Sandor W. Sklar ssklar@stanford.edu =cut
# errreporter.conf # configuration file for errreporter program # -------------------------------------------------------------------- # this file is "sourced" by the perl script errreporter, so it must # use proper perl syntax. #===================================================================== # -------------------------------------------------------------------- # $email - set the variable e-mail to the address that errpt entries # are to be mailed to. NOTE that the at-sign ("@") MUST be # protected by a backslah. I.e., ... # # $email = "foo\@bar.com"; # -------------------------------------------------------------------- $email = "foo\@bar.com"; # -------------------------------------------------------------------- # @ignore - the array ignore contains a list of the errlog entry # identifiers that should NOT be mailed to the above e-mail # address. A full listing of all of the identifiers can be # generated by running the errreporter command with the # "-l" flag, or by running "errpt -t". # -------------------------------------------------------------------- @ignore = ( "C6ACA566", # MESSAGE REDIRECTED # FROM SYSLOG "D1E21BA3", # LOG FILE EXPANDED # TO REQUESTED SIZE "C60BB505", # SOFTWARE PROGRAM # ABNORMALLY TERMINATED # (core dump) "9DBCFDEE", # ERROR LOGGING TURNED ON "192AC071", # ERROR LOGGING TURNED OFF ); #=====================================================================
In reply to stop me from embarrassing myself by blueflashlight
For: | Use: | ||
& | & | ||
< | < | ||
> | > | ||
[ | [ | ||
] | ] |