telcomwork
Technical User
Anyone have a new download path for netcat. The one posted here looks to be gone...
I would liek to setup CDR on a windows XP workstation.
I would liek to setup CDR on a windows XP workstation.
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
my $EXPECTEDLENGTH = 77; # this MUST be set to the record length as reported by the "change system-parameters cdr" screen, NOT INCLUDING any line-ending characters
my $PORTNUMBER = 9000; # TCP port number on which to listen -- must be set to whatever "remote port" the PBX will try to connect to (in "change ip-services")
my $IDLETIMEOUT = 900; # a safety measure in case a particular Netcat listener process goes off into the ozone; it shouldn't wait forever when it doesn't hear anything, it should quit itself within 15 minutes
my $COLLECTIONPERIOD = 5; # after this many minutes, start a new output file
mkdir "./GoingToSQL";
while (1) { # forever, until this entire program is killed...
my $childPID = open FH, "nc -l -p $PORTNUMBER -w $IDLETIMEOUT |"
or die "Could not open a subshell piped from a netcat listener: $!\n";
my $currentTime = localtime();
print "\n\n-- $currentTime New child PID is $childPID\n";
while (<FH>) {
chomp; # records arrive correctly CR-LF terminated, because we asked for those characters in the PBX's "change system-parameters cdr" screen
# print length($_), ' ', $_, "\n";
if (length($_) < $EXPECTEDLENGTH) {
# print "Above line discarded (should be a date/time stamp).\n";
next;
}
if (length($_) == $EXPECTEDLENGTH + 3) {
# print "Chop off first three chars.\n";
$_ = substr($_, 3);
# print "New line:\n";
# print length($_), ' ', $_, "\n";
# ...and fall through to next case to process this line
}
if (length($_) == $EXPECTEDLENGTH) {
# print "Process as normal.\n";
$_ =~ /^(.{2})(.{2})(.{2}) (.{2})(.{2}) (.{4}) (.{15}) (.{7}) (.{23}) (.{4}) (.{3}) (.{3})$/;
($second, $minute, $hour, $dayofmonth, $month, $year) = localtime;
$minute -= ($minute % $COLLECTIONPERIOD); # round down to nearest 5-minute boundary
my $filename = sprintf('./GoingToSQL/AvayaCDR-%04d-%02d-%02d-%02d%02d.sql',
$year + 1900, $month + 1, $dayofmonth, $hour, $minute);
open FHoutput, ">>$filename"
or die "Could not open $filename for append: $!\n";
print FHoutput "exec CallAccountingDataAdd_tw '20$3-$1-$2 $4:$5',$6,'$7','$8','$9','$10','$11','$12'\n";
close FHoutput;
next;
}
print "Unknown line length!\n";
}
close FH;
}
my $REQUIREDAGE = 5 * 60 + 10; # 5 minutes plus a "slop factor" of 10 seconds; file must be this many seconds old before it's considered "cut off" -- must be at least a bit larger than the cutoff boundary of the AvayaCDRCapturetoSQL program!
my $documentName;
my $modTime;
my $secondsOld;
mkdir "./Done";
while (1) { # forever, until we are killed...
my $currentTime = time();
my @potentialFiles = glob "./GoingToSQL/*.sql";
# print join("\n",@potentialFiles),"\n\n";
for ($i = 0; $i < (scalar @potentialFiles); $i++) {
print "Found $potentialFiles[$i]: ";
$modTime = (stat ($potentialFiles[$i]))[9];
$secondsOld = $currentTime - $modTime;
print "$secondsOld seconds old; ";
if ($secondsOld > $REQUIREDAGE) {
print "Process\n";
$newFile = $oldFile = $potentialFiles[$i];
$newFile =~ s:^\./GoingToSQL/:./Done/:;
$resultCode = system("osql -S dgoldmine -E -d CMS -b -i $oldFile -w 8000 -o $oldFile.log");
if ($resultCode == 0) {
rename "$oldFile", "$newFile";
rename "$oldFile.log", "$newFile.log";
} else {
print "Error encountered trying to run SQL script $oldFile; retrying later\n";
}
} else {
print "Skip it\n";
}
}
print "\n";
sleep 30;
}
my $EXPECTEDLENGTH = 78; # this MUST be set to the record length as reported by the "change system-parameters cdr" screen, NOT INCLUDING any line-ending characters
my $PORTNUMBER = 9000; # TCP port number on which to listen -- must be set to whatever "remote port" the PBX will try to connect to (in "change ip-services")
my $IDLETIMEOUT = 900; # a safety measure in case a particular Netcat listener process goes off into the ozone; it shouldn't wait forever when it doesn't hear anything, it should quit itself within 15 minutes
my $COLLECTIONPERIOD = 5; # after this many minutes, start a new output file
mkdir "./GoingToSQL";
while (1) { # forever, until this entire program is killed...
my $childPID = open FH, "nc -l -p $PORTNUMBER -w $IDLETIMEOUT |"
or die "Could not open a subshell piped from a netcat listener: $!\n";
my $currentTime = localtime();
print "\n\n-- $currentTime New child PID is $childPID\n";
while (<FH>) {
chomp; # records arrive correctly CR-LF terminated, because we asked for those characters in the PBX's "change system-parameters cdr" screen
# print length($_), ' ', $_, "\n";
if (length($_) < $EXPECTEDLENGTH) {
# print "Above line discarded (should be a date/time stamp).\n";
next;
}
if (length($_) == $EXPECTEDLENGTH + 3) {
# print "Chop off first three chars.\n";
$_ = substr($_, 3);
# print "New line:\n";
# print length($_), ' ', $_, "\n";
# ...and fall through to next case to process this line
}
if (length($_) == $EXPECTEDLENGTH) {
# print "Process as normal.\n";
$_ =~ /^(.{2})(.{2})(.{2}) (.{2})(.{2}) (.{1})(.{2})(.{2}) (.{15}) (.{7}) (.{23}) (.{4}) (.{3}) (.{3})$/;
($second, $minute, $hour, $dayofmonth, $month, $year) = localtime;
$minute -= ($minute % $COLLECTIONPERIOD); # round down to nearest 5-minute boundary
my $filename = sprintf('./GoingToSQL/AvayaCDR-%04d-%02d-%02d-%02d%02d.sql',
$year + 1900, $month + 1, $dayofmonth, $hour, $minute);
open FHoutput, ">>$filename"
or die "Could not open $filename for append: $!\n";
$durationInSeconds = ($6 * 3600) + ($7 * 60) + ($8);
print FHoutput "exec CallAccountingDataAdd_tw '20$3-$1-$2 $4:$5',$durationInSeconds,'$9','$10','$11','$12','$13','$14'\n";
close FHoutput;
next;
}
print "Unknown line length!\n";
}
close FH;
}