mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Adding CdrcConfig.DataUsageMultiplyFactor config option
This commit is contained in:
@@ -41,6 +41,9 @@ func NewCdrcConfigFromCgrXmlCdrcCfg(id string, xmlCdrcCfg *CgrXmlCdrcCfg) (*Cdrc
|
||||
if xmlCdrcCfg.FieldSeparator != nil {
|
||||
cdrcCfg.FieldSeparator = *xmlCdrcCfg.FieldSeparator
|
||||
}
|
||||
if xmlCdrcCfg.DataUsageMultiplyFactor != nil {
|
||||
cdrcCfg.DataUsageMultiplyFactor = *xmlCdrcCfg.DataUsageMultiplyFactor
|
||||
}
|
||||
if xmlCdrcCfg.RunDelay != nil {
|
||||
cdrcCfg.RunDelay = time.Duration(*xmlCdrcCfg.RunDelay) * time.Second
|
||||
}
|
||||
@@ -82,16 +85,17 @@ func NewDefaultCdrcConfig() *CdrcConfig {
|
||||
answerTimeFld, _ := NewCfgCdrFieldWithDefaults(false, []*utils.RSRField{&utils.RSRField{Id: "12"}}, nil, nil, &aTimeTag, nil, nil, nil, nil, nil, nil)
|
||||
usageFld, _ := NewCfgCdrFieldWithDefaults(false, []*utils.RSRField{&utils.RSRField{Id: "13"}}, nil, nil, &usageTag, nil, nil, nil, nil, nil, nil)
|
||||
cdrcCfg := &CdrcConfig{
|
||||
Id: utils.META_DEFAULT,
|
||||
Enabled: false,
|
||||
CdrsAddress: "",
|
||||
CdrFormat: utils.CSV,
|
||||
FieldSeparator: utils.FIELDS_SEP,
|
||||
RunDelay: time.Duration(0),
|
||||
CdrInDir: "/var/log/cgrates/cdrc/in",
|
||||
CdrOutDir: "/var/log/cgrates/cdrc/out",
|
||||
CdrSourceId: utils.CSV,
|
||||
CdrFields: []*CfgCdrField{torFld, accIdFld, reqTypeFld, directionFld, tenantFld, categoryFld, acntFld, subjFld, dstFld, setupTimeFld, answerTimeFld, usageFld},
|
||||
Id: utils.META_DEFAULT,
|
||||
Enabled: false,
|
||||
CdrsAddress: "",
|
||||
CdrFormat: utils.CSV,
|
||||
FieldSeparator: utils.FIELDS_SEP,
|
||||
DataUsageMultiplyFactor: 1.0,
|
||||
RunDelay: time.Duration(0),
|
||||
CdrInDir: "/var/log/cgrates/cdrc/in",
|
||||
CdrOutDir: "/var/log/cgrates/cdrc/out",
|
||||
CdrSourceId: utils.CSV,
|
||||
CdrFields: []*CfgCdrField{torFld, accIdFld, reqTypeFld, directionFld, tenantFld, categoryFld, acntFld, subjFld, dstFld, setupTimeFld, answerTimeFld, usageFld},
|
||||
}
|
||||
return cdrcCfg
|
||||
}
|
||||
@@ -111,6 +115,9 @@ func NewCdrcConfigFromFileParams(c *conf.ConfigFile) (*CdrcConfig, error) {
|
||||
if hasOpt := c.HasOption("cdrc", "field_separator"); hasOpt {
|
||||
cdrcCfg.FieldSeparator, _ = c.GetString("cdrc", "field_separator")
|
||||
}
|
||||
if hasOpt := c.HasOption("cdrc", "data_usage_multiply_factor"); hasOpt {
|
||||
cdrcCfg.DataUsageMultiplyFactor, _ = c.GetFloat64("cdrc", "data_usage_multiply_factor")
|
||||
}
|
||||
if hasOpt := c.HasOption("cdrc", "run_delay"); hasOpt {
|
||||
durStr, _ := c.GetString("cdrc", "run_delay")
|
||||
if cdrcCfg.RunDelay, err = utils.ParseDurationWithSecs(durStr); err != nil {
|
||||
@@ -187,14 +194,15 @@ func NewCdrcConfigFromFileParams(c *conf.ConfigFile) (*CdrcConfig, error) {
|
||||
}
|
||||
|
||||
type CdrcConfig struct {
|
||||
Id string // Configuration label
|
||||
Enabled bool // Enable/Disable the profile
|
||||
CdrsAddress string // The address where CDRs can be reached
|
||||
CdrFormat string // The type of CDR file to process <csv>
|
||||
FieldSeparator string // The separator to use when reading csvs
|
||||
RunDelay time.Duration // Delay between runs, 0 for inotify driven requests
|
||||
CdrInDir string // Folder to process CDRs from
|
||||
CdrOutDir string // Folder to move processed CDRs to
|
||||
CdrSourceId string // Source identifier for the processed CDRs
|
||||
CdrFields []*CfgCdrField // List of fields to be processed
|
||||
Id string // Configuration label
|
||||
Enabled bool // Enable/Disable the profile
|
||||
CdrsAddress string // The address where CDRs can be reached
|
||||
CdrFormat string // The type of CDR file to process <csv>
|
||||
FieldSeparator string // The separator to use when reading csvs
|
||||
DataUsageMultiplyFactor float64 // Conversion factor for data usage
|
||||
RunDelay time.Duration // Delay between runs, 0 for inotify driven requests
|
||||
CdrInDir string // Folder to process CDRs from
|
||||
CdrOutDir string // Folder to move processed CDRs to
|
||||
CdrSourceId string // Source identifier for the processed CDRs
|
||||
CdrFields []*CfgCdrField // List of fields to be processed
|
||||
}
|
||||
|
||||
@@ -28,15 +28,16 @@ import (
|
||||
|
||||
func TestNewDefaultCdrcConfig(t *testing.T) {
|
||||
eDfCdrcConfig := &CdrcConfig{
|
||||
Id: utils.META_DEFAULT,
|
||||
Enabled: false,
|
||||
CdrsAddress: "",
|
||||
CdrFormat: utils.CSV,
|
||||
FieldSeparator: utils.FIELDS_SEP,
|
||||
RunDelay: time.Duration(0),
|
||||
CdrInDir: "/var/log/cgrates/cdrc/in",
|
||||
CdrOutDir: "/var/log/cgrates/cdrc/out",
|
||||
CdrSourceId: utils.CSV,
|
||||
Id: utils.META_DEFAULT,
|
||||
Enabled: false,
|
||||
CdrsAddress: "",
|
||||
CdrFormat: utils.CSV,
|
||||
FieldSeparator: utils.FIELDS_SEP,
|
||||
DataUsageMultiplyFactor: 1.0,
|
||||
RunDelay: time.Duration(0),
|
||||
CdrInDir: "/var/log/cgrates/cdrc/in",
|
||||
CdrOutDir: "/var/log/cgrates/cdrc/out",
|
||||
CdrSourceId: utils.CSV,
|
||||
CdrFields: []*CfgCdrField{
|
||||
&CfgCdrField{
|
||||
Tag: utils.TOR,
|
||||
|
||||
@@ -236,6 +236,7 @@ func TestConfigFromFile(t *testing.T) {
|
||||
cdrcCfg.RunDelay = time.Duration(99) * time.Second
|
||||
cdrcCfg.CdrFormat = "test"
|
||||
cdrcCfg.FieldSeparator = ";"
|
||||
cdrcCfg.DataUsageMultiplyFactor = 99.0
|
||||
cdrcCfg.CdrInDir = "test"
|
||||
cdrcCfg.CdrOutDir = "test"
|
||||
cdrcCfg.CdrSourceId = "test"
|
||||
|
||||
@@ -68,6 +68,7 @@ cdrs = test # Address where to reach CDR server
|
||||
run_delay = 99 # Period to sleep between two runs, 0 to use automation via inotify
|
||||
cdr_format = test # CDR file format <csv>.
|
||||
field_separator =; # Csv separator, one character only and should be next to equal sign
|
||||
data_usage_multiply_factor = 99.0
|
||||
cdr_in_dir = test # Absolute path towards the direccategoryy where the CDRs are kept (file scategoryed CDRs).
|
||||
cdr_out_dir = test # Absolute path towards the direccategoryy where processed CDRs will be moved after processing.
|
||||
cdr_source_id = test # Tag identifying the source of the CDRs within CGRS database.
|
||||
|
||||
@@ -69,6 +69,7 @@ func TestParseXmlCdrcConfig(t *testing.T) {
|
||||
<cdrs_address>internal</cdrs_address>
|
||||
<cdr_format>csv</cdr_format>
|
||||
<field_separator>,</field_separator>
|
||||
<data_usage_multiply_factor>1024.0</data_usage_multiply_factor>
|
||||
<run_delay>0</run_delay>
|
||||
<cdr_in_dir>/var/log/cgrates/cdrc/in</cdr_in_dir>
|
||||
<cdr_out_dir>/var/log/cgrates/cdrc/out</cdr_out_dir>
|
||||
@@ -111,11 +112,12 @@ func TestGetCdrcCfgs(t *testing.T) {
|
||||
cdrsAddr := "internal"
|
||||
cdrFormat := "csv"
|
||||
fldSep := ","
|
||||
dataUsageMultiplyFactor := 1024.0
|
||||
runDelay := int64(0)
|
||||
cdrInDir := "/var/log/cgrates/cdrc/in"
|
||||
cdrOutDir := "/var/log/cgrates/cdrc/out"
|
||||
cdrSrcId := "freeswitch_csv"
|
||||
expectCdrc := &CgrXmlCdrcCfg{Enabled: &enabled, CdrsAddress: &cdrsAddr, CdrFormat: &cdrFormat, FieldSeparator: &fldSep,
|
||||
expectCdrc := &CgrXmlCdrcCfg{Enabled: &enabled, CdrsAddress: &cdrsAddr, CdrFormat: &cdrFormat, FieldSeparator: &fldSep, DataUsageMultiplyFactor: &dataUsageMultiplyFactor,
|
||||
RunDelay: &runDelay, CdrInDir: &cdrInDir, CdrOutDir: &cdrOutDir, CdrSourceId: &cdrSrcId}
|
||||
accIdTag, reqTypeTag, dirTag, tntTag, categTag, acntTag, subjTag, dstTag, sTimeTag, aTimeTag, usageTag, extr1, extr2 := utils.ACCID,
|
||||
utils.REQTYPE, utils.DIRECTION, utils.TENANT, utils.CATEGORY, utils.ACCOUNT, utils.SUBJECT, utils.DESTINATION, utils.SETUP_TIME, utils.ANSWER_TIME, utils.USAGE, "extr1", "extr2"
|
||||
|
||||
@@ -32,7 +32,7 @@ func TestXmlCdreCfgParseXmlConfig(t *testing.T) {
|
||||
<document type="cgrates/xml">
|
||||
<configuration section="cdre" id="CDRE-FW1">
|
||||
<cdr_format>fwv</cdr_format>
|
||||
<data_usage_multiply_factor>0.0</data_usage_multiply_factor>
|
||||
<data_usage_multiply_factor>1.0</data_usage_multiply_factor>
|
||||
<cost_multiply_factor>0.0</cost_multiply_factor>
|
||||
<cost_rounding_decimals>-1</cost_rounding_decimals>
|
||||
<cost_shift_digits>0</cost_shift_digits>
|
||||
@@ -62,7 +62,7 @@ func TestXmlCdreCfgParseXmlConfig(t *testing.T) {
|
||||
<field tag="TOR" type="constant" value="02" width="2" />
|
||||
<field tag="SubtypeTOR" type="constant" value="11" width="4" />
|
||||
<field tag="SetupTime" type="cdrfield" value="start_time" layout="020106150400" width="12" />
|
||||
<field tag="Duration" type="cdrfield" value="duration" width="6" multiply_factor_voice="1000" />
|
||||
<field tag="Duration" type="cdrfield" value="duration" width="6" />
|
||||
<field tag="DataVolume" type="filler" width="6" />
|
||||
<field tag="TaxCode" type="constant" value="1" width="1" />
|
||||
<field tag="OperatorCode" type="cdrfield" value="operator" width="2" />
|
||||
|
||||
@@ -55,15 +55,16 @@ type XmlCfgCdrField struct {
|
||||
|
||||
// One CDRC Configuration instance
|
||||
type CgrXmlCdrcCfg struct {
|
||||
Enabled *bool `xml:"enabled"` // Enable/Disable the
|
||||
CdrsAddress *string `xml:"cdrs_address"` // The address where CDRs can be reached
|
||||
CdrFormat *string `xml:"cdr_format"` // The type of CDR to process <csv>
|
||||
FieldSeparator *string `xml:"field_separator"` // The separator to use when reading csvs
|
||||
RunDelay *int64 `xml:"run_delay"` // Delay between runs
|
||||
CdrInDir *string `xml:"cdr_in_dir"` // Folder to process CDRs from
|
||||
CdrOutDir *string `xml:"cdr_out_dir"` // Folder to move processed CDRs to
|
||||
CdrSourceId *string `xml:"cdr_source_id"` // Source identifier for the processed CDRs
|
||||
CdrFields []*XmlCfgCdrField `xml:"fields>field"`
|
||||
Enabled *bool `xml:"enabled"` // Enable/Disable the
|
||||
CdrsAddress *string `xml:"cdrs_address"` // The address where CDRs can be reached
|
||||
CdrFormat *string `xml:"cdr_format"` // The type of CDR to process <csv>
|
||||
FieldSeparator *string `xml:"field_separator"` // The separator to use when reading csvs
|
||||
DataUsageMultiplyFactor *float64 `xml:"data_usage_multiply_factor"` // Conversion factor for data usage
|
||||
RunDelay *int64 `xml:"run_delay"` // Delay between runs
|
||||
CdrInDir *string `xml:"cdr_in_dir"` // Folder to process CDRs from
|
||||
CdrOutDir *string `xml:"cdr_out_dir"` // Folder to move processed CDRs to
|
||||
CdrSourceId *string `xml:"cdr_source_id"` // Source identifier for the processed CDRs
|
||||
CdrFields []*XmlCfgCdrField `xml:"fields>field"`
|
||||
}
|
||||
|
||||
// The CdrExporter configuration instance
|
||||
|
||||
@@ -72,6 +72,7 @@
|
||||
# run_delay = 0 # Sleep interval in seconds between consecutive runs, 0 to use automation via inotify
|
||||
# cdr_format = csv # CDR file format <csv|freeswitch_csv>.
|
||||
# field_separator = , # Separator used in case of csv files. One character only supported and needs to be right after equal sign
|
||||
# data_usage_multiply_factor = 1.0 # Conversion factor for data usage
|
||||
# cdr_in_dir = /var/log/cgrates/cdrc/in # Absolute path towards the directory where the CDRs are stored.
|
||||
# cdr_out_dir = /var/log/cgrates/cdrc/out # Absolute path towards the directory where processed CDRs will be moved.
|
||||
# cdr_source_id = csv # Free form field, tag identifying the source of the CDRs within CGRS database.
|
||||
|
||||
Reference in New Issue
Block a user