diff --git a/docs/tutorial.rst b/docs/tutorial.rst index e124fb08e..22c12402b 100644 --- a/docs/tutorial.rst +++ b/docs/tutorial.rst @@ -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, diff --git a/sessionmanager/event.go b/sessionmanager/event.go index ae2ea9f6e..a8e19095e 100644 --- a/sessionmanager/event.go +++ b/sessionmanager/event.go @@ -28,6 +28,7 @@ type Event interface { GetDirection() string GetOrigId() string GetSubject() string + GetAccount() string GetDestination() string GetTOR() string GetUUID() string diff --git a/sessionmanager/fsevent.go b/sessionmanager/fsevent.go index 5ac712625..9f8b3deef 100644 --- a/sessionmanager/fsevent.go +++ b/sessionmanager/fsevent.go @@ -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] } diff --git a/sessionmanager/postgreslogger.go b/sessionmanager/postgreslogger.go index 4c12b6700..e8ef66844 100644 --- a/sessionmanager/postgreslogger.go +++ b/sessionmanager/postgreslogger.go @@ -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, diff --git a/sessionmanager/session.go b/sessionmanager/session.go index a35cddb9f..1097752ec 100644 --- a/sessionmanager/session.go +++ b/sessionmanager/session.go @@ -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) } // diff --git a/sessionmanager/sessiondelegate.go b/sessionmanager/sessiondelegate.go index ab3079edd..10625d157 100644 --- a/sessionmanager/sessiondelegate.go +++ b/sessionmanager/sessiondelegate.go @@ -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, } diff --git a/timespans/callcost.go b/timespans/callcost.go index 99e029061..0142c7305 100644 --- a/timespans/callcost.go +++ b/timespans/callcost.go @@ -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()) } diff --git a/timespans/calldesc.go b/timespans/calldesc.go index 04dfff45d..60c745a7c 100644 --- a/timespans/calldesc.go +++ b/timespans/calldesc.go @@ -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,