mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Cdrc - http enhancements
This commit is contained in:
@@ -21,7 +21,6 @@ package cdrc
|
||||
import (
|
||||
"bufio"
|
||||
"encoding/csv"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
@@ -165,8 +164,7 @@ func (self *Cdrc) recordToStoredCdr(record []string) (*utils.StoredCdr, error) {
|
||||
for _, rsrFld := range httpFieldCfg.Value {
|
||||
httpAddr += rsrFld.ParseValue("")
|
||||
}
|
||||
cdrJson, _ := json.Marshal(storedCdr)
|
||||
if outValByte, err = utils.HttpJsonPost(httpAddr, self.httpSkipTlsCheck, cdrJson); err != nil && httpFieldCfg.Mandatory {
|
||||
if outValByte, err = utils.HttpJsonPost(httpAddr, self.httpSkipTlsCheck, storedCdr); err != nil && httpFieldCfg.Mandatory {
|
||||
return nil, err
|
||||
} else {
|
||||
fieldVal = string(outValByte)
|
||||
@@ -246,12 +244,12 @@ func (self *Cdrc) processFile(filePath string) error {
|
||||
}
|
||||
procRowNr += 1 // Only increase if not end of file
|
||||
if err != nil {
|
||||
engine.Logger.Err(fmt.Sprintf("<Cdrc> Error in csv file: %s", err.Error()))
|
||||
engine.Logger.Err(fmt.Sprintf("<Cdrc> Row %d - csv error: %s", procRowNr, err.Error()))
|
||||
continue // Other csv related errors, ignore
|
||||
}
|
||||
storedCdr, err := self.recordToStoredCdr(record)
|
||||
if err != nil {
|
||||
engine.Logger.Err(fmt.Sprintf("<Cdrc> Error in csv file: %s", err.Error()))
|
||||
engine.Logger.Err(fmt.Sprintf("<Cdrc> Row %d - failed converting to StoredCdr, error: %s", procRowNr, err.Error()))
|
||||
continue
|
||||
}
|
||||
if self.cdrsAddress == utils.INTERNAL {
|
||||
|
||||
@@ -233,7 +233,7 @@ func (self *CGRConfig) checkConfigSanity() error {
|
||||
if cdrcInst.CdrFormat == utils.CSV {
|
||||
for _, cdrFld := range cdrcInst.CdrFields {
|
||||
for _, rsrFld := range cdrFld.Value {
|
||||
if _, errConv := strconv.Atoi(rsrFld.Id); errConv != nil {
|
||||
if _, errConv := strconv.Atoi(rsrFld.Id); errConv != nil && !rsrFld.IsStatic() {
|
||||
return fmt.Errorf("CDR fields must be indices in case of .csv files, have instead: %s", rsrFld.Id)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -278,6 +278,9 @@ func HttpJsonPost(url string, skipTlsVerify bool, content interface{}) ([]byte,
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if resp.StatusCode > 299 {
|
||||
return respBody, fmt.Errorf("Unexpected status code received: %d", resp.StatusCode)
|
||||
}
|
||||
return respBody, nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user