Added *log exporter

This commit is contained in:
Trial97
2021-09-06 12:47:32 +03:00
committed by Dan Christian Bogos
parent 9d5827ef11
commit 5a12eb483d
8 changed files with 146 additions and 82 deletions

View File

@@ -73,81 +73,81 @@ var (
testApierInitStorDb,
testApierStartEngine,
testApierRpcConn,
// testApierTPTiming,
// testApierTPDestination,
// testApierTPRate,
// testApierTPDestinationRate,
// testApierTPRatingPlan,
// testApierTPRatingProfile,
// testApierTPActions,
// testApierTPActionPlan,
// testApierTPActionTriggers,
// testApierTPAccountActions,
// testApierLoadRatingPlan,
// testApierLoadRatingProfile,
// testApierLoadRatingProfileWithoutTenant,
// testApierLoadAccountActions,
// testApierReloadScheduler,
// testApierSetRatingProfile,
// testApierSetRatingProfileWithoutTenant,
// testApierRemoveRatingProfilesWithoutTenant,
// testAPIerSv1GetRatingProfile,
// testAPIerSv1GetRatingProfileWithoutTenant,
// testAPIerSv1GetRatingProfileIDsWithoutTenant,
// testApierReloadCache,
// testApierGetActionTrigger,
// testApierGetDestination,
// testApierGetRatingPlan,
// testApierRemoveRatingPlan,
// testApierAddBalance,
// testApierExecuteAction,
// testApierExecuteActionWithoutTenant,
// testApierSetActions,
// testApierGetActions,
// testApierSetActionPlan,
// testApierAddTriggeredAction,
// testApierGetAccountActionTriggers,
// testApierAddTriggeredAction2,
// testApierGetAccountActionTriggers2,
// testApierSetAccountActionTriggers,
// testApierRemAccountActionTriggers,
// testApierSetAccount,
// testApierGetAccountActionPlan,
// testApierGetAccountActionPlanWithoutTenant,
// testApierITGetScheduledActionsForAccount,
// testApierRemUniqueIDActionTiming,
// testApierRemUniqueIDActionTimingWithoutTenant,
// testApierGetAccount,
// testApierTriggersExecute,
// testApierResetDataBeforeLoadFromFolder,
// testApierLoadTariffPlanFromFolder,
// testApierComputeReverse,
// testApierResetDataAfterLoadFromFolder,
// testApierSetChargerS,
// testApierGetAccountAfterLoad,
// testApierResponderGetCost,
// testApierMaxDebitInexistentAcnt,
// testApierCdrServer,
// testApierITGetCdrs,
// testApierITProcessCdr,
// testApierGetCallCostLog,
// testApierITSetDestination,
// testApierITGetScheduledActions,
// testApierITGetDataCost,
// testApierITGetCost,
testApierTPTiming,
testApierTPDestination,
testApierTPRate,
testApierTPDestinationRate,
testApierTPRatingPlan,
testApierTPRatingProfile,
testApierTPActions,
testApierTPActionPlan,
testApierTPActionTriggers,
testApierTPAccountActions,
testApierLoadRatingPlan,
testApierLoadRatingProfile,
testApierLoadRatingProfileWithoutTenant,
testApierLoadAccountActions,
testApierReloadScheduler,
testApierSetRatingProfile,
testApierSetRatingProfileWithoutTenant,
testApierRemoveRatingProfilesWithoutTenant,
testAPIerSv1GetRatingProfile,
testAPIerSv1GetRatingProfileWithoutTenant,
testAPIerSv1GetRatingProfileIDsWithoutTenant,
testApierReloadCache,
testApierGetActionTrigger,
testApierGetDestination,
testApierGetRatingPlan,
testApierRemoveRatingPlan,
testApierAddBalance,
testApierExecuteAction,
testApierExecuteActionWithoutTenant,
testApierSetActions,
testApierGetActions,
testApierSetActionPlan,
testApierAddTriggeredAction,
testApierGetAccountActionTriggers,
testApierAddTriggeredAction2,
testApierGetAccountActionTriggers2,
testApierSetAccountActionTriggers,
testApierRemAccountActionTriggers,
testApierSetAccount,
testApierGetAccountActionPlan,
testApierGetAccountActionPlanWithoutTenant,
testApierITGetScheduledActionsForAccount,
testApierRemUniqueIDActionTiming,
testApierRemUniqueIDActionTimingWithoutTenant,
testApierGetAccount,
testApierTriggersExecute,
testApierResetDataBeforeLoadFromFolder,
testApierLoadTariffPlanFromFolder,
testApierComputeReverse,
testApierResetDataAfterLoadFromFolder,
testApierSetChargerS,
testApierGetAccountAfterLoad,
testApierResponderGetCost,
testApierMaxDebitInexistentAcnt,
testApierCdrServer,
testApierITGetCdrs,
testApierITProcessCdr,
testApierGetCallCostLog,
testApierITSetDestination,
testApierITGetScheduledActions,
testApierITGetDataCost,
testApierITGetCost,
testApierInitDataDb2,
testApierInitStorDb2,
// testApierReloadCache2,
// testApierReloadScheduler2,
// testApierImportTPFromFolderPath,
// testApierLoadTariffPlanFromStorDbDryRun,
// testApierGetCacheStats2,
// testApierLoadTariffPlanFromStorDb,
// testApierStartStopServiceStatus,
testApierReloadCache2,
testApierReloadScheduler2,
testApierImportTPFromFolderPath,
testApierLoadTariffPlanFromStorDbDryRun,
testApierGetCacheStats2,
testApierLoadTariffPlanFromStorDb,
testApierStartStopServiceStatus,
testApierReplayFldPosts,
// testApierGetDataDBVesions,
// testApierGetStorDBVesions,
// testApierBackwardsCompatible,
testApierGetDataDBVesions,
testApierGetStorDBVesions,
testApierBackwardsCompatible,
testApierStopEngine,
//start test for cache options

View File

@@ -339,7 +339,7 @@ func (attr *AttrSetActionTrigger) UpdateActionTrigger(at *engine.ActionTrigger,
}
if minQ, has := attr.ActionTrigger[utils.MinQueuedItems]; has {
var mQ int64
if mQ, err = utils.IfaceAsInt64(minQ); err != nil {
if mQ, err = utils.IfaceAsTInt64(minQ); err != nil {
return
}
at.MinQueuedItems = int(mQ)

View File

@@ -325,7 +325,8 @@ var possibleReaderTypes = utils.NewStringSet([]string{utils.MetaFileCSV,
var possibleExporterTypes = utils.NewStringSet([]string{utils.MetaFileCSV, utils.MetaNone, utils.MetaFileFWV,
utils.MetaHTTPPost, utils.MetaHTTPjsonMap, utils.MetaAMQPjsonMap, utils.MetaAMQPV1jsonMap, utils.MetaSQSjsonMap,
utils.MetaKafkajsonMap, utils.MetaS3jsonMap, utils.MetaElastic, utils.MetaVirt, utils.MetaSQL, utils.MetaNatsjsonMap})
utils.MetaKafkajsonMap, utils.MetaS3jsonMap, utils.MetaElastic, utils.MetaVirt, utils.MetaSQL, utils.MetaNatsjsonMap,
utils.MetaLog})
// LazySanityCheck used after check config sanity to display warnings related to the config
func (cfg *CGRConfig) LazySanityCheck() {

View File

@@ -70,11 +70,13 @@ func NewEventExporter(cfg *config.EventExporterCfg, cgrCfg *config.CGRConfig, fi
case utils.MetaKafkajsonMap:
return NewKafkaEE(cfg, dc), nil
case utils.MetaVirt:
return NewVirtualEE(cfg, dc)
return NewVirtualEE(cfg, dc), nil
case utils.MetaElastic:
return NewElasticEE(cfg, dc)
case utils.MetaSQL:
return NewSQLEe(cfg, dc)
case utils.MetaLog:
return NewLogEE(cfg, dc), nil
default:
return nil, fmt.Errorf("unsupported exporter type: <%s>", cfg.Type)
}

View File

@@ -157,10 +157,7 @@ func TestNewEventExporterCase6(t *testing.T) {
if err != nil {
t.Error(err)
}
eeExpect, err := NewVirtualEE(cgrCfg.EEsCfg().Exporters[0], dc)
if err != nil {
t.Error(err)
}
eeExpect := NewVirtualEE(cgrCfg.EEsCfg().Exporters[0], dc)
newEE := ee.(*VirtualEE)
newEE.dc.MapStorage[utils.TimeNow] = nil
eeExpect.dc.MapStorage[utils.TimeNow] = nil

64
ees/log.go Normal file
View File

@@ -0,0 +1,64 @@
/*
Real-time Online/Offline Charging System (OerS) for Telecom & ISP environments
Copyright (C) ITsysCOM GmbH
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package ees
import (
"fmt"
"strings"
"github.com/cgrates/cgrates/config"
"github.com/cgrates/cgrates/utils"
)
func NewLogEE(cfg *config.EventExporterCfg, dc *utils.SafeMapStorage) *LogEE {
return &LogEE{
cfg: cfg,
dc: dc,
}
}
// LogEE implements EventExporter interface for .csv files
type LogEE struct {
cfg *config.EventExporterCfg
dc *utils.SafeMapStorage
}
func (vEe *LogEE) Cfg() *config.EventExporterCfg { return vEe.cfg }
func (vEe *LogEE) Connect() error { return nil }
func (vEe *LogEE) ExportEvent(mp interface{}, _ string) error {
utils.Logger.Info(
fmt.Sprintf("<%s> <%s> exported: <%s>",
utils.EEs, vEe.Cfg().ID, utils.ToJSON(mp)))
return nil
}
func (vEe *LogEE) Close() error { return nil }
func (vEe *LogEE) GetMetrics() *utils.SafeMapStorage { return vEe.dc }
func (vEe *LogEE) PrepareMap(mp map[string]interface{}) (interface{}, error) {
return mp, nil
}
func (vEe *LogEE) PrepareOrderMap(mp *utils.OrderedNavigableMap) (interface{}, error) {
valMp := make(map[string]interface{})
for el := mp.GetFirstElement(); el != nil; el = el.Next() {
path := el.Value
nmIt, _ := mp.Field(path)
path = path[:len(path)-1] // remove the last index
valMp[strings.Join(path, utils.NestingSep)] = nmIt.String()
}
return valMp, nil
}

View File

@@ -23,12 +23,11 @@ import (
"github.com/cgrates/cgrates/utils"
)
func NewVirtualEE(cfg *config.EventExporterCfg, dc *utils.SafeMapStorage) (vEe *VirtualEE, err error) {
vEe = &VirtualEE{
func NewVirtualEE(cfg *config.EventExporterCfg, dc *utils.SafeMapStorage) *VirtualEE {
return &VirtualEE{
cfg: cfg,
dc: dc,
}
return
}
// VirtualEE implements EventExporter interface for .csv files

View File

@@ -170,6 +170,7 @@ cgrates (0.11.0~dev) UNRELEASED; urgency=medium
* [EEs] Added *nats_json_map
* [RSRParsers] Added *slice dataconverter
* [CacheS] Updated LoadCache and ReloadCache APIs
* [EEs] Added *log exporter
-- DanB <danb@cgrates.org> Wed, 19 Feb 2020 13:25:52 +0200