I have been at this for 3 days now and cant for the life of me work out why the code is piping out errors
Th input into the code for sake of simplicity as i think the rest of my errors are essentially the same thing is:
Expand|Select|Wrap|Line Numbers
- Dec 16 07:50:22 xxxx-vpn-xxx 1765156 12/16/2007 07:50:21.110 SEV=6 IKEDBG/64 RPT=183939 10.100.250.100 IKE Peer included IKE fragmentation capability flags: Main Mode: True Aggressive Mode: False
Use of uninitialized value in concatenation (.) or string at parser.pl line 62.
at parser.pl line 62
Use of uninitialized value in concatenation (.) or string at parser.pl line 64.
at parser.pl line 64
Now i know this means that a value wasn't declared or explicitly stated but i cant see how this is possible as i give them all the value 'null' when i declare them and then these null values are changed where necessary,
Before in the
Expand|Select|Wrap|Line Numbers
- if ($currentIP eq $sessionIP){ }
Expand|Select|Wrap|Line Numbers
- if($currentCode=~ m/(IKEDBG\/64)|(IKE\/52)|.....|(IKE\/49)|(IKE\/75)/){
This is just a snippet so it probably wont compile if you would like more please dont hesitate to ask
Expand|Select|Wrap|Line Numbers
- #!/usr/bin/perl-w
- #-w use warnings
- #-T use Taint to ensure program is secure
- use strict; #Force variable declarations
- # Functions to locate errors
- use Carp ();
- local $SIG{__WARN__} = \&Carp::cluck;
- #=== Delcare Varibles ===#
- my $line = undef; #Line to be processed
- my $file = 'testLog.txt'; #Path to log file
- my @log = undef; #Stores lines from log file
- # Session Data Array as global (to avoid un-neccesary processing when passed into function)
- our @sessions = (
- # Session Data Holding Variables
- {'clientIPAddress' => undef, #Address assigned from IP pool
- 'currentCode' => 'Initialiser',#Current IKE code being processed
- 'connectDate' => 'null', #Date of connection to access point
- 'connectTime' => 'null', #Time of connection to access point
- 'userID' => 'null', #Username unique to user
- 'authenticationTime' => 'null', #Time user's has been authenticated
- 'groupID' => 'null', #VPN group user belongs to (usually Roamnet)
- 'platformType' => 'null', #Platform user is running Windows, Unix etc..
- 'clientVersion' => 'null', #Version of VPN client
- 'vpnPoolAddress' => 'null', #IP address assigned from VPN pool
- 'disconnectTime' => 'null', #Time session was disconnected
- 'duration' => 'null', #Duration of session
- 'bytesTx' => 'null', #Bytes Transmitted
- 'bytesRx' => 'null', #Bytes Recieved
- 'reasonForDisconnect' => 'null',#Reason for connection termination
- 'errorMessages' => undef, #Additional error messages
- 'state' => 'Disconnected' #State of session
- }
- );
- #=== Get data from file ===
- open(LOG, $file) or die "Cannot open $!"; #Open file under the handle LOG
- for $line (<LOG>){ #Read file into @log
- if($line){
- chomp($line); #Removes new line character from entry
- process_log($line); #Call function to precess log line
- } else { #Check to see if line is empty
- print 'Warning Line is Empty <BR>\n';
- }
- }
- close(LOG); #Close the log file
- ### =================== TESTING - REMOVE ME = =============================
- my $totalSessions = scalar (@sessions);
- print ':::';
- for (my $n=0; $n < $totalSessions; $n++){
- print 'currentcode = '.$sessions[$n]{"currentCode"}.'<br>';
- print 'connectdate = '.$sessions[$n]{"connectDate"}.'<br>';
- print 'connecttime = '.$sessions[$n]{"connectTime"}.'<br>';
- print 'clientip = '.$sessions[$n]{"clientIPAddress"}.'<br>';
- print 'state = '.$sessions[$n]{"state"}.'<br>';
- print 'authentication date = '.$sessions[$n]{"authenticationDate"}.'<br>';
- print 'authentication time = '.$sessions[$n]{"authenticationTime"}.'<br>';
- print 'userID = '.$sessions[$n]{"userID"}.'<br>';
- print 'groupID = '.$sessions[$n]{"groupID"}.'<br>';
- print 'platformType = '.$sessions[$n]{"platformType"}.'<br>';
- print 'clientVersion = '.$sessions[$n]{"clientVersion"}.'<br>';
- print 'vpnPoolAddress = '.$sessions[$n]{"vpnPoolAddress"}.'<br>';
- print 'disconnectTime = '.$sessions[$n]{"disconnectTime"}.'<br>';
- print 'duration = '.$sessions[$n]{"duration"}.'<br>';
- print 'bytesTx = '.$sessions[$n]{"bytesTx"}.'<br>';
- print 'bytesRx = '.$sessions[$n]{"bytesRx"}.'<br>';
- print 'reasonForDisconnect = '.$sessions[$n]{"reasonForDisconnect"}.'<br>';
- print 'errorMessages = '.$sessions[$n]{"errorMessages"}.'<br>';
- print '<br>';
- }
- ### =========== END TESTING ==============================================
- #=== Sub Routines ===
- sub process_log { #Script to parse logs
- #== Parameters passed into function ==
- #$line (@_) line being processed
- #== Declare Variables ==
- my $currentCode = undef; #Code being processed
- my $currentIP = undef; #IP of line being processed
- my $currentUserID = undef; #UserID of line being processed
- my $numberOfSessions = undef; #Number of sessions in the array
- my $data = undef; #Stores result of regex expressions
- my $currentLine = undef; #Whole Line currently being processed
- my $errors = undef; #Stores erorrs in log parsing
- my $sessionIP = undef; #Used to store IP for session during search
- my $sessionUserID = undef; #Used to store userID for session during search
- #=== Store elements from line ===
- $currentLine = shift; #Get line passed into function
- my @seperatedLine = split(/\s/, $currentLine); #Split line based on empty space delimitation
- $currentIP = $seperatedLine[10]; #Get IP from line
- $numberOfSessions = scalar (@sessions); #Get number of elements sessions array
- $currentLine =~ m/SEV=\d (.*) RPT/; #Extract current code from line
- $currentCode = $1; #Get current code
- if($currentCode){ #Check if line contains a code
- }else{
- #no code found
- next;
- }
- #Check for an unknown error code and corrupted lines
- if($currentCode=~ m/(IKEDBG\/64)|(IKE\/52)|(AUTH\/5)|(IKE\/22)|(IKE\/100)|(IKE\/98)|(AUTH\/9)|(IKE\/167)|(IKE\/184)|(AUTH\/22)|(IKE\/194)|(IKE\/119)|(IKE\/136)|
- (IKE\/25)|(IKE\/34)|(IKE\/50)|(AUTH\/28)|(IKE\/123)|(IKE\/66)|(IKE\/120)|(IKE\/49)|(IKE\/75)/){
- #code found
- }else{
- $errors = 'Log Error: \''.$currentLine.'\'<BR>';
- #print $errors; #========================== Save error to log file/database =========================
- next;
- }
- # IKE/DBG64
- if ($currentCode eq 'IKEDBG/64'){
- for (my $i=1; $i <= $numberOfSessions; $i++){ #Check to see if session already exists
- $sessionIP = $sessions[$i]{"clientIPAddress"}; #Get IP for selected session
- if($sessionIP){ #Check if line contains a IP
- if ($currentIP eq $sessionIP){ #Compare IP
- #-Session Exists-
- #Check for illegal connections (session not terminated correctly)
- my $sessionState = $sessions[$i]{"state"}; #Get current state of session
- if ($sessionState eq 'Disconnected'){
- #--Legal Session--
- $sessions[$i]{"state"} = 'Connecting'; #Progress state to connecting
- last; #Break out of loop
- }else{
- #--Illegal Session--
- #Error Message
- $sessions[$i]{"reasonForDisconnect"} = 'Session was not teminated correctly and has been termintated by parser';
- save_session($i); #Call save_session function
- splice(@sessions,$i,1); #Delete the current session
- #Create new session
- create_new_session($i);
- $sessions[$i]{"clientIPAddress"} = $seperatedLine[10];#Used as key for session
- $sessions[$i]{'currentCode'} = $currentCode; #Store current code for debugging
- $sessions[$i]{"connectDate"} = $seperatedLine[5];
- $sessions[$i]{"connectTime"} = $seperatedLine[6];
- last; #Break out of loop
- }
- }
- }else{
- #-Session doesn't exist-
- #Create new session
- create_new_session($numberOfSessions); #As the array starts from 0, $numberOfSessions will
- #always be greater than the index for the last session.
- $sessions[$numberOfSessions]{"clientIPAddress"} = $seperatedLine[10]; #Used as key for session
- $sessions[$numberOfSessions]{'currentCode'} = $currentCode; #Store current code
- $sessions[$numberOfSessions]{"connectDate"} = $seperatedLine[5];
- $sessions[$numberOfSessions]{"connectTime"} = $seperatedLine[6];
- }
- }
- }
Thanks