mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Merge branch 'master' of github.com:cgrates/cgrates
This commit is contained in:
@@ -33,6 +33,7 @@ import (
|
||||
"net/http"
|
||||
"net/rpc"
|
||||
"net/rpc/jsonrpc"
|
||||
"os"
|
||||
"runtime"
|
||||
"strconv"
|
||||
"strings"
|
||||
@@ -85,7 +86,8 @@ var (
|
||||
sm_rpc_encoding = GOB // use JSON for RPC encoding
|
||||
|
||||
mediator_enabled = false
|
||||
mediator_cdr_path = "" // Freeswitch Master CSV CDR file.
|
||||
mediator_cdr_path = "" // Freeswitch Master CSV CDR path.
|
||||
mediator_cdr_out_path = "" // Freeswitch Master CSV CDR output path.
|
||||
mediator_rater = INTERNAL // address where to access rater. Can be internal, direct rater address or the address of a balancer
|
||||
mediator_rpc_encoding = GOB // use JSON for RPC encoding
|
||||
mediator_skipdb = false
|
||||
@@ -143,6 +145,7 @@ func readConfig(c *conf.ConfigFile) {
|
||||
|
||||
mediator_enabled, _ = c.GetBool("mediator", "enabled")
|
||||
mediator_cdr_path, _ = c.GetString("mediator", "cdr_path")
|
||||
mediator_cdr_out_path, _ = c.GetString("mediator", "cdr_out_path")
|
||||
mediator_rater, _ = c.GetString("mediator", "rater")
|
||||
mediator_rpc_encoding, _ = c.GetString("mediator", "rpc_encoding")
|
||||
mediator_skipdb, _ = c.GetBool("mediator", "skipdb")
|
||||
@@ -223,7 +226,15 @@ func startMediator(responder *timespans.Responder, loggerDb timespans.DataStorag
|
||||
}
|
||||
connector = ×pans.RPCClientConnector{client}
|
||||
}
|
||||
m, err := mediator.NewMediator(connector, loggerDb, mediator_skipdb, freeswitch_direction, freeswitch_tor, freeswitch_tenant, freeswitch_subject, freeswitch_account, freeswitch_destination, freeswitch_time_start, freeswitch_time_end)
|
||||
if _, err := os.Stat(mediator_cdr_path); err != nil {
|
||||
timespans.Logger.Crit(fmt.Sprintf("The input path for mediator does not exist: %v", mediator_cdr_path))
|
||||
exitChan <- true
|
||||
}
|
||||
if _, err := os.Stat(mediator_cdr_out_path); err != nil {
|
||||
timespans.Logger.Crit(fmt.Sprintf("The output path for mediator does not exist: %v", mediator_cdr_out_path))
|
||||
exitChan <- true
|
||||
}
|
||||
m, err := mediator.NewMediator(connector, loggerDb, mediator_skipdb, mediator_cdr_out_path, freeswitch_direction, freeswitch_tor, freeswitch_tenant, freeswitch_subject, freeswitch_account, freeswitch_destination, freeswitch_time_start, freeswitch_time_end)
|
||||
if err != nil {
|
||||
timespans.Logger.Crit(fmt.Sprintf("Failed to start mediator: %v", err))
|
||||
exitChan <- true
|
||||
|
||||
@@ -53,7 +53,8 @@ rpc_encoding = test # use JSON for RPC encoding
|
||||
|
||||
[mediator]
|
||||
enabled = true
|
||||
cdr_path = test # Freeswitch Master CSV CDR file.
|
||||
cdr_path = test # Freeswitch Master CSV CDR path.
|
||||
cdr_out_path = test
|
||||
rater = test #address where to access rater. Can be internal, direct rater address or the address of a balancer
|
||||
rpc_encoding = test # use JSON for RPC encoding
|
||||
skipdb = true
|
||||
@@ -126,6 +127,7 @@ func TestConfig(t *testing.T) {
|
||||
|
||||
mediator_enabled != true ||
|
||||
mediator_cdr_path != "test" ||
|
||||
mediator_cdr_out_path != "test" ||
|
||||
mediator_rater != "test" ||
|
||||
mediator_rpc_encoding != "test" ||
|
||||
mediator_skipdb != true ||
|
||||
@@ -170,6 +172,7 @@ func TestConfig(t *testing.T) {
|
||||
t.Log(sm_rpc_encoding)
|
||||
t.Log(mediator_enabled)
|
||||
t.Log(mediator_cdr_path)
|
||||
t.Log(mediator_cdr_out_path)
|
||||
t.Log(mediator_rater)
|
||||
t.Log(stats_enabled)
|
||||
t.Log(stats_listen)
|
||||
|
||||
@@ -37,6 +37,7 @@ rpc_encoding = gob # Use json or gob for RPC encoding
|
||||
[mediator]
|
||||
enabled = true # Start the mediator service
|
||||
cdr_path = /var/log/freeswitch # Freeswitch Master CSV CDR path
|
||||
cdr_out_path = /var/log/freeswitch/out # Freeswitch Master CSV CDR path
|
||||
rater = internal # Address where to access rater. Can be internal, direct rater address or the address of a balancer
|
||||
rpc_encoding = gob # Use json or gob for RPC encoding
|
||||
skipdb = true # Do not look in the database for logged cdrs, ask rater directly
|
||||
|
||||
@@ -25,6 +25,7 @@ logdb_name = cgrates # The name of the database to connect to.
|
||||
[mediator]
|
||||
enabled = true
|
||||
cdr_path = /tmp/cgrates # Freeswitch Master CSV CDR file.
|
||||
cdr_out_path = /tmp/cgrates/out # Freeswitch Master CSV CDR file.
|
||||
rater = internal #address where to access rater. Can be internal, direct rater address or the address of a balancer
|
||||
rpc_encoding = gob # use JSON for RPC encoding
|
||||
skipdb = false
|
||||
|
||||
@@ -59,7 +59,6 @@ Bellow there is a full configuration file:
|
||||
logdb_host = localhost # The host to connect to. Values that start with / are for UNIX domain sockets.
|
||||
logdb_name = cgrates # The name of the database to connect to.
|
||||
|
||||
|
||||
[balancer]
|
||||
enabled = false # Start balancer server
|
||||
listen = 127.0.0.1:2001 # Balancer listen interface
|
||||
@@ -73,8 +72,8 @@ Bellow there is a full configuration file:
|
||||
|
||||
[mediator]
|
||||
enabled = true # Start the mediator service
|
||||
cdr_file = Master.csv # Freeswitch Master CSV CDR file
|
||||
result_file = out.csv # Generated file containing CDR and price info
|
||||
cdr_path = /var/log/freeswitch # Freeswitch Master CSV CDR path
|
||||
cdr_out_path = /var/log/freeswitch/out # Freeswitch Master CSV CDR path
|
||||
rater = internal # Address where to access rater. Can be internal, direct rater address or the address of a balancer
|
||||
rpc_encoding = gob # Use json or gob for RPC encoding
|
||||
skipdb = true # Do not look in the database for logged cdrs, ask rater directly
|
||||
@@ -92,11 +91,19 @@ Bellow there is a full configuration file:
|
||||
[freeswitch]
|
||||
server = localhost:8021 # Freeswitch address host:port
|
||||
pass = ClueCon # Freeswtch address host:port
|
||||
|
||||
direction_index = 0
|
||||
tor_index = 1
|
||||
tenant_index = 2
|
||||
subject_index = 3
|
||||
account_index = 4
|
||||
destination_index = 5
|
||||
time_start_index = 6
|
||||
time_end_index = 7
|
||||
|
||||
[stats]
|
||||
enabled = true # Start the stats web server
|
||||
listen = 127.0.0.1:8000 # Web server address (for stat reports)
|
||||
media_path = /home/rif/cgrates/data # The path containig the css, js and templates for the web server
|
||||
media_path = /etc/cgrates/data # The path containig the css, js and templates for the web server
|
||||
|
||||
|
||||
There are various sections in the configuration file that define various services that the cgr-rater process can provide. If you are not interested in a certain service you can either leave it in the configuration with the enabled option set to false or remove the section entirely to reduce clutter.
|
||||
|
||||
@@ -32,16 +32,13 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
const (
|
||||
OUTPUT_DIR = "med_output"
|
||||
)
|
||||
|
||||
type csvindex int
|
||||
|
||||
type Mediator struct {
|
||||
connector timespans.Connector
|
||||
loggerDb timespans.DataStorage
|
||||
skipDb bool
|
||||
outputDir string
|
||||
directionIndex,
|
||||
torIndex,
|
||||
tenantIndex,
|
||||
@@ -52,11 +49,12 @@ type Mediator struct {
|
||||
timeEndIndex csvindex
|
||||
}
|
||||
|
||||
func NewMediator(connector timespans.Connector, loggerDb timespans.DataStorage, skipDb bool, directionIndex, torIndex, tenantIndex, subjectIndex, accountIndex, destinationIndex, timeStartIndex, timeEndIndex string) (*Mediator, error) {
|
||||
func NewMediator(connector timespans.Connector, loggerDb timespans.DataStorage, skipDb bool, outputDir, directionIndex, torIndex, tenantIndex, subjectIndex, accountIndex, destinationIndex, timeStartIndex, timeEndIndex string) (*Mediator, error) {
|
||||
m := &Mediator{
|
||||
connector: connector,
|
||||
loggerDb: loggerDb,
|
||||
skipDb: skipDb,
|
||||
outputDir: outputDir,
|
||||
}
|
||||
i, err := strconv.Atoi(directionIndex)
|
||||
if err != nil {
|
||||
@@ -116,7 +114,7 @@ func (m *Mediator) TrackCDRFiles(cdrPath string) (err error) {
|
||||
case ev := <-watcher.Event:
|
||||
if ev.Mask&inotify.IN_MOVED_TO != 0 {
|
||||
timespans.Logger.Info(fmt.Sprintf("Started to parse %v", ev.Name))
|
||||
err = m.parseCSV(cdrPath, ev.Name)
|
||||
err = m.parseCSV(ev.Name)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -128,7 +126,7 @@ func (m *Mediator) TrackCDRFiles(cdrPath string) (err error) {
|
||||
return
|
||||
}
|
||||
|
||||
func (m *Mediator) parseCSV(dir, cdrfn string) (err error) {
|
||||
func (m *Mediator) parseCSV(cdrfn string) (err error) {
|
||||
flag.Parse()
|
||||
file, err := os.Open(cdrfn)
|
||||
defer file.Close()
|
||||
@@ -138,9 +136,8 @@ func (m *Mediator) parseCSV(dir, cdrfn string) (err error) {
|
||||
}
|
||||
csvReader := csv.NewReader(bufio.NewReader(file))
|
||||
|
||||
dir = path.Join(dir, OUTPUT_DIR)
|
||||
os.Mkdir(dir, 0777)
|
||||
fout, err := os.Create(path.Join(dir, "test.out"))
|
||||
_, fn := path.Split(cdrfn)
|
||||
fout, err := os.Create(path.Join(m.outputDir, fn))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -177,8 +174,14 @@ func (m *Mediator) GetCostsFromDB(record []string) (cc *timespans.CallCost, err
|
||||
}
|
||||
|
||||
func (m *Mediator) GetCostsFromRater(record []string) (cc *timespans.CallCost, err error) {
|
||||
t1, _ := time.Parse("2012-05-21 17:48:20", record[m.timeStartIndex])
|
||||
t2, _ := time.Parse("2012-05-21 17:48:20", record[m.timeEndIndex])
|
||||
t1, err := time.Parse("2012-05-21 17:48:20", record[m.timeStartIndex])
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
t2, err := time.Parse("2012-05-21 17:48:20", record[m.timeEndIndex])
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
cd := timespans.CallDescriptor{
|
||||
Direction: record[m.directionIndex],
|
||||
Tenant: record[m.tenantIndex],
|
||||
|
||||
Reference in New Issue
Block a user