develooper Front page | perl.beginners | Postings from January 2002

Parsing log file line entries

Thread Next
From:
Robin Brown
Date:
January 17, 2002 07:39
Subject:
Parsing log file line entries
Message ID:
005901c19f6b$c14b2910$0bb0a8c0@rbrown
Hi,
 
I have a perl script that came with SNIPS network monitoring that takes
lines of a log file and parses them to create variables to be used to
send pager alerts.  It works as I like until I want to add that last
variable, then it completely breaks.
 
Log file line ( This is all on one line if the log):
Sun Jul 26 01:37:03 1998 [ippingmon]: \
DEVICE Test-Device xxx.xxx.xxx.xxx VAR ICMP-ping 0 3 Pkts \
LEVEL Critical LOGLEVEL Critical STATE down
 
Working version (without STATE):
 
if ($#ARGV >= 0) { $PAGETO = $ARGV[0]; }
 
while (<STDIN>)
{
 
if(/.+\[(\S+)\]:\s+SITE|DEVICE\s+(\S+.+)\s+LEVEL\s+(\S+)\s+LOGLEVEL\s+(\
S+)\s+
..+$/)
  {
    # print "Sender=$1, Device=$2, Level=$3, Loglevel=$4
    next if ($3 =~ /Info/ || /Critical/);
      &sendmail2 ($1,$2,$3,$4,$MAILTO) ;
  }
}
 
 
Non working version trying to add the STATE: if ($#ARGV >= 0) { $PAGETO
= $ARGV[0]; }
 
if ($#ARGV >= 0) { $PAGETO = $ARGV[0]; }
 
while (<STDIN>)
{
 
if(/.+\[(\S+)\]:\s+SITE|DEVICE\s+(\S+.+)\s+LEVEL\s+(\S+)\s+LOGLEVEL\s+(\
S+)\s+
STATE\s+(\S+.+)\s+.+$/)
  {
    # print "Sender=$1, Device=$2, Level=$3, Loglevel=$4, State=$5
    next if ($4 =~ /Info/ || /Critical/);
      &sendmail2 ($1,$2,$3,$4,$5,$MAILTO) ;
  }
}
 
 
 
 
 

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About