mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
updated loader for multiple database types
This commit is contained in:
@@ -91,6 +91,11 @@ func main() {
|
||||
if err = client.Call("Responder.Debit", cd, &result); err == nil {
|
||||
fmt.Println(result)
|
||||
}
|
||||
case "maxdebit":
|
||||
result := timespans.CallCost{}
|
||||
if err = client.Call("Responder.MaxDebit", cd, &result); err == nil {
|
||||
fmt.Println(result)
|
||||
}
|
||||
case "getmaxsessiontime":
|
||||
var result float64
|
||||
if err = client.Call("Responder.GetMaxSessionTime", cd, &result); err == nil {
|
||||
|
||||
@@ -24,15 +24,27 @@ import (
|
||||
"log"
|
||||
"path"
|
||||
"regexp"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
const (
|
||||
POSTGRES = "postgres"
|
||||
MONGO = "mongo"
|
||||
REDIS = "redis"
|
||||
)
|
||||
|
||||
var (
|
||||
separator = flag.String("separator", ",", "Default field separator")
|
||||
redissrv = flag.String("redissrv", "127.0.0.1:6379", "redis server address (tcp:127.0.0.1:6379)")
|
||||
redisdb = flag.Int("redisdb", 10, "redis database number (10)")
|
||||
redispass = flag.String("pass", "", "redis database password")
|
||||
flush = flag.Bool("flush", false, "Flush the database before importing")
|
||||
dataPath = flag.String("path", ".", "The path containing the data files")
|
||||
//separator = flag.String("separator", ",", "Default field separator")
|
||||
db_type = flag.String("dbtype", REDIS, "The type of the database (redis|mongo|postgres)")
|
||||
db_host = flag.String("dbhost", "localhost", "The database host to connect to.")
|
||||
db_port = flag.String("dbport", "6379", "The database port to bind to.")
|
||||
db_name = flag.String("dbname", "10", "he name/number of the database to connect to.")
|
||||
db_user = flag.String("dbuser", "", "The database user to sign in as.")
|
||||
db_pass = flag.String("dbpass", "", "The database user's password.")
|
||||
|
||||
flush = flag.Bool("flush", false, "Flush the database before importing")
|
||||
dataPath = flag.String("path", ".", "The path containing the data files")
|
||||
|
||||
destinationsFn = "Destinations.csv"
|
||||
ratesFn = "Rates.csv"
|
||||
timingsFn = "Timings.csv"
|
||||
@@ -89,7 +101,8 @@ func main() {
|
||||
}
|
||||
}
|
||||
|
||||
sep = []rune(*separator)[0]
|
||||
//sep = []rune(*separator)[0]
|
||||
sep = ','
|
||||
csvr := timespans.NewFileCSVReader()
|
||||
err := csvr.LoadDestinations(path.Join(*dataPath, destinationsFn), sep)
|
||||
if err != nil {
|
||||
@@ -127,12 +140,29 @@ func main() {
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
storage, err := timespans.NewRedisStorage(*redissrv, *redisdb, *redispass)
|
||||
//storage, err := timespans.NewMongoStorage("localhost", "cgrates")
|
||||
var getter timespans.StorageGetter
|
||||
switch *db_type {
|
||||
case REDIS:
|
||||
db_nb, err := strconv.Atoi(*db_name)
|
||||
if err != nil {
|
||||
log.Fatal("Redis db name must be an integer!")
|
||||
}
|
||||
if *db_port != "" {
|
||||
*db_host += ":" + *db_port
|
||||
}
|
||||
getter, err = timespans.NewRedisStorage(*db_host, db_nb, *db_pass)
|
||||
case MONGO:
|
||||
getter, err = timespans.NewMongoStorage(*db_host, *db_port, *db_name, *db_user, *db_pass)
|
||||
case POSTGRES:
|
||||
getter, err = timespans.NewPostgresStorage(*db_host, *db_port, *db_name, *db_user, *db_pass)
|
||||
default:
|
||||
log.Fatal("Unknown data db type, exiting!")
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
log.Fatal("Could not open database connection: %v", err)
|
||||
}
|
||||
|
||||
// writing to database
|
||||
csvr.WriteToDatabase(storage, *flush, true)
|
||||
csvr.WriteToDatabase(getter, *flush, true)
|
||||
}
|
||||
|
||||
@@ -305,6 +305,9 @@ func main() {
|
||||
timespans.Logger.Crit("Redis db name must be an integer!")
|
||||
exitChan <- true
|
||||
}
|
||||
if data_db_port != "" {
|
||||
data_db_host += ":" + data_db_port
|
||||
}
|
||||
getter, err = timespans.NewRedisStorage(data_db_host, db_nb, data_db_password)
|
||||
case MONGO:
|
||||
getter, err = timespans.NewMongoStorage(data_db_host, data_db_port, data_db_name, data_db_user, data_db_password)
|
||||
|
||||
@@ -125,35 +125,20 @@ This tool is used for importing the data from CSV files into the CGRateS databas
|
||||
|
||||
:Example: cgr-loader -destinations=Destinations.csv
|
||||
|
||||
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. It logs the calls information to a postgres database in order to be used by the mediator tool.
|
||||
|
||||
::
|
||||
|
||||
rif@grace:~$ cgr-sessionmanager --help
|
||||
Usage of cgr-sessionmanager:
|
||||
-balancer="127.0.0.1:2000": balancer address host:port
|
||||
-freeswitchpass="ClueCon": freeswitch address host:port
|
||||
-freeswitchsrv="localhost:8021": freeswitch address host:port
|
||||
-json=false: use JSON for RPC encoding
|
||||
-redisdb=10: redis database number
|
||||
-redissrv="127.0.0.1:6379": redis address host:port
|
||||
-standalone=false: run standalone (run as a rater)
|
||||
|
||||
:Example: cgr-sessionmanager -standalone=true
|
||||
|
||||
cgr-mediator
|
||||
~~~~~~~~~~~~
|
||||
The scheduler is loading the timed actions form database and executes them as appropriate, It will execute all run once actions as they are loaded. It will reload all the action timings from the database when it received system HUP signal (pkill -1 cgr-schedule).
|
||||
|
||||
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::
|
||||
|
||||
CREATE TABLE callcosts (
|
||||
uuid varchar(80) primary key,direction varchar(32),
|
||||
tenant varchar(32),tor varchar(32),
|
||||
uuid varchar(80) primary key,
|
||||
direction varchar(32),
|
||||
tenant varchar(32),
|
||||
tor varchar(32),
|
||||
subject varchar(32),
|
||||
account varchar(32),
|
||||
destination varchar(32),
|
||||
@@ -164,29 +149,5 @@ The structure of the table (as an SQL command) is the following::
|
||||
|
||||
::
|
||||
|
||||
rif@grace:~$ cgr-mediator --help
|
||||
Usage of cgr-mediator:
|
||||
-dbname="cgrates": The name of the database to connect to.
|
||||
-freeswitchcdr="Master.csv": Freeswitch Master CSV CDR file.
|
||||
-host="localhost": The host to connect to. Values that start with / are for UNIX domain sockets.
|
||||
-password="": The user's password.
|
||||
-port="5432": The port to bind to.
|
||||
-resultfile="out.csv": Generated file containing CDR and price info.
|
||||
-user="": The user to sign in as.
|
||||
|
||||
:Example: cgr-mediator -freeswitchcdr="logs.csv"
|
||||
|
||||
cgr-scheduler
|
||||
~~~~~~~~~~~~~
|
||||
|
||||
The scheduler is loading the timed actions form database and executes them as appropriate, It will execute all run once actions as they are loaded. It will reload all the action timings from the database when it received system HUP signal (pkill -1 cgr-schedule).
|
||||
|
||||
::
|
||||
|
||||
rif@grace:~$ cgr-scheduler --help
|
||||
Usage of cgr-scheduler:
|
||||
-pass="": redis database password
|
||||
-rdb=10: redis database number (10)
|
||||
-redisserver="127.0.0.1:6379": redis server address (tcp:127.0.0.1:6379)
|
||||
|
||||
:Example: cgr-scheduler -rdb=2 -pass="secret"
|
||||
Reference in New Issue
Block a user