Vous êtes sur la page 1sur 3

#!

/usr/bin/perl
###############################################################################
#
# Component : readtailfile.pl
# Description : Read/tails a file.
# Prerequistes : 1. Version 5.004 or above of Per
l.
# :
#
# Creation Date : Jul 2008
# Original Author : Craig Lister (HNIT)
# Source : /usr/local/script/readta
ilfil.pl
#
###############################################################################
#
# Version 1.00 Craig Lister 11/07/2008
# Read/tails a file.
#
################################################################################
###
use Postemsg;
use Sys::Hostname;
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst);
my $datetime = &loct();
my($minpastmidnight) = $hour * 60 + $min;

my ($Gmon, $Gday, $psappdumpdirs, $finishbytes);


my $oprdir ="/home/db2inst1/sqllib/db2dump";
my $targetfile = "db2diag.log";
my $logfile = "$oprdir/$targetfile";
my $flagfile = "$oprdir/TivoliFlag_$targetfile.LOG";
my $minpastmidnighttarget1 = -1;
my $minpastmidnighttarget2 = 1441; # Run all the time
my $evtcount;

my ($id_string) = 'readtailfile';
my ($hostname);
my $local_host=hostname();
my $logsdirfile = "/var/esm/logs/DBG$targetfile";
#my @matchlines = (error, exception, deadlock, timeout);
my @matchlines = ('ADM7009E An error was encountered in the "TCPIP" protocol su
pport');
if (($minpastmidnight > $minpastmidnighttarget1) && ($minpastmidnight < $minpast
midnighttarget2)) {
open (DBG, ">>$logsdirfile");
print DBG "$datetime Begin run +++++++++++++++++++++++++++++++++++++++++
++++++++++++++++\n";
}else {
open (DBG, ">>$logsdirfile");
print DBG "$datetime Not run as its out of application running hours\n";
close DBG;
exit 0;
}
if (open (FLG ,"<$flagfile")) {
while (<FLG>) {
$seekbytes = $_;
}
close FLG;
}else {
$seekbytes = 0;
}
print DBG "$datetime Monitoring file $logfile seeking $seekbytes\n";
if (open (TGT ,"<$logfile")) {
$evtcount = 0;
my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
$atime,$mtime,$ctime,$blksize,$blocks) = stat TGT;
if ($size < $seekbytes) {
$seekbytes = 0;
print DBG "$datetime Seekbytes is larger that file size, seekbyt
es set to zero\n";
}
seek TGT, $seekbytes, 0;
while (<TGT>) {
$matchee = $_;
foreach $matcher (@matchlines) {
print DBG "$datetime Line is $matchee testing for $matcher\n";
if ($matchee =~ m/$matcher/gi) {
$datetime = &loct();
&sendevt($matchee,$matcher);
last;
}
}
}
$finishbytes = tell TGT ;
close TGT;
open (FLG ,">$flagfile");
print FLG "$finishbytes\n";
close FLG;
}else {
print DBG "$datetime File $logfile cannot be opened\n";
}
print DBG "\n$datetime No of events sent is $evtcount\n";
close DBG;
exit 0;
# E N D O F M A I N L I N E
sub loct {
#####################
#Define the localtime
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
$mon = $mon+1;
if (length $mday < 2) { $mday="0".$mday; } # Add a "0" to the front if len
<2
if (length $mon < 2) { $mon="0".$mon; } # This is required as the localtime
fn
if (length $hour < 2) { $hour="0".$hour; } # doesn't prefix single digit f
ields
if (length $min < 2) { $min="0".$min; } # with a "0".
if (length $sec < 2) { $sec="0".$sec; }
$Gmon = $mon;
$Gday = $mday;
my $datetime=(($year+1900)."-".$mon."-".$mday." ".$hour.":".$min.":".$sec);
return $datetime;
}
sub sendevt {
#############
my ($sematchee,$sematcher) = @_;
$evtcount+=1;
chomp $sematchee;
print DBG "$datetime ----->line $sematchee found in $logfile containing
$sematcher\n";
$msg = Postemsg->new('aucftec01'); # Set th
e server hostname
$msg->setClass('SummaryLogCountHigh');
# Set a valid class name and
$msg->setAdapter('LOGFILE');
# Set a valid adapter name
$msg->setMessage("$numerrors errors of $errorseverity from $appname foun
d in $logfile");
$msg->setSeverity("$severity");
$msg->setSlotValue('hostname',"$local_host");
$msg->setSlotValue('situation_displayitem',"\'$appname/$errorseverity/$n
umerrors\'");
$msg->sendMessage();
return;
}

Vous aimerez peut-être aussi