Use freeradius Timestamp field as it implicitly has a Timezone AND exists in EVERY...
authorpnixon <pnixon>
Tue, 30 Nov 2004 10:45:56 +0000 (10:45 +0000)
committerpnixon <pnixon>
Tue, 30 Nov 2004 10:45:56 +0000 (10:45 +0000)
src/billing/cisco_h323_db_schema-postgres.sql
src/billing/h323detail2db.pl

index c394d8c..6592e8b 100644 (file)
 
 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,
@@ -37,17 +37,17 @@ CREATE TABLE StartVoIP (
        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,
@@ -56,7 +56,7 @@ CREATE TABLE StartTelephony (
        CallID                  VARCHAR(80) NOT NULL,
        processed               BOOLEAN DEFAULT false
 );
-create index starttelephonycombo on starttelephony (h323SetupTime, nasipaddress);
+create index starttelephonycombo on starttelephony (AcctTime, nasipaddress);
 
 
 
@@ -65,13 +65,13 @@ create index starttelephonycombo on starttelephony (h323SetupTime, 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,
@@ -87,25 +87,18 @@ CREATE TABLE StopVoIP (
        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,
@@ -121,9 +114,9 @@ CREATE TABLE StopTelephony (
        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'
index 4e8d3ca..7e7a53e 100755 (executable)
@@ -3,7 +3,7 @@
 # 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
@@ -21,6 +21,7 @@
 #
 
 
+
 # Modules that we use to get things done.
 require DBI;
 require Getopt::Long;
@@ -105,10 +106,10 @@ sub procedure_insert {            # FIXME: Does not work with current SQL schema. Use stan
 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',
@@ -151,9 +152,9 @@ sub db_update {
 }
 
 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";
@@ -166,7 +167,7 @@ sub db_read {
           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];
@@ -183,7 +184,7 @@ sub db_read {
 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="";
@@ -222,6 +223,7 @@ sub process_record {
        $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 = //) {