diff --git a/agents/diam_prom_it_test.go b/agents/diam_prom_it_test.go index 381d3cd83..a05a9c437 100644 --- a/agents/diam_prom_it_test.go +++ b/agents/diam_prom_it_test.go @@ -34,7 +34,7 @@ import ( ) func TestDiamPrometheus(t *testing.T) { - t.Skip("test by looking at the log output") + // t.Skip("test by looking at the log output") switch *utils.DBType { case utils.MetaInternal: case utils.MetaMySQL, utils.MetaMongo, utils.MetaPostgres: @@ -69,7 +69,7 @@ func TestDiamPrometheus(t *testing.T) { "prometheus_agent": { "enabled": true, "stats_conns": ["*localhost"], - "stat_queue_ids": ["SQ_1"] + "stat_queue_ids": ["SQ_1","SQ_2"] }, "stats": { "enabled": true, @@ -105,8 +105,8 @@ func TestDiamPrometheus(t *testing.T) { "*message", "*accounts", "*cdrs", - "*daStats:*ids:SQ_1", - "*daThresholds:*ids:TH_1", + "*daStats:SQ_1&SQ_2", + "*daThresholds:TH_1&TH_2", ], "request_fields": [{ "tag": "ToR", @@ -248,6 +248,29 @@ cgrates.org,DEFAULT,*string:~*req.Account:1001,,*default,*none,10`, t.Fatal(err) } + if err := client.Call(context.Background(), utils.APIerSv1SetStatQueueProfile, + engine.StatQueueProfileWithAPIOpts{ + StatQueueProfile: &engine.StatQueueProfile{ + Tenant: "cgrates.org", + ID: "SQ_2", + FilterIDs: []string{"*string:~*req.Category:sms"}, + QueueLength: -1, + TTL: 10 * time.Second, + Metrics: []*engine.MetricWithFilters{ + { + MetricID: "*average#~*req.ProcessingTime", + }, + { + MetricID: "*sum#~*req.ProcessingTime", + }, + }, + Stored: true, + MinItems: 1, + }, + }, &reply); err != nil { + t.Fatal(err) + } + if err := client.Call(context.Background(), utils.APIerSv1SetThresholdProfile, engine.ThresholdProfileWithAPIOpts{ ThresholdProfile: &engine.ThresholdProfile{ @@ -263,6 +286,21 @@ cgrates.org,DEFAULT,*string:~*req.Account:1001,,*default,*none,10`, t.Fatal(err) } + if err := client.Call(context.Background(), utils.APIerSv1SetThresholdProfile, + engine.ThresholdProfileWithAPIOpts{ + ThresholdProfile: &engine.ThresholdProfile{ + Tenant: "cgrates.org", + ID: "TH_2", + FilterIDs: []string{"*string:~*req.Category:sms"}, + MaxHits: -1, + MinHits: 10, + MinSleep: time.Second, + ActionIDs: []string{"ACT_LOG_WARNING"}, + }, + }, &reply); err != nil { + t.Fatal(err) + } + time.Sleep(500 * time.Millisecond) diamClient, err := NewDiameterClient(cfg.DiameterAgentCfg().Listen, "localhost", cfg.DiameterAgentCfg().OriginRealm, cfg.DiameterAgentCfg().VendorID, diff --git a/agents/libagents.go b/agents/libagents.go index 6f189cd57..80916f7de 100644 --- a/agents/libagents.go +++ b/agents/libagents.go @@ -213,21 +213,21 @@ func processRequest(ctx *context.Context, reqProcessor *config.RequestProcessor, return true, nil } - var statIDs, thIDs []string + var rawStatIDs, rawThIDs string switch agentName { case utils.DiameterAgent: - statIDs = reqProcessor.Flags.ParamsSlice(utils.MetaDAStats, utils.MetaIDs) - thIDs = reqProcessor.Flags.ParamsSlice(utils.MetaDAThresholds, utils.MetaIDs) + rawStatIDs = reqProcessor.Flags.ParamValue(utils.MetaDAStats) + rawThIDs = reqProcessor.Flags.ParamValue(utils.MetaDAThresholds) case utils.HTTPAgent: - statIDs = reqProcessor.Flags.ParamsSlice(utils.MetaHAStats, utils.MetaIDs) - thIDs = reqProcessor.Flags.ParamsSlice(utils.MetaHAThresholds, utils.MetaIDs) + rawStatIDs = reqProcessor.Flags.ParamValue(utils.MetaHAStats) + rawThIDs = reqProcessor.Flags.ParamValue(utils.MetaHAThresholds) case utils.DNSAgent: - statIDs = reqProcessor.Flags.ParamsSlice(utils.MetaDNSStats, utils.MetaIDs) - thIDs = reqProcessor.Flags.ParamsSlice(utils.MetaDNSThresholds, utils.MetaIDs) + rawStatIDs = reqProcessor.Flags.ParamValue(utils.MetaDNSStats) + rawThIDs = reqProcessor.Flags.ParamValue(utils.MetaDNSThresholds) } // Return early if nothing to process. - if len(statIDs) == 0 && len(thIDs) == 0 { + if rawStatIDs == "" && rawThIDs == "" { return true, nil } @@ -241,7 +241,8 @@ func processRequest(ctx *context.Context, reqProcessor *config.RequestProcessor, ev.Event[utils.Source] = agentName ev.APIOpts[utils.MetaEventType] = utils.ProcessTime - if len(statIDs) > 0 { + if rawStatIDs != "" { + statIDs := strings.Split(rawStatIDs, utils.ANDSep) ev.APIOpts[utils.OptsStatsProfileIDs] = statIDs var reply []string if err := connMgr.Call(ctx, statsConns, utils.StatSv1ProcessEvent, @@ -252,7 +253,8 @@ func processRequest(ctx *context.Context, reqProcessor *config.RequestProcessor, // NOTE: ProfileIDs APIOpts key persists for the ThresholdS request, // although it would be ignored. Might want to delete it. } - if len(thIDs) > 0 { + if rawThIDs != "" { + thIDs := strings.Split(rawThIDs, utils.ANDSep) ev.APIOpts[utils.OptsThresholdsProfileIDs] = thIDs var reply []string if err := connMgr.Call(ctx, thConns, utils.ThresholdSv1ProcessEvent, diff --git a/agents/radagent.go b/agents/radagent.go index c942dd1da..ffb8861eb 100644 --- a/agents/radagent.go +++ b/agents/radagent.go @@ -482,11 +482,11 @@ func (ra *RadiusAgent) processRequest(req *radigo.Packet, reqProcessor *config.R return true, nil } - statIDs := reqProcessor.Flags.ParamsSlice(utils.MetaRAStats, utils.MetaIDs) - thIDs := reqProcessor.Flags.ParamsSlice(utils.MetaRAThresholds, utils.MetaIDs) + rawStatIDs := reqProcessor.Flags.ParamValue(utils.MetaRAStats) + rawThIDs := reqProcessor.Flags.ParamValue(utils.MetaRAThresholds) // Early return if nothing to process. - if len(statIDs) == 0 && len(thIDs) == 0 { + if rawStatIDs == "" && rawThIDs == "" { return true, nil } @@ -500,7 +500,8 @@ func (ra *RadiusAgent) processRequest(req *radigo.Packet, reqProcessor *config.R ev.Event[utils.Source] = utils.RadiusAgent ev.APIOpts[utils.MetaEventType] = utils.ProcessTime - if len(statIDs) > 0 { + if rawStatIDs != "" { + statIDs := strings.Split(rawStatIDs, utils.ANDSep) ev.APIOpts[utils.OptsStatsProfileIDs] = statIDs var reply []string if err := ra.connMgr.Call(ra.ctx, ra.cgrCfg.RadiusAgentCfg().StatSConns, @@ -511,7 +512,8 @@ func (ra *RadiusAgent) processRequest(req *radigo.Packet, reqProcessor *config.R // NOTE: ProfileIDs APIOpts key persists for the ThresholdS request, // although it would be ignored. Might want to delete it. } - if len(thIDs) > 0 { + if rawThIDs != "" { + thIDs := strings.Split(rawThIDs, utils.ANDSep) ev.APIOpts[utils.OptsThresholdsProfileIDs] = thIDs var reply []string if err := ra.connMgr.Call(ra.ctx, ra.cgrCfg.RadiusAgentCfg().ThresholdSConns,