mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-21 15:18:44 +05:00
HttpPoster implementation in CDR replication and actions with call_url, new configuration parameters added: http_failed_dir, replication attempts, fixes #201, Rated bug fix in CDRC, Cost imported via CDRC in templates now
This commit is contained in:
@@ -23,6 +23,7 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/smtp"
|
||||
"path"
|
||||
"reflect"
|
||||
"sort"
|
||||
"strconv"
|
||||
@@ -427,7 +428,7 @@ func genericReset(ub *Account) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func callUrl(ub *Account, sq *StatsQueueTriggered, a *Action, acs Actions) (err error) {
|
||||
func callUrl(ub *Account, sq *StatsQueueTriggered, a *Action, acs Actions) error {
|
||||
var o interface{}
|
||||
if ub != nil {
|
||||
o = ub
|
||||
@@ -435,12 +436,9 @@ func callUrl(ub *Account, sq *StatsQueueTriggered, a *Action, acs Actions) (err
|
||||
if sq != nil {
|
||||
o = sq
|
||||
}
|
||||
//jsn, err := json.Marshal(o)
|
||||
//if err != nil {
|
||||
// return err
|
||||
//}
|
||||
cfg := config.CgrConfig()
|
||||
_, err = utils.HttpJsonPost(a.ExtraParameters, cfg.HttpSkipTlsVerify, o)
|
||||
fallbackPath := path.Join(cfg.HttpFailedDir, fmt.Sprintf("act_%s_%s_%s.json", a.ActionType, a.ExtraParameters, utils.GenUUID()))
|
||||
_, err := utils.HttpPoster(a.ExtraParameters, cfg.HttpSkipTlsVerify, o, utils.CONTENT_JSON, 1, fallbackPath)
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -453,23 +451,9 @@ func callUrlAsync(ub *Account, sq *StatsQueueTriggered, a *Action, acs Actions)
|
||||
if sq != nil {
|
||||
o = sq
|
||||
}
|
||||
//jsn, err := json.Marshal(o)
|
||||
//if err != nil {
|
||||
// return err
|
||||
//}
|
||||
cfg := config.CgrConfig()
|
||||
go func() {
|
||||
for i := 0; i < 5; i++ { // Loop so we can increase the success rate on best effort
|
||||
if _, err := utils.HttpJsonPost(a.ExtraParameters, cfg.HttpSkipTlsVerify, o); err == nil {
|
||||
break // Success, no need to reinterate
|
||||
} else if i == 4 { // Last iteration, syslog the warning
|
||||
utils.Logger.Warning(fmt.Sprintf("<Triggers> WARNING: Failed calling url: [%s], error: [%s], triggered: %s", a.ExtraParameters, err.Error(), o))
|
||||
break
|
||||
}
|
||||
time.Sleep(time.Duration(i) * time.Minute)
|
||||
}
|
||||
|
||||
}()
|
||||
fallbackPath := path.Join(cfg.HttpFailedDir, fmt.Sprintf("act_%s_%s_%s.json", a.ActionType, a.ExtraParameters, utils.GenUUID()))
|
||||
go utils.HttpPoster(a.ExtraParameters, cfg.HttpSkipTlsVerify, o, utils.CONTENT_JSON, 3, fallbackPath)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@ import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"path"
|
||||
"time"
|
||||
|
||||
"github.com/cgrates/cgrates/config"
|
||||
@@ -362,10 +363,11 @@ func (self *CdrServer) replicateCdr(cdr *StoredCdr) error {
|
||||
}
|
||||
switch rplCfg.Transport {
|
||||
case utils.META_HTTP_POST:
|
||||
httpClient := new(http.Client)
|
||||
errChan := make(chan error)
|
||||
go func(cdr *StoredCdr, rplCfg *config.CdrReplicationCfg, errChan chan error) {
|
||||
if _, err := httpClient.PostForm(fmt.Sprintf("%s", rplCfg.Server), cdr.AsHttpForm()); err != nil {
|
||||
utils.Logger.Debug(fmt.Sprintf("Replicating CDR: %+v, attempts: %d", cdr, rplCfg.Attempts))
|
||||
fallbackPath := path.Join(self.cgrCfg.HttpFailedDir, fmt.Sprintf("cdr_%s_%s_%s.form", rplCfg.Transport, rplCfg.Server, utils.GenUUID()))
|
||||
if _, err := utils.HttpPoster(rplCfg.Server, self.cgrCfg.HttpSkipTlsVerify, cdr.AsHttpForm(), utils.CONTENT_FORM, rplCfg.Attempts, fallbackPath); err != nil {
|
||||
utils.Logger.Err(fmt.Sprintf("<CDRReplicator> Replicating CDR: %+v, got error: %s", cdr, err.Error()))
|
||||
errChan <- err
|
||||
}
|
||||
|
||||
@@ -287,7 +287,6 @@ func (rs *Responder) GetDerivedMaxSessionTime(ev *StoredCdr, reply *float64) err
|
||||
}, ev, utils.EXTRA_FIELDS); err != nil && err != utils.ErrNotFound {
|
||||
return err
|
||||
}
|
||||
|
||||
// replace user profile fields
|
||||
if err := LoadUserProfile(ev, utils.EXTRA_FIELDS); err != nil {
|
||||
return err
|
||||
|
||||
Reference in New Issue
Block a user