diff --git a/cmd/cgr-engine/cgr-engine.go b/cmd/cgr-engine/cgr-engine.go index 85002e719..56117e59f 100644 --- a/cmd/cgr-engine/cgr-engine.go +++ b/cmd/cgr-engine/cgr-engine.go @@ -189,6 +189,7 @@ func startSessionManager(responder *engine.Responder, loggerDb engine.LogStorage sm, _ = sessionmanager.NewOSipsSessionManager(cfg, raterConn, cdrsConn) default: engine.Logger.Err(fmt.Sprintf(" Unsupported session manger type: %s!", cfg.SMSwitchType)) + exitChan <- true } if err = sm.Connect(); err != nil { engine.Logger.Err(fmt.Sprintf(" error: %s!", err)) diff --git a/cmd/cgr-loader/cgr-loader.go b/cmd/cgr-loader/cgr-loader.go index 57c10574d..c0d6f19b4 100644 --- a/cmd/cgr-loader/cgr-loader.go +++ b/cmd/cgr-loader/cgr-loader.go @@ -232,6 +232,9 @@ func main() { } if cdrstats != nil { statsQueueIds, _ := loader.GetLoadedIds(engine.CDR_STATS_PREFIX) + if *flush { + statsQueueIds = []string{} // Force reload all + } if len(statsQueueIds) != 0 { if *verbose { log.Print("Reloading CDRStats data") diff --git a/data/tariffplans/tutorial/ActionTriggers.csv b/data/tariffplans/tutorial/ActionTriggers.csv index e227892e0..024f25e96 100644 --- a/data/tariffplans/tutorial/ActionTriggers.csv +++ b/data/tariffplans/tutorial/ActionTriggers.csv @@ -2,8 +2,10 @@ STANDARD_TRIGGERS,*monetary,*out,*min_balance,2,false,0,,,,,,,LOG_WARNING,10 STANDARD_TRIGGERS,*monetary,*out,*max_balance,20,false,0,,,,,,,LOG_WARNING,10 STANDARD_TRIGGERS,*monetary,*out,*max_counter,5,false,0,FS_USERS,,,,,,LOG_WARNING,10 -CDRST5_WARN,,,*min_asr,45,true,1m,,,,,,3,LOG_WARNING,10 -CDRST5_WARN,,,*min_acd,10,true,1m,,,,,,5,LOG_WARNING,10 -CDRST5_WARN,,,*max_acc,10,true,1m,,,,,,5,LOG_WARNING,10 -CDRST6_WARN,,,*min_asr,30,true,0,,,,,,5,LOG_WARNING,10 -CDRST6_WARN,,,*min_acd,3,true,0,,,,,,2,LOG_WARNING,10 \ No newline at end of file +CDRST1_WARN,,,*min_asr,45,true,1m,,,,,,3,LOG_WARNING,10 +CDRST1_WARN,,,*min_acd,10,true,1m,,,,,,5,LOG_WARNING,10 +CDRST1_WARN,,,*max_acc,10,true,1m,,,,,,5,LOG_WARNING,10 +CDRST1001_WARN,,,*min_asr,65,true,1m,,,,,,3,LOG_WARNING,10 +CDRST1001_WARN,,,*min_acd,10,true,1m,,,,,,5,LOG_WARNING,10 +CDRST1001_WARN,,,*max_acc,5,true,1m,,,,,,5,LOG_WARNING,10 +CDRST3_WARN,,,*min_acd,60,true,1m,,,,,,5,LOG_WARNING,10 \ No newline at end of file diff --git a/data/tariffplans/tutorial/CdrStats.csv b/data/tariffplans/tutorial/CdrStats.csv index f38beadcc..17623959a 100644 --- a/data/tariffplans/tutorial/CdrStats.csv +++ b/data/tariffplans/tutorial/CdrStats.csv @@ -1,6 +1,13 @@ -#Id,QueueLength,TimeWindow,Metrics,SetupInterval,TOR,CdrHost,CdrSource,ReqType,Direction,Tenant,Category,Account,Subject,DestinationPrefix,UsageInterval,MediationRunIds,RatedAccount,RatedSubject,CostInterval,Triggers -CDRST5,5,1m,ASR,,*voice,,,,*out,cgrates.org,call,1001,1001,,,default,,,,CDRST5_WARN -CDRST5,,,ACD,,,,,,,,,,,,,,,,, -CDRST5,,,ACC,,,,,,,,,,,,,,,,, -CDRST6,10,0,ASR,,,,,,,cgrates.org,,,,,,default,,,,CDRST6_WARN -CDRST6,,,ACD,,,,,,,,,,,,,,,,, \ No newline at end of file +#Id,QueueLength,TimeWindow,Metric,SetupInterval,TOR,CdrHost,CdrSource,ReqType,Direction,Tenant,Category,Account,Subject,DestinationPrefix,UsageInterval,MediationRunIds,RatedAccount,RatedSubject,CostInterval,Triggers +CDRST1,10,0,ASR,,,,,,,cgrates.org,,,,,,default,,,,CDRST1_WARN +CDRST1,,,ACD,,,,,,,,,,,,,,,,, +CDRST1,,,ACC,,,,,,,,,,,,,,,,, +CDRST_1001,10,10m,ASR,,,,,,,cgrates.org,,,1001,,,default,,,,CDRST1001_WARN +CDRST_1001,,,ACD,,,,,,,,,,,,,,,,, +CDRST_1001,,,ACC,,,,,,,,,,,,,,,,, +CDRST_1002,10,10m,ASR,,,,,,,cgrates.org,,,1002,,,default,,,,CDRST1001_WARN +CDRST_1002,,,ACD,,,,,,,,,,,,,,,,, +CDRST_1002,,,ACC,,,,,,,,,,,,,,,,, +CDRST_1003,,,ASR,,,,,,,cgrates.org,,,,1003,,default,,,,CDRST3_WARN +CDRST_1003,,,ACD,,,,,,,,,,,,,,,,, + diff --git a/data/tariffplans/tutorial/README.md b/data/tariffplans/tutorial/README.md index 8209dcb4e..65f577afe 100644 --- a/data/tariffplans/tutorial/README.md +++ b/data/tariffplans/tutorial/README.md @@ -1,4 +1,4 @@ -Tutorial FS_JSON +CGRateS Tutorial ================ Scenario: @@ -15,25 +15,30 @@ Scenario: - Account 1001 will receive a special *deal* for 1002 and 1003 destinations during peak times with *RT_20CNT*, otherwise same as default rating. - Create 5 accounts (equivalent of FreeSWITCH default test users - 1001, 1002, 1003, 1004, 1007). -- 1002, 1003, 1004 will receive 10units of *monetary balance. -- 1001 will receive 5 units of general *monetary and 5 units of shared balance in the shared group *SHARED_A*. -- 1007 will receive 0 units of shared balance in the shared group *SHARED_A*. -- Define the shared balance *SHARED_A* with debit policy *highest. + + - 1002, 1003, 1004 will receive 10units of *monetary balance. + - 1001 will receive 5 units of general *monetary and 5 units of shared balance in the shared group *SHARED_A*. + - 1007 will receive 0 units of shared balance in the shared group *SHARED_A*. + - Define the shared balance *SHARED_A* with debit policy *highest. + +- Create 1 RatingProfile Alias: 1006 - alias of rating profile 1001. +- Create 1 Account Alias: 1006 - alias of account 1002. - For each balance created, attach 3 triggers to control the balance: log on balance=2, log on balance=20, log on 5 mins talked towards 10xx destination. -- Add 2 CDRStats Queue configurations: +- Add 4 CDRStats Queue configurations (extra to default one configured in .cfg file): + + - CDRStatsQueueId: *CDRST1* with purpose of monitoring calls on the Tenant=cgrates.org, and MediationRunId=default, with a QueueLength of 10 CDRs and no TimeWindow, monitoring ASR, ACD and ACC. Thrrough ActionTriggers *CDRST1_WARN* we monitor *min_asr(45), *min_acd(10) and *max_acc(10) parameters and log the warning on thresholds reached. + - CDRStatsQueueId: *CDRST_1001* with a QueueLength of 10 CDRs and a TimeWindow of 10 minutes, gathering ASR,ACD and ACC metrics with CDR filters on Tenant=cgrates.org, Subject=1001 and MediationRunId=default with the purpose of monitoring calls of user 1001. To this queue we attach an ActionTrigger profile named *CDRST1001_WARN* which will monitor min_asr(65), min_acd(10), max_acc(5) and log to syslog a warning once thresholds are reached. - - CDRStatsQueueId: *CDRST5* with a QueueLength of 5 CDRs and a TimeWindow of 1 minute monitoring ASR, ACD and ACC for CDRs with filters on TOR=*voice, Direction=*out, Tenant=cgrates.org, Category=call, Account=1001, Subject=1001 and MediationRunId=default. To this queue we attach ActionTriggers profile named CDRST5_WARN - - CDRStatsQueueId: *CDRST6* with a QueueLength of 10 CDRs and no TimeWindow gathering ASR and ACD metrics with CDR filters on Tenant=cgrates.org and MediationRunId=default. To this queue we attach an ActionTrigger profile named CDRST6_WARN. - ActionTrigger: *CDRST5_WARN* with thresholds explained bellow and having as action the *log on syslog - - Threshold on *min_asr of 45, configured as recurrent with a sleep time of 1 minute and a minimum of 3 items in the stats queue. - - Threshold on *min_acd of 10, configured as recurrent with a sleep time of 1 minute and a minimum of 5 items in the stats queue. - - Threshold on *max_acc of 10, configured as recurrent with a sleep time of 1 minute and a minimum of 5 items in the stats queue. + - Threshold on *min_asr of 45, configured as recurrent with a sleep time of 1 minute and a minimum of 3 items in the stats queue. + - Threshold on *min_acd of 10, configured as recurrent with a sleep time of 1 minute and a minimum of 5 items in the stats queue. + - Threshold on *max_acc of 10, configured as recurrent with a sleep time of 1 minute and a minimum of 5 items in the stats queue. - ActionTrigger: *CDRST6_WARN* with thresholds explained bellow and having as action the *log on syslog - - Threshold on *min_asr of 30, configured as recurrent without sleep time and a minimum of 5 items in the stats queue. - - Threshold on *min_acd of 3, configured as recurrent without sleep time and a minimum of 2 items in the stats queue. + - Threshold on *min_asr of 30, configured as recurrent without sleep time and a minimum of 5 items in the stats queue. + - Threshold on *min_acd of 3, configured as recurrent without sleep time and a minimum of 2 items in the stats queue. diff --git a/engine/mediator.go b/engine/mediator.go index d7eb3a4d3..d67e6d153 100644 --- a/engine/mediator.go +++ b/engine/mediator.go @@ -175,11 +175,11 @@ func (self *Mediator) RateCdr(storedCdr *utils.StoredCdr, sendToStats bool) erro } } if sendToStats && self.stats != nil { // We send to stats only after saving to db since there are chances we cannot store and then no way to reproduce stats offline - go func() { + go func(cdr *utils.StoredCdr) { // Pass it by value since the variable will be overwritten by for if err := self.stats.AppendCDR(cdr, nil); err != nil { Logger.Err(fmt.Sprintf("Could not append cdr to stats (mediator): %s", err.Error())) } - }() + }(cdr) } } return nil diff --git a/sessionmanager/osipssm.go b/sessionmanager/osipssm.go index b7da51257..384fe79fe 100644 --- a/sessionmanager/osipssm.go +++ b/sessionmanager/osipssm.go @@ -122,6 +122,7 @@ func (osm *OsipsSessionManager) SubscribeEvents(evStop chan struct{}) error { continue // Try again } if !success { + engine.Logger.Err(fmt.Sprintf(" Shutting down, failed subscribing to OpenSIPS at address: <%s>", osm.cgrCfg.OsipsMiAddr)) close(osm.stopServing) // Do not serve anymore since we got errors on subscribing return errors.New("Failed subscribing to OpenSIPS events") }