CREATE TABLE StartVoIP (
RadAcctId BIGSERIAL PRIMARY KEY,
- h323SetupTime TIMESTAMP with time zone NOT NULL,
+ AcctTime TIMESTAMP with time zone NOT NULL,
+ h323SetupTime TIMESTAMP with time zone,
H323ConnectTime TIMESTAMP with time zone,
UserName VARCHAR(64),
RadiusServerName VARCHAR(32),
NASIPAddress INET NOT NULL,
- AcctTime TIMESTAMP with time zone,
CalledStationId VARCHAR(80),
CallingStationId VARCHAR(80),
AcctDelayTime INTEGER,
CallID VARCHAR(80) NOT NULL,
processed BOOLEAN DEFAULT false
);
-create index startvoipcombo on startvoip (h323SetupTime, nasipaddress);
+create index startvoipcombo on startvoip (AcctTime, nasipaddress);
CREATE TABLE StartTelephony (
RadAcctId BIGSERIAL PRIMARY KEY,
- h323SetupTime TIMESTAMP with time zone NOT NULL,
+ AcctTime TIMESTAMP with time zone NOT NULL,
+ h323SetupTime TIMESTAMP with time zone,
H323ConnectTime TIMESTAMP with time zone,
UserName VARCHAR(64),
RadiusServerName VARCHAR(32),
NASIPAddress INET NOT NULL,
- AcctTime TIMESTAMP with time zone,
CalledStationId VARCHAR(80),
CallingStationId VARCHAR(80),
AcctDelayTime INTEGER,
CallID VARCHAR(80) NOT NULL,
processed BOOLEAN DEFAULT false
);
-create index starttelephonycombo on starttelephony (h323SetupTime, nasipaddress);
+create index starttelephonycombo on starttelephony (AcctTime, nasipaddress);
*/
CREATE TABLE StopVoIP (
RadAcctId BIGSERIAL PRIMARY KEY,
+ AcctTime TIMESTAMP with time zone NOT NULL,
H323SetupTime TIMESTAMP with time zone,
H323ConnectTime TIMESTAMP with time zone,
- H323DisconnectTime TIMESTAMP with time zone NOT NULL,
+ H323DisconnectTime TIMESTAMP with time zone,
UserName VARCHAR(32),
RadiusServerName VARCHAR(32),
NASIPAddress INET NOT NULL,
- AcctTime TIMESTAMP with time zone,
AcctSessionTime BIGINT,
AcctInputOctets BIGINT,
AcctOutputOctets BIGINT,
CallID VARCHAR(80) NOT NULL,
processed BOOLEAN DEFAULT false
);
-create UNIQUE index stopvoipcombo on stopvoip (h323SetupTime, nasipaddress, CallID);
-/*
- * Some Cisco CSPS do not have complete VSA details. If you have one of these you will want
- * to use the following index, as the one above will drop records.
- *
- * create UNIQUE index stopvoipcombo on stopvoip (h323DisconnectTime, nasipaddress, CallID);
- *
- */
+create UNIQUE index stopvoipcombo on stopvoip (AcctStopTime, nasipaddress, CallID);
CREATE TABLE StopTelephony (
RadAcctId BIGSERIAL PRIMARY KEY,
+ AcctTime TIMESTAMP with time zone NOT NULL,
H323SetupTime TIMESTAMP with time zone NOT NULL,
H323ConnectTime TIMESTAMP with time zone NOT NULL,
H323DisconnectTime TIMESTAMP with time zone NOT NULL,
UserName VARCHAR(32) DEFAULT '' NOT NULL,
RadiusServerName VARCHAR(32),
NASIPAddress INET NOT NULL,
- AcctTime TIMESTAMP with time zone,
AcctSessionTime BIGINT,
AcctInputOctets BIGINT,
AcctOutputOctets BIGINT,
CallID VARCHAR(80) NOT NULL,
processed BOOLEAN DEFAULT false
);
--- You can have more than one record that is identical except for CiscoNASPort if you have a VoIP dial peer
+-- You can have more than one record that is identical except for CiscoNASPort if you have a dial peer hungroup
-- configured for multiple PRIs.
-create UNIQUE index stoptelephonycombo on stoptelephony (h323SetupTime, nasipaddress, CallID, CiscoNASPort);
+create UNIQUE index stoptelephonycombo on stoptelephony (AcctTime, nasipaddress, CallID, CiscoNASPort);
/*
* Table structure for 'gateways'
# Author: Peter Nixon <codemonkey@peternixon.net>
# Summary: Extract information from Radius detail log and
# compare/insert/update a Postgresql database.
-# Copy Policy: GNU General Public Licence Version 2
+# Copy Policy: GNU Public Licence Version 2
# URL: http://www.peternixon.net/code/
# Supported: PostgreSQL (tested on version 7.2, 7.3, 7.4 and 8) and FreeRadius
# Copyright: 2004 Peter Nixon http://www.petenixon.net
#
+
# Modules that we use to get things done.
require DBI;
require Getopt::Long;
sub db_insert {
if ($h323_call_type eq 'VoIP') {
$sth2 = $dbh->prepare("INSERT into Stop$h323_call_type (
- AcctStopTime, UserName, NASIPAddress, AcctSessionTime, AcctInputOctets, AcctOutputOctets,
+ AcctTime, UserName, NASIPAddress, AcctSessionTime, AcctInputOctets, AcctOutputOctets,
CalledStationId, CallingStationId, AcctDelayTime, H323RemoteAddress, h323gwid, h323callorigin,
callid, h323connecttime, h323disconnectcause, h323disconnecttime, h323setuptime, h323voicequality)
- values('$radius_record_timestamp', '$UserName', '$NasIPAddress', '$AcctSessionTime', '$AcctInputOctets',
+ values(($Timestamp)::abstime, '$UserName', '$NasIPAddress', '$AcctSessionTime', '$AcctInputOctets',
'$AcctOutputOctets', '$Called_Station_Id', '$Calling_Station_Id', '$AcctDelayTime',
NULLIF('$h323_remote_address', '')::INET, '$h323_gw_id','$h323_call_origin', '$h323_conf_id',
NULLIF('$h323_connect_time', '')::TIMESTAMPTZ, '$h323_disconnect_cause',
}
sub db_read {
- if ($verbose > 0) { print "Record: $passno) ConfID: $h323_conf_id Timestamp: $radius_record_timestamp Length: $AcctSessionTime"; }
+ if ($verbose > 0) { print "Record: $passno) ConfID: $h323_conf_id Timestamp: $radius_record_timestamp Length: $AcctSessionTime "; }
my $sth = $dbh->prepare("SELECT RadAcctId FROM Stop$h323_call_type
- WHERE AcctStopTime = '$radius_record_timestamp'
+ WHERE AcctTime = ($Timestamp)::abstime
AND NASIPAddress = '$NasIPAddress'
AND callid = '$h323_conf_id'")
or die "\nCouldn't prepare statement: " . $dbh->errstr . "\n";
if ($sth->rows == 0) {
&db_insert; # It's a new record. All systems go.
} elsif ($sth->rows == 1) {
- if ($verbose > 0) { print "Exists in DB.\n"; }
+ if ($verbose > 0) { print "already in DB.\n"; }
# FIXME: Make updates an option!
#while (@data = $sth->fetchrow_array()) {
#my $dbAcctSessionId = $data[1];
sub process_record {
$radius_record_timestamp = @record[0];
chomp $radius_record_timestamp;
- if ($verbose > 1) { print "DEBUG: Processing new record with timestamp: $radius_record_timestamp \n"; }
+ if ($verbose > 1) { print "DEBUG: Processing new record with time: $radius_record_timestamp \n"; }
# Clear the variable we use so that we don't have rubbish from the last loop
$UserName=""; $NasPort=""; $NasPortType="";
$NasIPAddress = ""; $AcctStatusType=""; $AcctSessionTime="";
$Called_Station_Id = $_ if s/Called-Station-Id = //;
$Calling_Station_Id = $_ if s/Calling-Station-Id = //;
$Cisco_NAS_Port = $_ if s/Cisco-NAS-Port = //;
+ $Timestamp = $_ if s/Timestamp = //;
if (s/h323-call-type = \"h323-call-type=//) {
$h323_call_type = substr($_, 0, -1);
} elsif (s/h323-call-type = //) {