Hi, as a bit of background (and seeing as it is my first post :)) i am a complete newbie at perl. I literally picked it up a week ago to do this project as it seemed like the best choice for a language to connect to a SQL database in a Unix envirment as well as script parsing so there is more than likely a ton of things i could have done a better way.
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: -
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
The code works but the errors i am getting are:
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 - if ($currentIP eq $sessionIP){ }
statements, even though essentially the code wouldnt get that far because it would be caught by -
if($currentCode=~ m/(IKEDBG\/64)|(IKE\/52)|.....|(IKE\/49)|(IKE\/75)/){
As being an invalid line adding a check to see if sessionIP contained something got rid of the error message
This is just a snippet so it probably wont compile if you would like more please dont hesitate to ask -
#!/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];
-
}
-
}
-
}
-
Any help would be much appreciated
Thanks
4 3746 KevinADC 4,059
Recognized Expert Specialist
It appears that variables, like 'clientIPAddres s' => undef, are not initialized before you try printing a little bit later: print 'clientip = '.$sessions[$n]{"clientIPAddre ss"}.'<br>';
same with print 'authentication date = '.$sessions[$n]{"authenticatio nDate"}.'<br>';
there is no "authentication Date" in the initial data set @sessions. Why are you using an array that contains an annonymous hash? Are there more annonymous hashes in the array?
It appears that variables, like 'clientIPAddres s' => undef, are not initialized before you try printing a little bit later:
print 'clientip = '.$sessions[$n]{"clientIPAddre ss"}.'<br>';
same with
print 'authentication date = '.$sessions[$n]{"authenticatio nDate"}.'<br>';
there is no "authentication Date" in the initial data set @sessions.
Maybe it's me being dim I dont quite understand :s, surely the set is initialised when i make the template entry and put 'null' values into them from the get go
i use the same method to create a new "session" later on in the function create_session. (see below)
If anything shouldn't it just print 'null'?
I used undef for the client IP and other things so that i could do a check to see if there was anything in the variable, if there wasnt the loop would break and if there was it would continue to try avoid the uninitialised problems -
sub create_new_session { #Script to create a blank session
-
-
my $sessionID = shift; #Session ID
-
# Create empty session
-
$sessions[$sessionID]{'clientIPAddress'} = undef; #Address assigned from IP pool
-
$sessions[$sessionID]{'currentCode'} = 'Initialiser'; #Current IKE code being processed
-
$sessions[$sessionID]{'connectDate'} = 'null'; #Date of connection to access point
-
$sessions[$sessionID]{'connectTime'} = 'null'; #Time of connection to access point
-
$sessions[$sessionID]{'userID'} = 'null'; #Username unique to user
-
$sessions[$sessionID]{'authenticationDate'} = 'null'; #Date user's has been authenticated
-
$sessions[$sessionID]{'authenticationTime'} = 'null'; #Time user's has been authenticated
-
$sessions[$sessionID]{'groupID'} = 'null'; #VPN group user belongs to (usually Roamnet)
-
$sessions[$sessionID]{'platformType'} = 'null'; #Platform user is running Windows, Unix etc..
-
$sessions[$sessionID]{'clientVersion'} = 'null'; #Version of VPN client
-
$sessions[$sessionID]{'vpnPoolAddress'} = 'null'; #IP address assigned from VPN pool
-
$sessions[$sessionID]{'disconnectTime'} = 'null'; #Time session was disconnected
-
$sessions[$sessionID]{'duration'} = 'null'; #Duration of session
-
$sessions[$sessionID]{'bytesTx'} = 'null'; #Bytes Transmitted
-
$sessions[$sessionID]{'bytesRx'} = 'null'; #Bytes Recieved
-
$sessions[$sessionID]{'reasonForDisconnect'} = undef;#Reason for connection termination
-
$sessions[$sessionID]{'errorMessages'} = undef; #Additional error messages
-
$sessions[$sessionID]{'state'} = 'Disconnected'; #State of session
-
} #End Create empty session
-
Why are you using an array that contains an annonymous hash? Are there more annonymous hashes in the array?
It's because more than one session needs to be tracked at any one time as the script is intended to parse live logs, therefore needs to be done on a line by line basis rather than pull a session out the logs save it and move on.
I created the empty session at the top to make the code easier to read and so i could delcare and initialise all the variables to try avoid the error i am getting
eWish 971
Recognized Expert Contributor
If anything shouldn't it just print 'null'?
If you want insert a null value into the db you have to use 'undef'. Otherwise, you are just printing the word 'Null' which is not the same as a null/undefined value.
Here is an example where if $value is not defined, then it will use undef. - my $value = $some_other_value || undef;
KevinADC 4,059
Recognized Expert Specialist
the value of 'null' is a string, so those variables are defined, undef means undefined, so any value assigned the value of undef is undefined.
use warnings;
$foo = undef;
print $foo;
The above returns a warnings about "uninitiali zed value in print" which is essentially the same warning you are getting.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Tom |
last post by:
Hi
I am installing Oracle9ias onto a United Linux 1.0 and encountering
the following error at "Single Sign On Configuration Assistant", any
idea?
....
PL/SQL procedure successfully completed.
Disconnected from Oracle9i Enterprise Edition Release 9.0.1.3.0 -
|
by: Gene Wirchenko |
last post by:
Is the following guaranteed safe?
void InitInt(int & SomeInt)
{
SomeInt=3;
return;
}
int main()
{
|
by: Lyn |
last post by:
I am trying to get my head around the concept of default, special or empty
values that appear in Access VBA, depending on data type. The Access Help
is not much (help), and the manual that I have is not much help here either.
Googling has given me a little help.
This is my current understanding -- I would appreciate any comments or
corrections...
"" -- this means an empty string when applied to String data type, and also
to Variant...
|
by: santosh |
last post by:
Hi,
If I call free() with a uninitialised pointer, will the program
state become undefined, or will free() return harmlessly?
Incidentally, is there a way in Standard C to determine
weather a pointer points to a valid block of allocated
memory?
Thanks for your time.
|
by: Madhav |
last post by:
Hi all,
I did not understand why do the global vars are
initialized to NULL where as the block level variables have random
values? I know that the C standard requires this as was mentioned in a
recent thread.
I want to know why this descrimination is in place. Can't all the
variables be initialised to NULL automatically by the compiler? This
would make programming a little easier.
| |
by: sandy |
last post by:
I need (okay, I want) to make a dynamic array of my class 'Directory',
within my class Directory (Can you already smell disaster?)
Each Directory can have subdirectories so I thought to put these in an
array. The application compiles but aborts without giving me any useful
information.
What I suspect is happening is infinite recursion. Each Directory
object creates an array of Subdirectories each of which has an array of...
|
by: geek.arnuld |
last post by:
this is the programme:
#include <iostream // std::cout
int main()
{
int sum;
std::cout << sum << "\n";
}
|
by: BlueJ |
last post by:
My program is to send data using socket.. but I got the error message:
"sendto(msg) points to uninitialised byte(s) " This is my source code
1. key_list = emalloc(BUFSIZE - sizeof(Key) - sizeof(byte) -
sizeof(int));
bzero(key_list, sizeof(*key_list));
bp = key_list;
memmove(bp, key, ID_LEN);
|
by: Ulrich Eckhardt |
last post by:
Greetings!
I was recently surprised by the compiler's warning concerning this code:
struct text {
char* s;
size_t len;
};
int main() {
struct text t = {"hello world!"};
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
| |
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |