mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Fix balance thresholds not being executed
This commit is contained in:
@@ -11,7 +11,7 @@ Scenario:
|
||||
- Rate id: *RT_10CNT* with connect fee of 20cents, 10cents per minute for the first 60s in 60s increments followed by 5cents per minute in 1s increments.
|
||||
- Rate id: *RT_20CNT* with connect fee of 40cents, 20cents per minute for the first 60s in 60s increments, followed by 10 cents per minute charged in 1s increments.
|
||||
- Rate id: *RT_40CNT* with connect fee of 80cents, 40cents per minute for the first 60s in 60s increments, follwed by 20cents per minute charged in 10s increments.
|
||||
- Will charge by default *RT_40CNT* for all FreeSWITCH_ destinations during peak times (Monday-Friday 08:00-19:00) and *RT_10CNT* during offpeatimes (rest).
|
||||
- Will charge by default *RT_40CNT* for all FreeSWITCH_ destinations during peak time (Monday-Friday 08:00-19:00) and *RT_10CNT* during offpeatimes (rest).
|
||||
- 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).
|
||||
|
||||
@@ -74,31 +74,31 @@ To verify that all actions successfully performed, we use following *cgr-console
|
||||
|
||||
::
|
||||
|
||||
cgr-console get_cache_stats
|
||||
cgr-console get_cache_age 1002
|
||||
cgr-console get_cache_age RP_RETAIL
|
||||
cgr-console get_cache_age *out:cgrates.org:call:*any
|
||||
cgr-console get_cache_age LOG_WARNING
|
||||
cgr-console cache_stats
|
||||
cgr-console 'cache_age 1002'
|
||||
cgr-console 'cache_age RP_RETAIL1'
|
||||
cgr-console 'cache_age *out:cgrates.org:call:*any'
|
||||
cgr-console 'cache_age LOG_WARNING'
|
||||
|
||||
- Make sure all our balances were topped-up:
|
||||
|
||||
::
|
||||
|
||||
cgr-console get_balance cgrates.org 1001
|
||||
cgr-console get_balance cgrates.org 1002
|
||||
cgr-console get_balance cgrates.org 1003
|
||||
cgr-console get_balance cgrates.org 1004
|
||||
cgr-console 'account Tenant="cgrates.org" Account="1001"'
|
||||
cgr-console 'account Tenant="cgrates.org" Account="1002"'
|
||||
cgr-console 'account Tenant="cgrates.org" Account="1003"'
|
||||
cgr-console 'account Tenant="cgrates.org" Account="1004"'
|
||||
|
||||
- Query call costs so we can see our calls will have expected costs (final cost will result as sum of *ConnectFee* and *Cost* fields):
|
||||
|
||||
::
|
||||
|
||||
cgr-console get_cost call cgrates.org 1001 1002 *now 20s
|
||||
cgr-console get_cost call cgrates.org 1001 1002 *now 1m25s
|
||||
cgr-console get_cost call cgrates.org 1001 1003 *now 20s
|
||||
cgr-console get_cost call cgrates.org 1001 1003 *now 1m25s
|
||||
cgr-console get_cost call cgrates.org 1001 1004 *now 20s
|
||||
cgr-console get_cost call cgrates.org 1001 1004 *now 1m25s
|
||||
cgr-console 'cost Category="call" Tenant="cgrates.org" Subject="1001" Destination="1002" TimeStart="2014-08-04T13:00:00Z" TimeEnd="2014-08-04T13:00:20Z"'
|
||||
cgr-console 'cost Category="call" Tenant="cgrates.org" Subject="1001" Destination="1002" TimeStart="2014-08-04T13:00:00Z" TimeEnd="2014-08-04T13:01:25Z"'
|
||||
cgr-console 'cost Category="call" Tenant="cgrates.org" Subject="1001" Destination="1003" TimeStart="2014-08-04T13:00:00Z" TimeEnd="2014-08-04T13:00:20Z"'
|
||||
cgr-console 'cost Category="call" Tenant="cgrates.org" Subject="1001" Destination="1003" TimeStart="2014-08-04T13:00:00Z" TimeEnd="2014-08-04T13:01:25Z"'
|
||||
cgr-console 'cost Category="call" Tenant="cgrates.org" Subject="1001" Destination="1004" TimeStart="2014-08-04T13:00:00Z" TimeEnd="2014-08-04T13:00:20Z"'
|
||||
cgr-console 'cost Category="call" Tenant="cgrates.org" Subject="1001" Destination="1004" TimeStart="2014-08-04T13:00:00Z" TimeEnd="2014-08-04T13:01:25Z"'
|
||||
|
||||
|
||||
Test calls
|
||||
@@ -116,7 +116,7 @@ Check that 1001 balance is properly debitted, during the call:
|
||||
|
||||
::
|
||||
|
||||
cgr-console get_balance cgrates.org 1001
|
||||
cgr-console 'account Tenant="cgrates.org" Account="1001"'
|
||||
|
||||
|
||||
1002 -> 1001
|
||||
@@ -128,7 +128,7 @@ To check that we had debits we use again console command, this time not during t
|
||||
|
||||
::
|
||||
|
||||
cgr-console get_balance cgrates.org 1002
|
||||
cgr-console 'account Tenant="cgrates.org" Account="1002"'
|
||||
|
||||
|
||||
1003 -> 1001
|
||||
@@ -140,7 +140,7 @@ To check that there are no debits during or by the end of the call, but when the
|
||||
|
||||
::
|
||||
|
||||
cgr-console get_balance cgrates.org 1003
|
||||
cgr-console 'account Tenant="cgrates.org" Account="1003"'
|
||||
|
||||
|
||||
1004 -> 1001
|
||||
@@ -156,7 +156,7 @@ Since we have configured some action triggers (more than 20 units of balance top
|
||||
|
||||
::
|
||||
|
||||
cgr-console add_balance cgrates.org 1003 21
|
||||
cgr-console 'balance_set Tenant="cgrates.org" Account="1003" Direction="*out" Value=23'
|
||||
tail -f /var/log/syslog -n 20
|
||||
|
||||
*Note*: The actions are only executed once, in order to be repetive they need to be reset (via automated or manual process).
|
||||
@@ -182,7 +182,7 @@ Once the CDRs are mediated, can be exported as *.csv* format again via remote co
|
||||
|
||||
::
|
||||
|
||||
cgr-console export_cdrs csv
|
||||
cgr-console 'cdrs_export CdrFormat="csv" ExportDir="/tmp"'
|
||||
|
||||
|
||||
.. _FreeSWITCH: http://www.freeswitch.org/
|
||||
|
||||
@@ -80,32 +80,32 @@ To verify that all actions successfully performed, we use following *cgr-console
|
||||
|
||||
::
|
||||
|
||||
cgr-console get_cache_stats
|
||||
cgr-console get_cache_age 1002
|
||||
cgr-console get_cache_age RP_RETAIL1
|
||||
cgr-console get_cache_age *out:cgrates.org:call:*any
|
||||
cgr-console get_cache_age LOG_WARNING
|
||||
cgr-console cache_stats
|
||||
cgr-console 'cache_age 1002'
|
||||
cgr-console 'cache_age RP_RETAIL1'
|
||||
cgr-console 'cache_age *out:cgrates.org:call:*any'
|
||||
cgr-console 'cache_age LOG_WARNING'
|
||||
|
||||
- Make sure all our balances were topped-up:
|
||||
|
||||
::
|
||||
|
||||
cgr-console get_account cgrates.org 1001
|
||||
cgr-console get_account cgrates.org 1002
|
||||
cgr-console get_account cgrates.org 1003
|
||||
cgr-console get_account cgrates.org 1004
|
||||
cgr-console get_account cgrates.org 1007
|
||||
cgr-console 'account Tenant="cgrates.org" Account="1001"'
|
||||
cgr-console 'account Tenant="cgrates.org" Account="1002"'
|
||||
cgr-console 'account Tenant="cgrates.org" Account="1003"'
|
||||
cgr-console 'account Tenant="cgrates.org" Account="1004"'
|
||||
cgr-console 'account Tenant="cgrates.org" Account="1005"'
|
||||
|
||||
- Query call costs so we can see our calls will have expected costs (final cost will result as sum of *ConnectFee* and *Cost* fields):
|
||||
|
||||
::
|
||||
|
||||
cgr-console get_cost call cgrates.org 1001 1002 *now 20s
|
||||
cgr-console get_cost call cgrates.org 1001 1002 *now 1m25s
|
||||
cgr-console get_cost call cgrates.org 1001 1003 *now 20s
|
||||
cgr-console get_cost call cgrates.org 1001 1003 *now 1m25s
|
||||
cgr-console get_cost call cgrates.org 1001 1004 *now 20s
|
||||
cgr-console get_cost call cgrates.org 1001 1004 *now 1m25s
|
||||
cgr-console 'cost Category="call" Tenant="cgrates.org" Subject="1001" Destination="1002" TimeStart="2014-08-04T13:00:00Z" TimeEnd="2014-08-04T13:00:20Z"'
|
||||
cgr-console 'cost Category="call" Tenant="cgrates.org" Subject="1001" Destination="1002" TimeStart="2014-08-04T13:00:00Z" TimeEnd="2014-08-04T13:01:25Z"'
|
||||
cgr-console 'cost Category="call" Tenant="cgrates.org" Subject="1001" Destination="1003" TimeStart="2014-08-04T13:00:00Z" TimeEnd="2014-08-04T13:00:20Z"'
|
||||
cgr-console 'cost Category="call" Tenant="cgrates.org" Subject="1001" Destination="1003" TimeStart="2014-08-04T13:00:00Z" TimeEnd="2014-08-04T13:01:25Z"'
|
||||
cgr-console 'cost Category="call" Tenant="cgrates.org" Subject="1001" Destination="1004" TimeStart="2014-08-04T13:00:00Z" TimeEnd="2014-08-04T13:00:20Z"'
|
||||
cgr-console 'cost Category="call" Tenant="cgrates.org" Subject="1001" Destination="1004" TimeStart="2014-08-04T13:00:00Z" TimeEnd="2014-08-04T13:01:25Z"'
|
||||
|
||||
|
||||
Test calls
|
||||
@@ -123,7 +123,7 @@ Check that 1001 balance is properly debitted, during the call, and moreover cons
|
||||
|
||||
::
|
||||
|
||||
cgr-console get_account cgrates.org 1001
|
||||
cgr-console 'account Tenant="cgrates.org" Account="1001"'
|
||||
|
||||
|
||||
1002 -> 1001
|
||||
@@ -135,7 +135,7 @@ To check that we had debits we use again console command, this time not during t
|
||||
|
||||
::
|
||||
|
||||
cgr-console get_account cgrates.org 1002
|
||||
cgr-console 'account Tenant="cgrates.org" Account="1002"'
|
||||
|
||||
|
||||
1003 -> 1001
|
||||
@@ -147,7 +147,7 @@ To check that there are no debits during or by the end of the call, but when the
|
||||
|
||||
::
|
||||
|
||||
cgr-console get_account cgrates.org 1003
|
||||
cgr-console 'account Tenant="cgrates.org" Account="1003"'
|
||||
|
||||
|
||||
1004 -> 1001
|
||||
@@ -165,8 +165,8 @@ Check that 1001 balance is properly debitted, during the call, and moreover cons
|
||||
|
||||
::
|
||||
|
||||
cgr-console get_account cgrates.org 1006
|
||||
cgr-console get_account cgrates.org 1001
|
||||
cgr-console 'account Tenant="cgrates.org" Account="1006"'
|
||||
cgr-console 'account Tenant="cgrates.org" Account="1001"'
|
||||
|
||||
|
||||
1007 -> 1002
|
||||
@@ -178,8 +178,8 @@ Check that call can proceed even if 1007 has no units left into his own balances
|
||||
|
||||
::
|
||||
|
||||
cgr-console get_account cgrates.org 1007
|
||||
cgr-console get_account cgrates.org 1001
|
||||
cgr-console 'account Tenant="cgrates.org" Account="1007"'
|
||||
cgr-console 'account Tenant="cgrates.org" Account="1001"'
|
||||
|
||||
|
||||
Fraud detection
|
||||
@@ -189,10 +189,10 @@ Since we have configured some action triggers (more than 20 units of balance top
|
||||
|
||||
::
|
||||
|
||||
cgr-console add_balance cgrates.org 1003 21
|
||||
cgr-console 'balance_set Tenant="cgrates.org" Account="1003" Direction="*out" Value=23'
|
||||
tail -f /var/log/syslog -n 20
|
||||
|
||||
*Note*: The actions are only executed once, in order to be repetive they need to be reset (via automated or manual process).
|
||||
*Note*: The actions are only executed once, in order to be repetive they need to be recurrent or reset via a manual or automated process.
|
||||
|
||||
|
||||
CDR processing
|
||||
@@ -202,7 +202,7 @@ At the end of each call FreeSWITCH_ will issue a http post with the CDR. This wi
|
||||
|
||||
::
|
||||
|
||||
cgr-console export_cdrs csv
|
||||
cgr-console 'cdrs_export CdrFormat="csv" ExportDir="/tmp"'
|
||||
|
||||
|
||||
.. _FreeSWITCH: http://www.freeswitch.org/
|
||||
|
||||
@@ -328,7 +328,7 @@ func (ub *Account) executeActionTriggers(a *Action) {
|
||||
for _, at := range ub.ActionTriggers {
|
||||
// sanity check
|
||||
if !strings.Contains(at.ThresholdType, "counter") &&
|
||||
strings.Contains(at.ThresholdType, "balance") {
|
||||
!strings.Contains(at.ThresholdType, "balance") {
|
||||
continue
|
||||
}
|
||||
if at.Executed {
|
||||
|
||||
@@ -241,7 +241,7 @@ func (at *ActionTiming) Execute() (err error) {
|
||||
} else if ub.Disabled {
|
||||
return 0, fmt.Errorf("User %s is disabled", ubId)
|
||||
}
|
||||
Logger.Info(fmt.Sprintf("Executing %v on %v", a.ActionType, ub.Id))
|
||||
//Logger.Info(fmt.Sprintf("Executing %v on %v", a.ActionType, ub.Id))
|
||||
err = actionFunction(ub, nil, a)
|
||||
accountingStorage.SetAccount(ub)
|
||||
return 0, nil
|
||||
|
||||
@@ -77,7 +77,7 @@ func (at *ActionTrigger) Execute(ub *Account, sq *StatsQueue) (err error) {
|
||||
Logger.Warning(fmt.Sprintf("Function type %v not available, aborting execution!", a.ActionType))
|
||||
return
|
||||
}
|
||||
go Logger.Info(fmt.Sprintf("Executing %v, %v: %v", ub, sq, a))
|
||||
//go Logger.Info(fmt.Sprintf("Executing %v, %v: %v", ub, sq, a))
|
||||
err = actionFunction(ub, sq, a)
|
||||
if err == nil {
|
||||
atLeastOneActionExecuted = true
|
||||
|
||||
Reference in New Issue
Block a user