added account atribute to callcost

This commit is contained in:
Radu Ioan Fericean
2012-07-13 16:41:33 +03:00
parent 53f9737c4e
commit fb40cbdd19
8 changed files with 21 additions and 8 deletions

View File

@@ -128,7 +128,7 @@ This tool is used for importing the data from CSV files into the CGRateS databas
cgr-sessionmanager
~~~~~~~~~~~~~~~~~~
Session manager connects and monitors the freeswitch server issuing API request to other CGRateS components. It can run in standalone mode for minimal system configuration.
Session manager connects and monitors the freeswitch server issuing API request to other CGRateS components. It can run in standalone mode for minimal system configuration. It logs the calls information to a postgres database in order to be used by the mediator tool.
::
@@ -147,7 +147,7 @@ Session manager connects and monitors the freeswitch server issuing API request
cgr-mediator
~~~~~~~~~~~~
The mediator parses the CDR file and writes the calls cost to a postgress database.
The mediator parses the call logs written in a postgres database by the session manager and writes the call costs to a freeswitch CDR file.
The structure of the table (as an SQL command) is the following::
@@ -155,6 +155,7 @@ The structure of the table (as an SQL command) is the following::
uuid varchar(80) primary key,direction varchar(32),
tenant varchar(32),tor varchar(32),
subject varchar(32),
account varchar(32),
destination varchar(32),
cost real,
conect_fee real,

View File

@@ -28,6 +28,7 @@ type Event interface {
GetDirection() string
GetOrigId() string
GetSubject() string
GetAccount() string
GetDestination() string
GetTOR() string
GetUUID() string

View File

@@ -39,6 +39,7 @@ const (
CALL_DIRECTION = "Call-Direction"
ORIG_ID = "variable_sip_call_id" //- originator_id - match cdrs
SUBJECT = "variable_cgr_subject"
ACCOUNT = ""
DESTINATION = "variable_cgr_destination"
TOR = "variable_cgr_tor"
UUID = "Unique-ID" // -Unique ID for this call leg
@@ -85,6 +86,9 @@ func (fsev *FSEvent) GetOrigId() string {
func (fsev *FSEvent) GetSubject() string {
return fsev.Fields[SUBJECT]
}
func (fsev *FSEvent) GetAccount() string {
return fsev.Fields[ACCOUNT]
}
func (fsev *FSEvent) GetDestination() string {
return fsev.Fields[DESTINATION]
}

View File

@@ -48,12 +48,13 @@ func (psl *PostgresLogger) Log(uuid string, cc *timespans.CallCost) {
if err != nil {
log.Printf("Error marshalling timespans to json: %v", err)
}
_, err = psl.db.Exec(fmt.Sprintf("INSERT INTO callcosts VALUES ('%s', '%s', '%s', '%s', '%s', %v, %v, '%s')",
_, err = psl.db.Exec(fmt.Sprintf("INSERT INTO callcosts VALUES ('%s','%s', '%s', '%s', '%s', '%s', '%s', %v, %v, '%s')",
uuid,
cc.Destination,
cc.Tenant,
cc.TOR,
cc.Subject,
cc.Account,
cc.Destination,
cc.Cost,
cc.ConnectFee,

View File

@@ -51,6 +51,7 @@ func NewSession(ev Event, sm SessionManager) (s *Session) {
Tenant: ev.GetTenant(),
TOR: ev.GetTOR(),
Subject: ev.GetSubject(),
Account: ev.GetAccount(),
Destination: ev.GetDestination(),
TimeStart: startTime}
s = &Session{uuid: ev.GetUUID(),
@@ -108,7 +109,7 @@ func (s *Session) Disconnect() {
// Nice print for session
func (s *Session) String() string {
return fmt.Sprintf("%v: %s -> %s", s.callDescriptor.TimeStart, s.callDescriptor.Subject, s.callDescriptor.Destination)
return fmt.Sprintf("%v: %s(%s) -> %s", s.callDescriptor.TimeStart, s.callDescriptor.Subject, s.callDescriptor.Account, s.callDescriptor.Destination)
}
//

View File

@@ -104,6 +104,7 @@ func (dsd *DirectSessionDelegate) OnChannelHangupComplete(ev Event, s *Session)
Tenant: lastCC.Tenant,
TOR: lastCC.TOR,
Subject: lastCC.Subject,
Account: lastCC.Account,
Destination: lastCC.Destination,
Amount: -cost,
}
@@ -115,6 +116,7 @@ func (dsd *DirectSessionDelegate) OnChannelHangupComplete(ev Event, s *Session)
Tenant: lastCC.Tenant,
TOR: lastCC.TOR,
Subject: lastCC.Subject,
Account: lastCC.Account,
Destination: lastCC.Destination,
Amount: -seconds,
}
@@ -227,6 +229,7 @@ func (rsd *RPCSessionDelegate) OnChannelHangupComplete(ev Event, s *Session) {
Tenant: lastCC.Tenant,
TOR: lastCC.TOR,
Subject: lastCC.Subject,
Account: lastCC.Account,
Destination: lastCC.Destination,
Amount: -cost,
}
@@ -241,6 +244,7 @@ func (rsd *RPCSessionDelegate) OnChannelHangupComplete(ev Event, s *Session) {
TOR: lastCC.TOR,
Tenant: lastCC.Tenant,
Subject: lastCC.Subject,
Account: lastCC.Account,
Destination: lastCC.Destination,
Amount: -seconds,
}

View File

@@ -26,14 +26,14 @@ import (
The output structure that will be returned with the call cost information.
*/
type CallCost struct {
Direction, TOR, Tenant, Subject, Destination string
Cost, ConnectFee float64
Timespans []*TimeSpan
Direction, TOR, Tenant, Subject, Account, Destination string
Cost, ConnectFee float64
Timespans []*TimeSpan
}
// Pretty printing for call cost
func (cc *CallCost) String() (r string) {
r = fmt.Sprintf("%v[%v] : %s -> %s (", cc.Cost, cc.ConnectFee, cc.Subject, cc.Destination)
r = fmt.Sprintf("%v[%v] : %s(%s) -> %s (", cc.Cost, cc.ConnectFee, cc.Subject, cc.Account, cc.Destination)
for _, ts := range cc.Timespans {
r += fmt.Sprintf(" %v,", ts.GetDuration())
}

View File

@@ -265,6 +265,7 @@ func (cd *CallDescriptor) GetCost() (*CallCost, error) {
cc := &CallCost{TOR: cd.TOR,
Tenant: cd.Tenant,
Subject: cd.Subject,
Account: cd.Account,
Destination: destPrefix,
Cost: cost,
ConnectFee: connectionFee,