Changed the strip strategy (e.g. "right" to "*right")

This commit is contained in:
adragusin
2020-03-12 18:17:01 +02:00
committed by Dan Christian Bogos
parent 6d9419f773
commit 07877daef0
13 changed files with 111 additions and 98 deletions

View File

@@ -210,12 +210,12 @@ func (ar *AgentRequest) ParseField(
var isString bool
switch cfgFld.Type {
default:
return "", fmt.Errorf("unsupported type: <%s>", cfgFld.Type)
return utils.EmptyString, fmt.Errorf("unsupported type: <%s>", cfgFld.Type)
case utils.META_NONE:
return
case utils.META_FILLER:
out, err = cfgFld.Value.ParseValue(utils.EmptyString)
cfgFld.Padding = "right"
cfgFld.Padding = utils.MetaRight
isString = true
case utils.META_CONSTANT:
out, err = cfgFld.Value.ParseValue(utils.EmptyString)

View File

@@ -75,19 +75,19 @@ func radFieldOutVal(pkt *radigo.Packet, agReq *AgentRequest,
switch cfgFld.Type {
case utils.META_FILLER:
outVal, err = cfgFld.Value.ParseValue(utils.EmptyString)
cfgFld.Padding = "right"
cfgFld.Padding = utils.MetaRight
case utils.META_CONSTANT:
outVal, err = cfgFld.Value.ParseValue(utils.EmptyString)
case utils.META_COMPOSED:
outVal = radComposedFieldValue(pkt, agReq, cfgFld.Value)
default:
return "", fmt.Errorf("unsupported configuration field type: <%s>", cfgFld.Type)
return utils.EmptyString, fmt.Errorf("unsupported configuration field type: <%s>", cfgFld.Type)
}
if err != nil {
return
}
if outVal, err = utils.FmtFieldWidth(cfgFld.Tag, outVal, cfgFld.Width, cfgFld.Strip, cfgFld.Padding, cfgFld.Mandatory); err != nil {
return "", err
return utils.EmptyString, err
}
return
}

View File

@@ -228,26 +228,26 @@
"flags": ["*cdrs"],
"processed_path": "/tmp/fwvErs/out",
"fields": [
{"tag": "FileName", "path": "*cgreq.CdrFileName", "type": "*variable", "value": "~*hdr.95-135", "padding":"right"},
{"tag": "FileSeqNr", "path": "*cgreq.FileSeqNr", "type": "*variable", "value": "~*hdr.135-141", "padding":"zeroleft"},
{"tag": "AccId1", "path": "*cgreq.AccId1", "type": "*variable", "value": "~*hdr.135-141", "padding":"zeroleft"},
{"tag": "FileName", "path": "*cgreq.CdrFileName", "type": "*variable", "value": "~*hdr.95-135", "padding":"*right"},
{"tag": "FileSeqNr", "path": "*cgreq.FileSeqNr", "type": "*variable", "value": "~*hdr.135-141", "padding":"*zeroleft"},
{"tag": "AccId1", "path": "*cgreq.AccId1", "type": "*variable", "value": "~*hdr.135-141", "padding":"*zeroleft"},
{"tag": "Tor", "path": "*cgreq.ToR", "type": "*constant", "value": "*voice", "mandatory": true},
{"tag": "RequestType", "path": "*cgreq.RequestType", "type": "*constant", "value": "rated", "mandatory": true},
{"tag": "OriginID", "path": "*cgreq.OriginID", "type": "*variable", "value": "~*req.0-10", "padding":"right", "mandatory": true},
{"tag": "OriginID", "path": "*cgreq.OriginID", "type": "*variable", "value": "~*req.0-10", "padding":"*right", "mandatory": true},
{"tag": "OriginHost", "path": "*cgreq.OriginHost", "type": "*constant", "value": "0.0.0.0", "mandatory": true},
{"tag": "Tenant", "path": "*cgreq.Tenant", "type": "*constant", "value": "cgrates.org", "mandatory": true},
{"tag": "Category", "path": "*cgreq.Category", "type": "*constant", "value": "call", "mandatory": true},
{"tag": "Account", "path": "*cgreq.Account", "type": "*variable", "value": "~*req.30-49", "padding":"right", "mandatory": true},
{"tag": "Subject", "path": "*cgreq.Subject", "type": "*variable", "value": "~*req.30-49", "padding":"right", "mandatory": true},
{"tag": "Destination", "path": "*cgreq.Destination", "type": "*variable", "value": "~*req.52-80", "padding":"right", "mandatory": true},
{"tag": "Account", "path": "*cgreq.Account", "type": "*variable", "value": "~*req.30-49", "padding":"*right", "mandatory": true},
{"tag": "Subject", "path": "*cgreq.Subject", "type": "*variable", "value": "~*req.30-49", "padding":"*right", "mandatory": true},
{"tag": "Destination", "path": "*cgreq.Destination", "type": "*variable", "value": "~*req.52-80", "padding":"*right", "mandatory": true},
{"tag": "SetupTime", "path": "*cgreq.SetupTime", "type": "*variable", "value": "~*req.14-30:s/(\\d{4})(\\d{2})(\\d{2})(\\d{2})(\\d{2})(\\d{2})(\\d{2})/${1}-${2}-${3} ${4}:${5}:${6}/", "mandatory": true},
{"tag": "AnswerTime", "path": "*cgreq.AnswerTime", "type": "*variable", "value": "~*req.14-30:s/(\\d{4})(\\d{2})(\\d{2})(\\d{2})(\\d{2})(\\d{2})(\\d{2})/${1}-${2}-${3} ${4}:${5}:${6}/", "mandatory": true},
{"tag": "Usage", "path": "*cgreq.Usage", "type": "*variable", "value": "~*req.127-135:s/(\\d{2})(\\d{2})(\\d{2})(\\d{2})/${1}h${2}m${3}s/", "mandatory": true},
{"tag": "DisconnectCause", "path": "*cgreq.DisconnectCause", "type": "*variable", "value": "~*req.138-139", "mandatory": true},
{"tag": "RetailAmount", "path": "*cgreq.RetailAmount", "type": "*variable", "value": "~*req.103-111", "padding":"zeroleft"},
{"tag": "WholesaleAmount", "path": "*cgreq.RetailAmount", "type": "*variable", "value": "~*req.115-123", "padding":"zeroleft"},
{"tag": "AccId1", "path": "*cgreq.AccId1", "type": "*variable", "value": "~*req.3-6", "padding":"zeroleft", "mandatory": true},
{"tag": "AccId2", "path": "*cgreq.AccId2", "type": "*variable", "value": "~*req.14-30", "padding":"right", "mandatory": true},
{"tag": "RetailAmount", "path": "*cgreq.RetailAmount", "type": "*variable", "value": "~*req.103-111", "padding":"*zeroleft"},
{"tag": "WholesaleAmount", "path": "*cgreq.RetailAmount", "type": "*variable", "value": "~*req.115-123", "padding":"*zeroleft"},
{"tag": "AccId1", "path": "*cgreq.AccId1", "type": "*variable", "value": "~*req.3-6", "padding":"*zeroleft", "mandatory": true},
{"tag": "AccId2", "path": "*cgreq.AccId2", "type": "*variable", "value": "~*req.14-30", "padding":"*right", "mandatory": true},
{"tag": "NrOfCdrs", "type": "*variable", "path":"*cgreq.NrOfCdrs", "value": "~*trl.142-150"},
{"tag": "TotalDuration", "type": "*variable", "path":"*cgreq.TotalDuration", "value": "~*trl.150-162"}
],

View File

@@ -229,26 +229,26 @@
"flags": ["*cdrs"],
"processed_path": "/tmp/fwvErs/out",
"fields": [
{"tag": "FileName", "path": "*cgreq.CdrFileName", "type": "*variable", "value": "~*hdr.95-135", "padding":"right"},
{"tag": "FileSeqNr", "path": "*cgreq.FileSeqNr", "type": "*variable", "value": "~*hdr.135-141", "padding":"zeroleft"},
{"tag": "AccId1", "path": "*cgreq.AccId1", "type": "*variable", "value": "~*hdr.135-141", "padding":"zeroleft"},
{"tag": "FileName", "path": "*cgreq.CdrFileName", "type": "*variable", "value": "~*hdr.95-135", "padding":"*right"},
{"tag": "FileSeqNr", "path": "*cgreq.FileSeqNr", "type": "*variable", "value": "~*hdr.135-141", "padding":"*zeroleft"},
{"tag": "AccId1", "path": "*cgreq.AccId1", "type": "*variable", "value": "~*hdr.135-141", "padding":"*zeroleft"},
{"tag": "Tor", "path": "*cgreq.ToR", "type": "*constant", "value": "*voice", "mandatory": true},
{"tag": "RequestType", "path": "*cgreq.RequestType", "type": "*constant", "value": "rated", "mandatory": true},
{"tag": "OriginID", "path": "*cgreq.OriginID", "type": "*variable", "value": "~*req.0-10", "padding":"right", "mandatory": true},
{"tag": "OriginID", "path": "*cgreq.OriginID", "type": "*variable", "value": "~*req.0-10", "padding":"*right", "mandatory": true},
{"tag": "OriginHost", "path": "*cgreq.OriginHost", "type": "*constant", "value": "0.0.0.0", "mandatory": true},
{"tag": "Tenant", "path": "*cgreq.Tenant", "type": "*constant", "value": "cgrates.org", "mandatory": true},
{"tag": "Category", "path": "*cgreq.Category", "type": "*constant", "value": "call", "mandatory": true},
{"tag": "Account", "path": "*cgreq.Account", "type": "*variable", "value": "~*req.30-49", "padding":"right", "mandatory": true},
{"tag": "Subject", "path": "*cgreq.Subject", "type": "*variable", "value": "~*req.30-49", "padding":"right", "mandatory": true},
{"tag": "Destination", "path": "*cgreq.Destination", "type": "*variable", "value": "~*req.52-80", "padding":"right", "mandatory": true},
{"tag": "Account", "path": "*cgreq.Account", "type": "*variable", "value": "~*req.30-49", "padding":"*right", "mandatory": true},
{"tag": "Subject", "path": "*cgreq.Subject", "type": "*variable", "value": "~*req.30-49", "padding":"*right", "mandatory": true},
{"tag": "Destination", "path": "*cgreq.Destination", "type": "*variable", "value": "~*req.52-80", "padding":"*right", "mandatory": true},
{"tag": "SetupTime", "path": "*cgreq.SetupTime", "type": "*variable", "value": "~*req.14-30:s/(\\d{4})(\\d{2})(\\d{2})(\\d{2})(\\d{2})(\\d{2})(\\d{2})/${1}-${2}-${3} ${4}:${5}:${6}/", "mandatory": true},
{"tag": "AnswerTime", "path": "*cgreq.AnswerTime", "type": "*variable", "value": "~*req.14-30:s/(\\d{4})(\\d{2})(\\d{2})(\\d{2})(\\d{2})(\\d{2})(\\d{2})/${1}-${2}-${3} ${4}:${5}:${6}/", "mandatory": true},
{"tag": "Usage", "path": "*cgreq.Usage", "type": "*variable", "value": "~*req.127-135:s/(\\d{2})(\\d{2})(\\d{2})(\\d{2})/${1}h${2}m${3}s/", "mandatory": true},
{"tag": "DisconnectCause", "path": "*cgreq.DisconnectCause", "type": "*variable", "value": "~*req.138-139", "mandatory": true},
{"tag": "RetailAmount", "path": "*cgreq.RetailAmount", "type": "*variable", "value": "~*req.103-111", "padding":"zeroleft"},
{"tag": "WholesaleAmount", "path": "*cgreq.RetailAmount", "type": "*variable", "value": "~*req.115-123", "padding":"zeroleft"},
{"tag": "AccId1", "path": "*cgreq.AccId1", "type": "*variable", "value": "~*req.3-6", "padding":"zeroleft", "mandatory": true},
{"tag": "AccId2", "path": "*cgreq.AccId2", "type": "*variable", "value": "~*req.14-30", "padding":"right", "mandatory": true},
{"tag": "RetailAmount", "path": "*cgreq.RetailAmount", "type": "*variable", "value": "~*req.103-111", "padding":"*zeroleft"},
{"tag": "WholesaleAmount", "path": "*cgreq.RetailAmount", "type": "*variable", "value": "~*req.115-123", "padding":"*zeroleft"},
{"tag": "AccId1", "path": "*cgreq.AccId1", "type": "*variable", "value": "~*req.3-6", "padding":"*zeroleft", "mandatory": true},
{"tag": "AccId2", "path": "*cgreq.AccId2", "type": "*variable", "value": "~*req.14-30", "padding":"*right", "mandatory": true},
{"tag": "NrOfCdrs", "type": "*variable", "path":"*cgreq.NrOfCdrs", "value": "~*trl.142-150"},
{"tag": "TotalDuration", "type": "*variable", "path":"*cgreq.TotalDuration", "value": "~*trl.150-162"}
],

View File

@@ -226,26 +226,26 @@
"flags": ["*cdrs"],
"processed_path": "/tmp/fwvErs/out",
"fields": [
{"tag": "FileName", "path": "*cgreq.CdrFileName", "type": "*variable", "value": "~*hdr.95-135", "padding":"right"},
{"tag": "FileSeqNr", "path": "*cgreq.FileSeqNr", "type": "*variable", "value": "~*hdr.135-141", "padding":"zeroleft"},
{"tag": "AccId1", "path": "*cgreq.AccId1", "type": "*variable", "value": "~*hdr.135-141", "padding":"zeroleft"},
{"tag": "FileName", "path": "*cgreq.CdrFileName", "type": "*variable", "value": "~*hdr.95-135", "padding":"*right"},
{"tag": "FileSeqNr", "path": "*cgreq.FileSeqNr", "type": "*variable", "value": "~*hdr.135-141", "padding":"*zeroleft"},
{"tag": "AccId1", "path": "*cgreq.AccId1", "type": "*variable", "value": "~*hdr.135-141", "padding":"*zeroleft"},
{"tag": "Tor", "path": "*cgreq.ToR", "type": "*constant", "value": "*voice", "mandatory": true},
{"tag": "RequestType", "path": "*cgreq.RequestType", "type": "*constant", "value": "rated", "mandatory": true},
{"tag": "OriginID", "path": "*cgreq.OriginID", "type": "*variable", "value": "~*req.0-10", "padding":"right", "mandatory": true},
{"tag": "OriginID", "path": "*cgreq.OriginID", "type": "*variable", "value": "~*req.0-10", "padding":"*right", "mandatory": true},
{"tag": "OriginHost", "path": "*cgreq.OriginHost", "type": "*constant", "value": "0.0.0.0", "mandatory": true},
{"tag": "Tenant", "path": "*cgreq.Tenant", "type": "*constant", "value": "cgrates.org", "mandatory": true},
{"tag": "Category", "path": "*cgreq.Category", "type": "*constant", "value": "call", "mandatory": true},
{"tag": "Account", "path": "*cgreq.Account", "type": "*variable", "value": "~*req.30-49", "padding":"right", "mandatory": true},
{"tag": "Subject", "path": "*cgreq.Subject", "type": "*variable", "value": "~*req.30-49", "padding":"right", "mandatory": true},
{"tag": "Destination", "path": "*cgreq.Destination", "type": "*variable", "value": "~*req.52-80", "padding":"right", "mandatory": true},
{"tag": "Account", "path": "*cgreq.Account", "type": "*variable", "value": "~*req.30-49", "padding":"*right", "mandatory": true},
{"tag": "Subject", "path": "*cgreq.Subject", "type": "*variable", "value": "~*req.30-49", "padding":"*right", "mandatory": true},
{"tag": "Destination", "path": "*cgreq.Destination", "type": "*variable", "value": "~*req.52-80", "padding":"*right", "mandatory": true},
{"tag": "SetupTime", "path": "*cgreq.SetupTime", "type": "*variable", "value": "~*req.14-30:s/(\\d{4})(\\d{2})(\\d{2})(\\d{2})(\\d{2})(\\d{2})(\\d{2})/${1}-${2}-${3} ${4}:${5}:${6}/", "mandatory": true},
{"tag": "AnswerTime", "path": "*cgreq.AnswerTime", "type": "*variable", "value": "~*req.14-30:s/(\\d{4})(\\d{2})(\\d{2})(\\d{2})(\\d{2})(\\d{2})(\\d{2})/${1}-${2}-${3} ${4}:${5}:${6}/", "mandatory": true},
{"tag": "Usage", "path": "*cgreq.Usage", "type": "*variable", "value": "~*req.127-135:s/(\\d{2})(\\d{2})(\\d{2})(\\d{2})/${1}h${2}m${3}s/", "mandatory": true},
{"tag": "DisconnectCause", "path": "*cgreq.DisconnectCause", "type": "*variable", "value": "~*req.138-139", "mandatory": true},
{"tag": "RetailAmount", "path": "*cgreq.RetailAmount", "type": "*variable", "value": "~*req.103-111", "padding":"zeroleft"},
{"tag": "WholesaleAmount", "path": "*cgreq.RetailAmount", "type": "*variable", "value": "~*req.115-123", "padding":"zeroleft"},
{"tag": "AccId1", "path": "*cgreq.AccId1", "type": "*variable", "value": "~*req.3-6", "padding":"zeroleft", "mandatory": true},
{"tag": "AccId2", "path": "*cgreq.AccId2", "type": "*variable", "value": "~*req.14-30", "padding":"right", "mandatory": true},
{"tag": "RetailAmount", "path": "*cgreq.RetailAmount", "type": "*variable", "value": "~*req.103-111", "padding":"*zeroleft"},
{"tag": "WholesaleAmount", "path": "*cgreq.RetailAmount", "type": "*variable", "value": "~*req.115-123", "padding":"*zeroleft"},
{"tag": "AccId1", "path": "*cgreq.AccId1", "type": "*variable", "value": "~*req.3-6", "padding":"*zeroleft", "mandatory": true},
{"tag": "AccId2", "path": "*cgreq.AccId2", "type": "*variable", "value": "~*req.14-30", "padding":"*right", "mandatory": true},
{"tag": "NrOfCdrs", "type": "*variable", "path":"*cgreq.NrOfCdrs", "value": "~*trl.142-150"},
{"tag": "TotalDuration", "type": "*variable", "path":"*cgreq.TotalDuration", "value": "~*trl.150-162"}
],

View File

@@ -223,26 +223,26 @@
"flags": ["*cdrs"],
"processed_path": "/tmp/fwvErs/out",
"fields": [
{"tag": "FileName", "path": "*cgreq.CdrFileName", "type": "*variable", "value": "~*hdr.95-135", "padding":"right"},
{"tag": "FileSeqNr", "path": "*cgreq.FileSeqNr", "type": "*variable", "value": "~*hdr.135-141", "padding":"zeroleft"},
{"tag": "AccId1", "path": "*cgreq.AccId1", "type": "*variable", "value": "~*hdr.135-141", "padding":"zeroleft"},
{"tag": "FileName", "path": "*cgreq.CdrFileName", "type": "*variable", "value": "~*hdr.95-135", "padding":"*right"},
{"tag": "FileSeqNr", "path": "*cgreq.FileSeqNr", "type": "*variable", "value": "~*hdr.135-141", "padding":"*zeroleft"},
{"tag": "AccId1", "path": "*cgreq.AccId1", "type": "*variable", "value": "~*hdr.135-141", "padding":"*zeroleft"},
{"tag": "Tor", "path": "*cgreq.ToR", "type": "*constant", "value": "*voice", "mandatory": true},
{"tag": "RequestType", "path": "*cgreq.RequestType", "type": "*constant", "value": "rated", "mandatory": true},
{"tag": "OriginID", "path": "*cgreq.OriginID", "type": "*variable", "value": "~*req.0-10", "padding":"right", "mandatory": true},
{"tag": "OriginID", "path": "*cgreq.OriginID", "type": "*variable", "value": "~*req.0-10", "padding":"*right", "mandatory": true},
{"tag": "OriginHost", "path": "*cgreq.OriginHost", "type": "*constant", "value": "0.0.0.0", "mandatory": true},
{"tag": "Tenant", "path": "*cgreq.Tenant", "type": "*constant", "value": "cgrates.org", "mandatory": true},
{"tag": "Category", "path": "*cgreq.Category", "type": "*constant", "value": "call", "mandatory": true},
{"tag": "Account", "path": "*cgreq.Account", "type": "*variable", "value": "~*req.30-49", "padding":"right", "mandatory": true},
{"tag": "Subject", "path": "*cgreq.Subject", "type": "*variable", "value": "~*req.30-49", "padding":"right", "mandatory": true},
{"tag": "Destination", "path": "*cgreq.Destination", "type": "*variable", "value": "~*req.52-80", "padding":"right", "mandatory": true},
{"tag": "Account", "path": "*cgreq.Account", "type": "*variable", "value": "~*req.30-49", "padding":"*right", "mandatory": true},
{"tag": "Subject", "path": "*cgreq.Subject", "type": "*variable", "value": "~*req.30-49", "padding":"*right", "mandatory": true},
{"tag": "Destination", "path": "*cgreq.Destination", "type": "*variable", "value": "~*req.52-80", "padding":"*right", "mandatory": true},
{"tag": "SetupTime", "path": "*cgreq.SetupTime", "type": "*variable", "value": "~*req.14-30:s/(\\d{4})(\\d{2})(\\d{2})(\\d{2})(\\d{2})(\\d{2})(\\d{2})/${1}-${2}-${3} ${4}:${5}:${6}/", "mandatory": true},
{"tag": "AnswerTime", "path": "*cgreq.AnswerTime", "type": "*variable", "value": "~*req.14-30:s/(\\d{4})(\\d{2})(\\d{2})(\\d{2})(\\d{2})(\\d{2})(\\d{2})/${1}-${2}-${3} ${4}:${5}:${6}/", "mandatory": true},
{"tag": "Usage", "path": "*cgreq.Usage", "type": "*variable", "value": "~*req.127-135:s/(\\d{2})(\\d{2})(\\d{2})(\\d{2})/${1}h${2}m${3}s/", "mandatory": true},
{"tag": "DisconnectCause", "path": "*cgreq.DisconnectCause", "type": "*variable", "value": "~*req.138-139", "mandatory": true},
{"tag": "RetailAmount", "path": "*cgreq.RetailAmount", "type": "*variable", "value": "~*req.103-111", "padding":"zeroleft"},
{"tag": "WholesaleAmount", "path": "*cgreq.RetailAmount", "type": "*variable", "value": "~*req.115-123", "padding":"zeroleft"},
{"tag": "AccId1", "path": "*cgreq.AccId1", "type": "*variable", "value": "~*req.3-6", "padding":"zeroleft", "mandatory": true},
{"tag": "AccId2", "path": "*cgreq.AccId2", "type": "*variable", "value": "~*req.14-30", "padding":"right", "mandatory": true},
{"tag": "RetailAmount", "path": "*cgreq.RetailAmount", "type": "*variable", "value": "~*req.103-111", "padding":"*zeroleft"},
{"tag": "WholesaleAmount", "path": "*cgreq.RetailAmount", "type": "*variable", "value": "~*req.115-123", "padding":"*zeroleft"},
{"tag": "AccId1", "path": "*cgreq.AccId1", "type": "*variable", "value": "~*req.3-6", "padding":"*zeroleft", "mandatory": true},
{"tag": "AccId2", "path": "*cgreq.AccId2", "type": "*variable", "value": "~*req.14-30", "padding":"*right", "mandatory": true},
{"tag": "NrOfCdrs", "type": "*variable", "path":"*cgreq.NrOfCdrs", "value": "~*trl.142-150"},
{"tag": "TotalDuration", "type": "*variable", "path":"*cgreq.TotalDuration", "value": "~*trl.150-162"}
],

View File

@@ -352,7 +352,7 @@ func (cdr *CDR) formatField(cfgFld *config.FCTemplate, httpSkipTLSCheck bool,
switch cfgFld.Type {
case utils.META_FILLER:
outVal, err = cfgFld.Value.ParseValue(utils.EmptyString)
cfgFld.Padding = "right"
cfgFld.Padding = utils.MetaRight
case utils.META_CONSTANT:
outVal, err = cfgFld.Value.ParseValue(utils.EmptyString)
case utils.MetaDateTime: // Convert the requested field value into datetime with layout

View File

@@ -159,7 +159,7 @@ func (cdre *CDRExporter) composeHeader() (err error) {
return err
}
outVal = out
cfgFld.Padding = "right"
cfgFld.Padding = utils.MetaRight
case utils.META_CONSTANT:
out, err := cfgFld.Value.ParseValue(utils.EmptyString)
if err != nil {
@@ -208,7 +208,7 @@ func (cdre *CDRExporter) composeTrailer() (err error) {
return err
}
outVal = out
cfgFld.Padding = "right"
cfgFld.Padding = utils.MetaRight
case utils.META_CONSTANT:
out, err := cfgFld.Value.ParseValue(utils.EmptyString)
if err != nil {

View File

@@ -51,8 +51,8 @@ var contentJsnCfgFlds = []*config.FcTemplateJsonCfg{
Type: utils.StringPointer(utils.META_HANDLER),
Value: utils.StringPointer(metaExportID),
Width: utils.IntPointer(5),
Strip: utils.StringPointer("right"),
Padding: utils.StringPointer("zeroleft")},
Strip: utils.StringPointer(utils.MetaRight),
Padding: utils.StringPointer(utils.MetaZeroLeft)},
{
Tag: utils.StringPointer("LastCdr"),
Path: utils.StringPointer("*hdr.LastCdr"),
@@ -90,32 +90,32 @@ var contentJsnCfgFlds = []*config.FcTemplateJsonCfg{
Type: utils.StringPointer(utils.META_COMPOSED),
Value: utils.StringPointer("~" + utils.Account),
Width: utils.IntPointer(12),
Strip: utils.StringPointer("left"),
Padding: utils.StringPointer("right")},
Strip: utils.StringPointer(utils.MetaLeft),
Padding: utils.StringPointer(utils.MetaRight)},
{
Tag: utils.StringPointer("Subject"),
Path: utils.StringPointer("*exp.Subject"),
Type: utils.StringPointer(utils.META_COMPOSED),
Value: utils.StringPointer("~" + utils.Subject),
Width: utils.IntPointer(5),
Strip: utils.StringPointer("right"),
Padding: utils.StringPointer("right")},
Strip: utils.StringPointer(utils.MetaRight),
Padding: utils.StringPointer(utils.MetaRight)},
{
Tag: utils.StringPointer("CLI"),
Path: utils.StringPointer("*exp.CLI"),
Type: utils.StringPointer(utils.META_COMPOSED),
Width: utils.IntPointer(15),
Value: utils.StringPointer("cli"),
Strip: utils.StringPointer("xright"),
Padding: utils.StringPointer("right")},
Strip: utils.StringPointer(utils.MetaXRight),
Padding: utils.StringPointer(utils.MetaRight)},
{
Tag: utils.StringPointer("Destination"),
Path: utils.StringPointer("*exp.Destination"),
Type: utils.StringPointer(utils.META_COMPOSED),
Value: utils.StringPointer("~" + utils.Destination),
Width: utils.IntPointer(24),
Strip: utils.StringPointer("xright"),
Padding: utils.StringPointer("right")},
Strip: utils.StringPointer(utils.MetaXRight),
Padding: utils.StringPointer(utils.MetaRight)},
{
Tag: utils.StringPointer("ToR"),
Path: utils.StringPointer("*exp.ToR"),
@@ -127,7 +127,7 @@ var contentJsnCfgFlds = []*config.FcTemplateJsonCfg{
Path: utils.StringPointer("*exp.SubtypeTOR"),
Type: utils.StringPointer(utils.META_CONSTANT),
Value: utils.StringPointer("11"),
Padding: utils.StringPointer("right"),
Padding: utils.StringPointer(utils.MetaRight),
Width: utils.IntPointer(4)},
{
Tag: utils.StringPointer("SetupTime"),
@@ -135,8 +135,8 @@ var contentJsnCfgFlds = []*config.FcTemplateJsonCfg{
Type: utils.StringPointer(utils.META_COMPOSED),
Value: utils.StringPointer("~" + utils.SetupTime),
Width: utils.IntPointer(12),
Strip: utils.StringPointer("right"),
Padding: utils.StringPointer("right"),
Strip: utils.StringPointer(utils.MetaRight),
Padding: utils.StringPointer(utils.MetaRight),
Layout: utils.StringPointer("020106150400")},
{
Tag: utils.StringPointer("Duration"),
@@ -144,8 +144,8 @@ var contentJsnCfgFlds = []*config.FcTemplateJsonCfg{
Type: utils.StringPointer(utils.META_COMPOSED),
Value: utils.StringPointer("~" + utils.Usage),
Width: utils.IntPointer(6),
Strip: utils.StringPointer("right"),
Padding: utils.StringPointer("right"),
Strip: utils.StringPointer(utils.MetaRight),
Padding: utils.StringPointer(utils.MetaRight),
Layout: utils.StringPointer(utils.SECONDS)},
{
Tag: utils.StringPointer("DataVolume"),
@@ -164,16 +164,16 @@ var contentJsnCfgFlds = []*config.FcTemplateJsonCfg{
Type: utils.StringPointer(utils.META_COMPOSED),
Value: utils.StringPointer("opercode"),
Width: utils.IntPointer(2),
Strip: utils.StringPointer("right"),
Padding: utils.StringPointer("right")},
Strip: utils.StringPointer(utils.MetaRight),
Padding: utils.StringPointer(utils.MetaRight)},
{
Tag: utils.StringPointer("ProductId"),
Path: utils.StringPointer("*exp.ProductId"),
Type: utils.StringPointer(utils.META_COMPOSED),
Value: utils.StringPointer("~productid"),
Width: utils.IntPointer(5),
Strip: utils.StringPointer("right"),
Padding: utils.StringPointer("right")},
Strip: utils.StringPointer(utils.MetaRight),
Padding: utils.StringPointer(utils.MetaRight)},
{
Tag: utils.StringPointer("NetworkId"),
Path: utils.StringPointer("*exp.NetworkId"),
@@ -186,7 +186,7 @@ var contentJsnCfgFlds = []*config.FcTemplateJsonCfg{
Type: utils.StringPointer(utils.META_COMPOSED),
Value: utils.StringPointer("~" + utils.OriginID),
Width: utils.IntPointer(16),
Padding: utils.StringPointer("right")},
Padding: utils.StringPointer(utils.MetaRight)},
{
Tag: utils.StringPointer("Filler"),
Path: utils.StringPointer("*exp.Filler"),
@@ -203,15 +203,15 @@ var contentJsnCfgFlds = []*config.FcTemplateJsonCfg{
Type: utils.StringPointer(utils.META_COMPOSED),
Value: utils.StringPointer("~operator;~product"),
Width: utils.IntPointer(5),
Strip: utils.StringPointer("right"),
Padding: utils.StringPointer("right")},
Strip: utils.StringPointer(utils.MetaRight),
Padding: utils.StringPointer(utils.MetaRight)},
{
Tag: utils.StringPointer("Cost"),
Path: utils.StringPointer("*exp.Cost"),
Type: utils.StringPointer(utils.META_COMPOSED),
Width: utils.IntPointer(9),
Value: utils.StringPointer("~" + utils.COST),
Padding: utils.StringPointer("zeroleft"),
Padding: utils.StringPointer(utils.MetaZeroLeft),
Rounding_decimals: utils.IntPointer(5)},
{
Tag: utils.StringPointer("DestinationPrivacy"),
@@ -241,22 +241,22 @@ var contentJsnCfgFlds = []*config.FcTemplateJsonCfg{
Type: utils.StringPointer(utils.META_HANDLER),
Value: utils.StringPointer(metaExportID),
Width: utils.IntPointer(5),
Strip: utils.StringPointer("right"),
Padding: utils.StringPointer("zeroleft")},
Strip: utils.StringPointer(utils.MetaRight),
Padding: utils.StringPointer(utils.MetaZeroLeft)},
{
Tag: utils.StringPointer("NumberOfRecords"),
Path: utils.StringPointer("*trl.NumberOfRecords"),
Type: utils.StringPointer(utils.META_HANDLER),
Value: utils.StringPointer(metaNrCDRs),
Width: utils.IntPointer(6),
Padding: utils.StringPointer("zeroleft")},
Padding: utils.StringPointer(utils.MetaZeroLeft)},
{
Tag: utils.StringPointer("CdrsDuration"),
Path: utils.StringPointer("*trl.CdrsDuration"),
Type: utils.StringPointer(utils.META_HANDLER),
Value: utils.StringPointer(metaDurCDRs),
Width: utils.IntPointer(8),
Padding: utils.StringPointer("zeroleft"),
Padding: utils.StringPointer(utils.MetaZeroLeft),
Layout: utils.StringPointer(utils.SECONDS)},
{
Tag: utils.StringPointer("FirstCdrTime"),

View File

@@ -7,18 +7,19 @@ cgrates (0.10.1~dev) UNRELEASED; urgency=medium
ToJSON for request String method
* [DiameterAgent] Updated 3gp_vendor dictionary
* [Templates] Added new dataconvertor: *ip2hex
* [AgentRequest] Add support for *group type and correctly overwrite
* [AgentRequest] Added support for *group type and correctly overwrite
the values in case of *variable
* [EventReader] Correctly populate ConcurrentRequest from config in
EventReader
* [SupplierS] In case of missing usage from Event use 1 minute as
default value
* [DataDB] Mongo support different marshaler than msgpack
* [General] Fix rpc_conns handling id with two connections and one of
* [ConnManager] Fixed rpc_conns handling id with two connections and one of
it *internal
* [Replicator] Add Limit and StaticTTL otions for Items from
* [Replicator] Added Limit and StaticTTL otions for Items from
DataDB/StorDB
* Migrator discover tenant from key instead of taking it from config
* [Migrator] Auto discover tenant from key instead of taking it from config
* [Templates] Fixed missing "*" for strip and padding strategy
-- Alexandru Tripon <alexandru.tripon@itsyscom.com> Wed, 19 Feb 2020 15:22:59 +0200

View File

@@ -1556,6 +1556,18 @@ var (
PostgressSSLModeVerifyFull = "verify-full"
)
// Strip/Padding strategy
var (
// common
MetaRight = "*right"
MetaLeft = "*left"
// only for strip
MetaXRight = "*xright"
MetaXLeft = "*xleft"
// only for padding
MetaZeroLeft = "*zeroleft"
)
func buildCacheInstRevPrefixes() {
CachePrefixToInstance = make(map[string]string)
for k, v := range CacheInstanceToPrefix {

View File

@@ -499,14 +499,14 @@ func FmtFieldWidth(fieldID, source string, width int, strip, padding string, man
if len(strip) == 0 {
return "", fmt.Errorf("Source %s is bigger than the width %d, no strip defied, fieldID: <%s>", source, width, fieldID)
}
if strip == "right" {
if strip == MetaRight {
return source[:width], nil
} else if strip == "xright" {
} else if strip == MetaXRight {
return source[:width-1] + "x", nil // Suffix with x to mark prefix
} else if strip == "left" {
} else if strip == MetaLeft {
diffIndx := len(source) - width
return source[diffIndx:], nil
} else if strip == "xleft" { // Prefix one x to mark stripping
} else if strip == MetaXLeft { // Prefix one x to mark stripping
diffIndx := len(source) - width
return "x" + source[diffIndx+1:], nil
}
@@ -516,11 +516,11 @@ func FmtFieldWidth(fieldID, source string, width int, strip, padding string, man
}
var paddingFmt string
switch padding {
case "right":
case MetaRight:
paddingFmt = fmt.Sprintf("%%-%ds", width)
case "left":
case MetaLeft:
paddingFmt = fmt.Sprintf("%%%ds", width)
case "zeroleft":
case MetaZeroLeft:
paddingFmt = fmt.Sprintf("%%0%ds", width)
}
if len(paddingFmt) != 0 {

View File

@@ -666,56 +666,56 @@ func TestFmtFieldWidth(t *testing.T) {
t.Errorf("Expected \"test\" received: \"%s\"", result)
}
//RPadding
if result, err := FmtFieldWidth("", "test", 8, "", "right", false); err != nil {
if result, err := FmtFieldWidth("", "test", 8, "", "*right", false); err != nil {
t.Error(err)
} else if result != "test " {
t.Errorf("Expected <\"test \"> \" received: \"%s\"", result)
}
//PaddingFiller
expected := " "
if result, err := FmtFieldWidth("", "", 8, "", "right", false); err != nil {
if result, err := FmtFieldWidth("", "", 8, "", "*right", false); err != nil {
t.Error(err)
} else if result != expected {
t.Errorf("Expected \"%s \" received: \"%s\"", expected, result)
}
//LPadding
expected = " test"
if result, err := FmtFieldWidth("", "test", 8, "", "left", false); err != nil {
if result, err := FmtFieldWidth("", "test", 8, "", "*left", false); err != nil {
t.Error(err)
} else if result != expected {
t.Errorf("Expected \"%s \" received: \"%s\"", expected, result)
}
//ZeroLPadding
expected = "0000test"
if result, err := FmtFieldWidth("", "test", 8, "", "zeroleft", false); err != nil {
if result, err := FmtFieldWidth("", "test", 8, "", "*zeroleft", false); err != nil {
t.Error(err)
} else if result != expected {
t.Errorf("Expected \"%s \" received: \"%s\"", expected, result)
}
//RStrip
expected = "te"
if result, err := FmtFieldWidth("", "test", 2, "right", "", false); err != nil {
if result, err := FmtFieldWidth("", "test", 2, "*right", "", false); err != nil {
t.Error(err)
} else if result != expected {
t.Errorf("Expected \"%s \" received: \"%s\"", expected, result)
}
//XRStrip
expected = "tex"
if result, err := FmtFieldWidth("", "test", 3, "xright", "", false); err != nil {
if result, err := FmtFieldWidth("", "test", 3, "*xright", "", false); err != nil {
t.Error(err)
} else if result != expected {
t.Errorf("Expected \"%s \" received: \"%s\"", expected, result)
}
//LStrip
expected = "st"
if result, err := FmtFieldWidth("", "test", 2, "left", "", false); err != nil {
if result, err := FmtFieldWidth("", "test", 2, "*left", "", false); err != nil {
t.Error(err)
} else if result != expected {
t.Errorf("Expected \"%s \" received: \"%s\"", expected, result)
}
//XLStrip
expected = "xst"
if result, err := FmtFieldWidth("", "test", 3, "xleft", "", false); err != nil {
if result, err := FmtFieldWidth("", "test", 3, "*xleft", "", false); err != nil {
t.Error(err)
} else if result != expected {
t.Errorf("Expected \"%s \" received: \"%s\"", expected, result)