Merge branch 'master' of github.com:cgrates/cgrates

This commit is contained in:
Radu Ioan Fericean
2013-06-03 10:42:57 +03:00
6 changed files with 152 additions and 155 deletions

View File

@@ -50,6 +50,7 @@ const (
REDIS = "redis"
SAME = "same"
FS = "freeswitch"
FSCDR_FILE_CSV = "freeswitch_file_csv"
)
var (
@@ -123,15 +124,13 @@ func startMediator(responder *rater.Responder, loggerDb rater.DataStorage) {
connector = &rater.RPCClientConnector{Client: client}
}
var err error
medi, err = mediator.NewMediator(connector, loggerDb, cfg.MediatorCDROutDir, cfg.MediatorPseudoprepaid,
cfg.FreeswitchDirectionIdx, cfg.FreeswitchTORIdx, cfg.FreeswitchTenantIdx, cfg.FreeswitchSubjectIdx, cfg.FreeswitchAccountIdx,
cfg.FreeswitchDestIdx, cfg.FreeswitchTimeStartIdx, cfg.FreeswitchDurationIdx, cfg.FreeswitchUUIDIdx)
medi, err = mediator.NewMediator(connector, loggerDb, cfg )
if err != nil {
rater.Logger.Crit(fmt.Sprintf("Mediator config parsing error: %v", err))
exitChan <- true
}
if cfg.MediatorEnabled { //Mediator as standalone service
if cfg.MediatorCDRType == FSCDR_FILE_CSV { //Mediator as standalone service for file CDRs
if _, err := os.Stat(cfg.MediatorCDRInDir); err != nil {
rater.Logger.Crit(fmt.Sprintf("The input path for mediator does not exist: %v", cfg.MediatorCDRInDir))
exitChan <- true
@@ -194,18 +193,17 @@ func startSessionManager(responder *rater.Responder, loggerDb rater.DataStorage)
}
func startCDRS(responder *rater.Responder, loggerDb rater.DataStorage) {
if !cfg.MediatorEnabled {
go startMediator(responder, loggerDb) // Will start it internally, important to connect the responder
}
for i := 0; i < 3; i++ { // ToDo: If the right approach, make the reconnects configurable
time.Sleep(time.Duration(i/2) * time.Second)
if medi!=nil { // Got our mediator, no need to wait any longer
break
if cfg.CDRSMediator == INTERNAL {
for i := 0; i < 3; i++ { // ToDo: If the right approach, make the reconnects configurable
time.Sleep(time.Duration(i/2) * time.Second)
if medi!=nil { // Got our mediator, no need to wait any longer
break
}
}
if medi == nil {
rater.Logger.Crit("<CDRS> Could not connect to mediator, exiting.")
exitChan <- true
}
}
if medi == nil {
rater.Logger.Crit("<CDRS> Could not connect to mediator, exiting.")
exitChan <- true
}
cs := cdrs.New(loggerDb, medi, cfg)
cs.StartCapturingCDRs()
@@ -343,6 +341,7 @@ func main() {
rater.Logger.Info("Starting CGRateS Mediator.")
go startMediator(responder, loggerDb)
}
if cfg.CDRSListen != "" {
rater.Logger.Info("Starting CGRateS CDR Server.")
go startCDRS(responder, loggerDb)

View File

@@ -34,6 +34,10 @@ const (
REDIS = "redis"
SAME = "same"
FS = "freeswitch"
PREPAID = "prepaid"
POSTPAID = "postpaid"
PSEUDOPREPAID = "pseudoprepaid"
RATED = "rated"
)
// Holds system configuration, defaults are overwritten with values from config file if found
@@ -69,26 +73,26 @@ type CGRConfig struct {
SMRater string // address where to access rater. Can be internal, direct rater address or the address of a balancer
SMRaterReconnects int // Number of reconnect attempts to rater
SMDebitInterval int // the period to be debited in advanced during a call (in seconds)
MediatorEnabled bool
MediatorEnabled bool // Starts Mediator service: <true|false>.
MediatorListen string // Mediator's listening interface: <internal>.
MediatorCDRType string // sets the type of cdrs we are processing.
MediatorCDRInDir string // Freeswitch Master CSV CDR path.
MediatorCDROutDir string // Freeswitch Master CSV CDR output path.
MediatorRater string // address where to access rater. Can be internal, direct rater address or the address of a balancer
MediatorRaterReconnects int // Number of reconnect attempts to rater
MediatorPseudoprepaid bool
MediatorRater string // Address where to reach the Rater: <internal|x.y.z.y:1234>
MediatorRaterReconnects int // Number of reconnects to rater before giving up.
MediatorCDRType string // CDR type <freeswitch_http_json|freeswitch_file_csv>.
MediatorAccIdField string // Name of field identifying accounting id used during mediation. Use index number in case of .csv cdrs.
MediatorSubjectFields string // Name of subject fields to be used during mediation. Use index numbers in case of .csv cdrs.
MediatorReqTypeFields string // Name of request type fields to be used during mediation. Use index number in case of .csv cdrs.
MediatorDirectionFields string // Name of direction fields to be used during mediation. Use index numbers in case of .csv cdrs.
MediatorTenantFields string // Name of tenant fields to be used during mediation. Use index numbers in case of .csv cdrs.
MediatorTORFields string // Name of tor fields to be used during mediation. Use index numbers in case of .csv cdrs.
MediatorAccountFields string // Name of account fields to be used during mediation. Use index numbers in case of .csv cdrs.
MediatorDestFields string // Name of destination fields to be used during mediation. Use index numbers in case of .csv cdrs.
MediatorTimeStartFields string // Name of time_start fields to be used during mediation. Use index numbers in case of .csv cdrs.
MediatorDurationFields string // Name of duration fields to be used during mediation. Use index numbers in case of .csv cdrs.
MediatorCDRInDir string // Absolute path towards the directory where the CDRs are kept (file stored CDRs).
MediatorCDROutDir string // Absolute path towards the directory where processed CDRs will be exported (file stored CDRs).
FreeswitchServer string // freeswitch address host:port
FreeswitchPass string // FS socket password
FreeswitchDirectionIdx string
FreeswitchTORIdx string
FreeswitchTenantIdx string
FreeswitchSubjectIdx string
FreeswitchAccountIdx string
FreeswitchDestIdx string
FreeswitchTimeStartIdx string
FreeswitchDurationIdx string
FreeswitchUUIDIdx string
FreeswitchReconnects int // number of times to attempt reconnect after connect fails
FreeswitchReconnects int // number of times to attempt reconnect after connect fails
}
func ( self *CGRConfig ) setDefaults() error {
@@ -105,6 +109,7 @@ func ( self *CGRConfig ) setDefaults() error {
self.LogDBUser = ""
self.LogDBPass = ""
self.RPCEncoding = GOB
self.DefaultReqType = "rated"
self.DefaultTOR = "0"
self.DefaultTenant = "0"
self.DefaultSubject = "0"
@@ -119,30 +124,29 @@ func ( self *CGRConfig ) setDefaults() error {
self.CDRSMediator = INTERNAL
self.MediatorEnabled = false
self.MediatorListen = "127.0.0.1:2032"
self.MediatorCDRInDir = "/var/log/freeswitch/cdr-csv"
self.MediatorCDROutDir = "/var/log/cgrates/cdr_out"
self.MediatorRater = "127.0.0.1:2012"
self.MediatorRaterReconnects = 3
self.MediatorPseudoprepaid = false
self.MediatorCDRType = "freeswitch_csv"
self.MediatorCDRType = "freeswitch_http_json"
self.MediatorAccIdField = "accid"
self.MediatorSubjectFields = "subject"
self.MediatorReqTypeFields = "reqtype"
self.MediatorDirectionFields = "direction"
self.MediatorTenantFields = "tenant"
self.MediatorTORFields = "tor"
self.MediatorAccountFields = "account"
self.MediatorDestFields = "destination"
self.MediatorTimeStartFields = "time_start"
self.MediatorDurationFields = "duration"
self.MediatorCDRInDir = "/var/log/freeswitch/cdr-csv"
self.MediatorCDROutDir = "/var/log/cgrates/cdr/out/freeswitch/csv"
self.SMEnabled = false
self.SMSwitchType = FS
self.SMRater = "127.0.0.1:2012"
self.SMRaterReconnects = 3
self.SMDebitInterval = 10
self.DefaultReqType = ""
self.FreeswitchServer = "127.0.0.1:8021"
self.FreeswitchPass = "ClueCon"
self.FreeswitchReconnects = 5
self.FreeswitchUUIDIdx = "10"
self.FreeswitchTORIdx = "-1"
self.FreeswitchTenantIdx = "-1"
self.FreeswitchDirectionIdx = "-1"
self.FreeswitchSubjectIdx = "-1"
self.FreeswitchAccountIdx = "-1"
self.FreeswitchDestIdx = "-1"
self.FreeswitchTimeStartIdx = "-1"
self.FreeswitchDurationIdx = "-1"
return nil
}
@@ -253,24 +257,51 @@ func loadConfig(c *conf.ConfigFile) (*CGRConfig, error) {
if hasOpt = c.HasOption("mediator", "listen"); hasOpt {
cfg.MediatorListen, _ = c.GetString("mediator", "listen")
}
if hasOpt = c.HasOption("mediator", "cdr_in_dir"); hasOpt {
cfg.MediatorCDRInDir, _ = c.GetString("mediator", "cdr_in_dir")
}
if hasOpt = c.HasOption("mediator", "cdr_out_dir"); hasOpt {
cfg.MediatorCDROutDir, _ = c.GetString("mediator", "cdr_out_dir")
}
if hasOpt = c.HasOption("mediator", "rater"); hasOpt {
cfg.MediatorRater, _ = c.GetString("mediator", "rater")
}
if hasOpt = c.HasOption("mediator", "rater_reconnects"); hasOpt {
cfg.MediatorRaterReconnects, _ = c.GetInt("mediator", "rater_reconnects")
}
if hasOpt = c.HasOption("mediator", "pseudoprepaid"); hasOpt {
cfg.MediatorPseudoprepaid, _ = c.GetBool("mediator", "pseudoprepaid")
}
if hasOpt = c.HasOption("mediator", "cdr_type"); hasOpt {
cfg.MediatorCDRType, _ = c.GetString("mediator", "cdr_type")
}
if hasOpt = c.HasOption("mediator", "accid_field"); hasOpt {
cfg.MediatorAccIdField, _ = c.GetString("mediator", "accid_field")
}
if hasOpt = c.HasOption("mediator", "subject_fields"); hasOpt {
cfg.MediatorSubjectFields, _ = c.GetString("mediator", "subject_fields")
}
if hasOpt = c.HasOption("mediator", "reqtype_fields"); hasOpt {
cfg.MediatorReqTypeFields, _ = c.GetString("mediator", "reqtype_fields")
}
if hasOpt = c.HasOption("mediator", "direction_fields"); hasOpt {
cfg.MediatorDirectionFields, _ = c.GetString("mediator", "direction_fields")
}
if hasOpt = c.HasOption("mediator", "tenant_fields"); hasOpt {
cfg.MediatorTenantFields, _ = c.GetString("mediator", "tenant_fields")
}
if hasOpt = c.HasOption("mediator", "tor_fields"); hasOpt {
cfg.MediatorTORFields, _ = c.GetString("mediator", "tor_fields")
}
if hasOpt = c.HasOption("mediator", "account_fields"); hasOpt {
cfg.MediatorAccountFields, _ = c.GetString("mediator", "account_fields")
}
if hasOpt = c.HasOption("mediator", "destination_fields"); hasOpt {
cfg.MediatorDestFields, _ = c.GetString("mediator", "destination_fields")
}
if hasOpt = c.HasOption("mediator", "time_start_fields"); hasOpt {
cfg.MediatorTimeStartFields, _ = c.GetString("mediator", "time_start_fields")
}
if hasOpt = c.HasOption("mediator", "duration_fields"); hasOpt {
cfg.MediatorDurationFields, _ = c.GetString("mediator", "duration_fields")
}
if hasOpt = c.HasOption("mediator", "cdr_in_dir"); hasOpt {
cfg.MediatorCDRInDir, _ = c.GetString("mediator", "cdr_in_dir")
}
if hasOpt = c.HasOption("mediator", "cdr_out_dir"); hasOpt {
cfg.MediatorCDROutDir, _ = c.GetString("mediator", "cdr_out_dir")
}
if hasOpt = c.HasOption("session_manager", "enabled"); hasOpt {
cfg.SMEnabled, _ = c.GetBool("session_manager", "enabled")
}
@@ -295,33 +326,6 @@ func loadConfig(c *conf.ConfigFile) (*CGRConfig, error) {
if hasOpt = c.HasOption("freeswitch", "reconnects"); hasOpt {
cfg.FreeswitchReconnects, _ = c.GetInt("freeswitch", "reconnects")
}
if hasOpt = c.HasOption("freeswitch", "uuid_index"); hasOpt {
cfg.FreeswitchUUIDIdx, _ = c.GetString("freeswitch", "uuid_index")
}
if hasOpt = c.HasOption("freeswitch", "tor_index"); hasOpt {
cfg.FreeswitchTORIdx, _ = c.GetString("freeswitch", "tor_index")
}
if hasOpt = c.HasOption("freeswitch", "tenant_index"); hasOpt {
cfg.FreeswitchTenantIdx, _ = c.GetString("freeswitch", "tenant_index")
}
if hasOpt = c.HasOption("freeswitch", "direction_index"); hasOpt {
cfg.FreeswitchDirectionIdx, _ = c.GetString("freeswitch", "direction_index")
}
if hasOpt = c.HasOption("freeswitch", "subject_index"); hasOpt {
cfg.FreeswitchSubjectIdx, _ = c.GetString("freeswitch", "subject_index")
}
if hasOpt = c.HasOption("freeswitch", "account_index"); hasOpt {
cfg.FreeswitchAccountIdx, _ = c.GetString("freeswitch", "account_index")
}
if hasOpt = c.HasOption("freeswitch", "destination_index"); hasOpt {
cfg.FreeswitchDestIdx, _ = c.GetString("freeswitch", "destination_index")
}
if hasOpt = c.HasOption("freeswitch", "time_start_index"); hasOpt {
cfg.FreeswitchTimeStartIdx, _ = c.GetString("freeswitch", "time_start_index")
}
if hasOpt = c.HasOption("freeswitch", "duration_index"); hasOpt {
cfg.FreeswitchDurationIdx, _ = c.GetString("freeswitch", "duration_index")
}
return cfg, nil
}

View File

@@ -46,7 +46,7 @@ func TestDefaults(t *testing.T) {
eCfg.LogDBUser = ""
eCfg.LogDBPass = ""
eCfg.RPCEncoding = GOB
eCfg.DefaultReqType = ""
eCfg.DefaultReqType = RATED
eCfg.DefaultTOR = "0"
eCfg.DefaultTenant = "0"
eCfg.DefaultSubject = "0"
@@ -61,12 +61,21 @@ func TestDefaults(t *testing.T) {
eCfg.CDRSMediator = INTERNAL
eCfg.MediatorEnabled = false
eCfg.MediatorListen = "127.0.0.1:2032"
eCfg.MediatorCDRInDir = "/var/log/freeswitch/cdr-csv"
eCfg.MediatorCDROutDir = "/var/log/cgrates/cdr_out"
eCfg.MediatorRater = "127.0.0.1:2012"
eCfg.MediatorRaterReconnects = 3
eCfg.MediatorPseudoprepaid = false
eCfg.MediatorCDRType = "freeswitch_csv"
eCfg.MediatorCDRType = "freeswitch_http_json"
eCfg.MediatorAccIdField = "accid"
eCfg.MediatorSubjectFields = "subject"
eCfg.MediatorReqTypeFields = "reqtype"
eCfg.MediatorDirectionFields = "direction"
eCfg.MediatorTenantFields = "tenant"
eCfg.MediatorTORFields = "tor"
eCfg.MediatorAccountFields = "account"
eCfg.MediatorDestFields = "destination"
eCfg.MediatorTimeStartFields = "time_start"
eCfg.MediatorDurationFields = "duration"
eCfg.MediatorCDRInDir = "/var/log/freeswitch/cdr-csv"
eCfg.MediatorCDROutDir = "/var/log/cgrates/cdr/out/freeswitch/csv"
eCfg.SMEnabled = false
eCfg.SMSwitchType = FS
eCfg.SMRater = "127.0.0.1:2012"
@@ -75,15 +84,6 @@ func TestDefaults(t *testing.T) {
eCfg.FreeswitchServer = "127.0.0.1:8021"
eCfg.FreeswitchPass = "ClueCon"
eCfg.FreeswitchReconnects = 5
eCfg.FreeswitchUUIDIdx = "10"
eCfg.FreeswitchTORIdx = "-1"
eCfg.FreeswitchTenantIdx = "-1"
eCfg.FreeswitchDirectionIdx = "-1"
eCfg.FreeswitchSubjectIdx = "-1"
eCfg.FreeswitchAccountIdx = "-1"
eCfg.FreeswitchDestIdx = "-1"
eCfg.FreeswitchTimeStartIdx = "-1"
eCfg.FreeswitchDurationIdx = "-1"
if !reflect.DeepEqual(cfg ,eCfg ){
t.Log(eCfg)
t.Log(cfg)
@@ -148,12 +148,21 @@ func TestConfigFromFile(t *testing.T) {
eCfg.CDRSMediator = "test"
eCfg.MediatorEnabled = true
eCfg.MediatorListen = "test"
eCfg.MediatorCDRInDir = "test"
eCfg.MediatorCDROutDir = "test"
eCfg.MediatorRater = "test"
eCfg.MediatorRaterReconnects = 99
eCfg.MediatorPseudoprepaid = true
eCfg.MediatorCDRType = "test"
eCfg.MediatorAccIdField = "test"
eCfg.MediatorSubjectFields = "test"
eCfg.MediatorReqTypeFields = "test"
eCfg.MediatorDirectionFields = "test"
eCfg.MediatorTenantFields = "test"
eCfg.MediatorTORFields = "test"
eCfg.MediatorAccountFields = "test"
eCfg.MediatorDestFields = "test"
eCfg.MediatorTimeStartFields = "test"
eCfg.MediatorDurationFields = "test"
eCfg.MediatorCDRInDir = "test"
eCfg.MediatorCDROutDir = "test"
eCfg.SMEnabled = true
eCfg.SMSwitchType = "test"
eCfg.SMRater = "test"
@@ -162,15 +171,6 @@ func TestConfigFromFile(t *testing.T) {
eCfg.FreeswitchServer = "test"
eCfg.FreeswitchPass = "test"
eCfg.FreeswitchReconnects = 99
eCfg.FreeswitchUUIDIdx = "test"
eCfg.FreeswitchTORIdx = "test"
eCfg.FreeswitchTenantIdx = "test"
eCfg.FreeswitchDirectionIdx = "test"
eCfg.FreeswitchSubjectIdx = "test"
eCfg.FreeswitchAccountIdx = "test"
eCfg.FreeswitchDestIdx = "test"
eCfg.FreeswitchTimeStartIdx = "test"
eCfg.FreeswitchDurationIdx = "test"
if !reflect.DeepEqual(cfg ,eCfg ){
t.Log(eCfg)
t.Log(cfg)

View File

@@ -1,4 +1,5 @@
### Test data, not for production usage
# Test Data.
# NOT A REAL CONFIGURATION FILE
[global]
datadb_type = test # The main database: <redis>.
@@ -6,23 +7,23 @@ datadb_host = test # Database host address.
datadb_port = test # Port to reach the database.
datadb_name = test # The name of the database to connect to.
datadb_user = test # Username to use when connecting to database.
datadb_passwd = test # Password to use when connecting to database.
logdb_type = test # Log/stored database type to use: <same|postgres|mongo|redis>
datadb_passwd = test # Password to use when connecting to database.
logdb_type = test # Log/stored database type to use: <same|postgres|mongo|redis>
logdb_host = test # The host to connect to. Values that start with / are for UNIX domain sockets.
logdb_port = test # The port to reach the logdb.
logdb_name = test # The name of the log database to connect to.
logdb_user = test # Username to use when connecting to logdb.
logdb_passwd = test # Password to use when connecting to logdb.
logdb_user = test # Username to use when connecting to logdb.
logdb_passwd = test # Password to use when connecting to logdb.
rpc_encoding = test # RPC encoding used on APIs: <gob|json>.
default_reqtype = test # Default request type to consider when missing from requests: <""|prepaid|postpaid|pseudoprepaid>.
default_reqtype = test # Default request type to consider when missing from requests: <""|prepaid|postpaid|pseudoprepaid|rated>.
default_tor = test # Default Type of Record to consider when missing from requests.
default_tenant = test # Default Tenant to consider when missing from requests.
default_subject = test # Default rating Subject to consider when missing from requests.
[balancer]
enabled = true # Start Balancer service: <true|false>.
listen = test # Balancer listen interface: <disabled|x.y.z.y:1234>.
enabled = true # Start Balancer service: <true|false>.
listen = test # Balancer listen interface: <disabled|x.y.z.y:1234>.
[rater]
enabled = true # Enable Rater service: <true|false>.
@@ -40,12 +41,21 @@ mediator = test # Address where to reach the Mediator. Empty for disabling m
[mediator]
enabled = true # Starts Mediator service: <true|false>.
listen = test # Mediator's listening interface: <internal>.
rater = test # Address where to reach the Rater.
rater = test # Address where to reach the Rater: <internal|x.y.z.y:1234>
rater_reconnects = 99 # Number of reconnects to rater before giving up.
pseudoprepaid = true # Execute debits together with pricing: <true|false>.
cdr_type = test # CDR type <freeswitch_cdr>.
cdr_in_dir = test # Absolute path towards the directory where the CDRs are kept.
cdr_out_dir = test # Absolute path towards the directory where processed CDRs will be exported.
cdr_type = test # CDR type <freeswitch_http_json|freeswitch_file_csv>.
accid_field = test # Name of field identifying accounting id used during mediation. Use index number in case of .csv cdrs.
subject_fields = test # Name of subject fields to be used during mediation. Use index numbers in case of .csv cdrs.
reqtype_fields = test # Name of request type fields to be used during mediation. Use index number in case of .csv cdrs.
direction_fields = test # Name of direction fields to be used during mediation. Use index numbers in case of .csv cdrs.
tenant_fields = test # Name of tenant fields to be used during mediation. Use index numbers in case of .csv cdrs.
tor_fields = test # Name of tor fields to be used during mediation. Use index numbers in case of .csv cdrs.
account_fields = test # Name of account fields to be used during mediation. Use index numbers in case of .csv cdrs.
destination_fields = test # Name of destination fields to be used during mediation. Use index numbers in case of .csv cdrs.
time_start_fields = test # Name of time_start fields to be used during mediation. Use index numbers in case of .csv cdrs.
duration_fields = test # Name of duration fields to be used during mediation. Use index numbers in case of .csv cdrs.
cdr_in_dir = test # Absolute path towards the directory where the CDRs are kept (file stored CDRs).
cdr_out_dir = test # Absolute path towards the directory where processed CDRs will be exported (file stored CDRs).
[session_manager]
enabled = true # Starts SessionManager service: <true|false>.
@@ -58,14 +68,4 @@ debit_interval = 99 # Interval to perform debits on.
server = test # Adress where to connect to FreeSWITCH socket.
passwd = test # FreeSWITCH socket password.
reconnects = 99 # Number of attempts on connect failure.
uuid_index = test # Index of the UUID info in the CDR file.
direction_index = test # Index of the CallDirection info in the CDR file.
tor_index = test # Index of the TypeOfRecord info in the CDR file.
tenant_index = test # Index of the Tenant info in the CDR file.
subject_index = test # Index of the Subject info in the CDR file. -1 to query database instead of rater
account_index = test # Index of the Account info in the CDR file.
destination_index = test # Index of the Destination info in the CDR file.
time_start_index = test # Index of the TimeStart info in the CDR file.
duration_index = test # Index of the CallDuration info in the CDR file.

View File

@@ -18,7 +18,7 @@
# logdb_user = # Username to use when connecting to logdb.
# logdb_passwd = # Password to use when connecting to logdb.
# rpc_encoding = gob # RPC encoding used on APIs: <gob|json>.
# default_reqtype = # Default request type to consider when missing from requests: <""|prepaid|postpaid|pseudoprepaid>.
# default_reqtype = rated # Default request type to consider when missing from requests: <""|prepaid|postpaid|pseudoprepaid|rated>.
# default_tor = 0 # Default Type of Record to consider when missing from requests.
# default_tenant = 0 # Default Tenant to consider when missing from requests.
# default_subject = 0 # Default rating Subject to consider when missing from requests.
@@ -39,17 +39,26 @@
[cdrs]
# listen=127.0.0.1:2022 # CDRS's listening interface: <x.y.z.y:1234>.
# freeswitch_json_enabled=false # Enable the handler for FreeSWITCH JSON CDRs: <true|false>.
# mediator = internal # Address where to reach the Mediator. Empty for disabling mediation. <""|internal>
# mediator = # Address where to reach the Mediator. Empty for disabling mediation. <""|internal>
[mediator]
# enabled = false # Starts Mediator service: <true|false>.
# listen=internal # Mediator's listening interface: <internal>.
# rater = 127.0.0.1:2012 # Address where to reach the Rater.
# rater = 127.0.0.1:2012 # Address where to reach the Rater: <internal|x.y.z.y:1234>
# rater_reconnects = 3 # Number of reconnects to rater before giving up.
# pseudoprepaid = false # Execute debits together with pricing: <true|false>.
# cdr_type = freeswitch_cdr # CDR type <freeswitch_cdr>.
# cdr_in_dir = /var/log/freeswitch/cdr-csv # Absolute path towards the directory where the CDRs are kept.
# cdr_out_dir = /var/log/cgrates/cdr_out # Absolute path towards the directory where processed CDRs will be exported.
# cdr_type = freeswitch_http_json # CDR type <freeswitch_http_json|freeswitch_file_csv>.
# accid_field = accid # Name of field identifying accounting id used during mediation. Use index number in case of .csv cdrs.
# subject_fields = subject # Name of subject fields to be used during mediation. Use index numbers in case of .csv cdrs.
# reqtype_fields = -1 # Name of request type fields to be used during mediation. Use index number in case of .csv cdrs.
# direction_fields = direction # Name of direction fields to be used during mediation. Use index numbers in case of .csv cdrs.
# tenant_fields = tenant # Name of tenant fields to be used during mediation. Use index numbers in case of .csv cdrs.
# tor_fields = tor # Name of tor fields to be used during mediation. Use index numbers in case of .csv cdrs.
# account_fields = account # Name of account fields to be used during mediation. Use index numbers in case of .csv cdrs.
# destination_fields = destination # Name of destination fields to be used during mediation. Use index numbers in case of .csv cdrs.
# time_start_fields = time_start # Name of time_start fields to be used during mediation. Use index numbers in case of .csv cdrs.
# duration_fields = duration # Name of duration fields to be used during mediation. Use index numbers in case of .csv cdrs.
# cdr_in_dir = /var/log/freeswitch/cdr-csv # Absolute path towards the directory where the CDRs are kept (file stored CDRs).
# cdr_out_dir = /var/log/cgrates/cdr/out/freeswitch/csv # Absolute path towards the directory where processed CDRs will be exported (file stored CDRs).
[session_manager]
# enabled = false # Starts SessionManager service: <true|false>.
@@ -62,14 +71,4 @@
# server = 127.0.0.1:8021 # Adress where to connect to FreeSWITCH socket.
# passwd = ClueCon # FreeSWITCH socket password.
# reconnects = 5 # Number of attempts on connect failure.
# uuid_index = 10 # Index of the UUID info in the CDR file.
# direction_index = -1 # Index of the CallDirection info in the CDR file.
# tor_index = -1 # Index of the TypeOfRecord info in the CDR file.
# tenant_index = -1 # Index of the Tenant info in the CDR file.
# subject_index = -1 # Index of the Subject info in the CDR file. -1 to query database instead of rater
# account_index = -1 # Index of the Account info in the CDR file.
# destination_index = -1 # Index of the Destination info in the CDR file.
# time_start_index = -1 # Index of the TimeStart info in the CDR file.
# duration_index = -1 # Index of the CallDuration info in the CDR file.

View File

@@ -54,7 +54,6 @@ type Mediator struct {
connector rater.Connector
loggerDb rater.DataStorage
outputDir string
pseudoPrepaid bool
directionIndexs,
torIndexs,
tenantIndexs,
@@ -69,15 +68,11 @@ type Mediator struct {
// Creates a new mediator object parsing the indexses
func NewMediator(connector rater.Connector,
loggerDb rater.DataStorage,
outputDir string,
pseudoPrepaid bool,
directionIndexs, torIndexs, tenantIndexs, subjectIndexs, accountIndexs, destinationIndexs,
timeStartIndexs, durationIndexs, uuidIndexs string) (m *Mediator, err error) {
cfg *config.CGRConfig) (m *Mediator, err error) {
m = &Mediator{
connector: connector,
loggerDb: loggerDb,
outputDir: outputDir,
pseudoPrepaid: pseudoPrepaid,
}
idxs := []string{directionIndexs, torIndexs, tenantIndexs, subjectIndexs, accountIndexs,
destinationIndexs, timeStartIndexs, durationIndexs, uuidIndexs}
@@ -210,7 +205,7 @@ func (m *Mediator) getCostsFromRater(record []string, runIdx int) (cc *rater.Cal
Destination: record[m.destinationIndexs[runIdx]],
TimeStart: t1,
TimeEnd: t1.Add(d)}
if m.pseudoPrepaid {
if cfg.DefaultReqType == PSEUDOPREPAID { //ToDo: Implement here dynamically getting the tor out of record instance
err = m.connector.Debit(cd, cc)
} else {
err = m.connector.GetCost(cd, cc)