From 1ff2af86d40a25b81442e497b9640bdc039caf88 Mon Sep 17 00:00:00 2001 From: DanB Date: Wed, 6 Aug 2014 01:45:32 +0200 Subject: [PATCH] Fix Thresholds not being calculated for new balances --- .../fs_json/cgrates/etc/cgrates/cgrates.cfg | 203 +++++++++++------- .../cgrates/etc/cgrates/cgrates.cfg | 2 +- docs/tut_freeswitch_csv.rst | 2 +- docs/tut_freeswitch_json.rst | 2 +- engine/account.go | 1 + 5 files changed, 126 insertions(+), 84 deletions(-) diff --git a/data/tutorials/fs_json/cgrates/etc/cgrates/cgrates.cfg b/data/tutorials/fs_json/cgrates/etc/cgrates/cgrates.cfg index 51c0894d0..d0fbb63c2 100644 --- a/data/tutorials/fs_json/cgrates/etc/cgrates/cgrates.cfg +++ b/data/tutorials/fs_json/cgrates/etc/cgrates/cgrates.cfg @@ -1,133 +1,174 @@ -# CGRateS Configuration file +# Real-time Charging System for Telecom & ISP environments +# Copyright (C) ITsysCOM GmbH # # This file contains the default configuration hardcoded into CGRateS. # This is what you get when you load CGRateS with an empty configuration file. -# [global] must exist in all files, rest of the configuration is inter-changeable. [global] # ratingdb_type = redis # Rating subsystem database: . -# ratingdb_host = 127.0.0.1 # Rating subsystem database host address. +# ratingdb_host = 127.0.0.1 # Rating subsystem database host address. # ratingdb_port = 6379 # Rating subsystem port to reach the database. # ratingdb_name = 10 # Rating subsystem database name to connect to. -# ratingdb_user = # Rating subsystem username to use when connecting to database. -# ratingdb_passwd = # Rating subsystem password to use when connecting to database. +# ratingdb_user = # Rating subsystem username to use when connecting to database. +# ratingdb_passwd = # Rating subsystem password to use when connecting to database. # accountdb_type = redis # Accounting subsystem database: . -# accountdb_host = 127.0.0.1 # Accounting subsystem database host address. +# accountdb_host = 127.0.0.1 # Accounting subsystem database host address. # accountdb_port = 6379 # Accounting subsystem port to reach the database. # accountdb_name = 11 # Accounting subsystem database name to connect to. -# accountdb_user = # Accounting subsystem username to use when connecting to database. +# accountdb_user = # Accounting subsystem username to use when connecting to database. # accountdb_passwd = # Accounting subsystem password to use when connecting to database. # stordb_type = mysql # Stor database type to use: # stordb_host = 127.0.0.1 # The host to connect to. Values that start with / are for UNIX domain sockets. # stordb_port = 3306 # The port to reach the logdb. # stordb_name = cgrates # The name of the log database to connect to. # stordb_user = cgrates # Username to use when connecting to stordb. -# stordb_passwd = CGRateS.org # Password to use when connecting to stordb. +# stordb_passwd = CGRateS.org # Password to use when connecting to stordb. # dbdata_encoding = msgpack # The encoding used to store object data in strings: -rpc_json_listen = :2012 # RPC JSON listening address -rpc_gob_listen = :2013 # RPC GOB listening address -# http_listen = 127.0.0.1:2080 # HTTP listening address +# rpc_json_listen = 127.0.0.1:2012 # RPC JSON listening address +# rpc_gob_listen = 127.0.0.1:2013 # RPC GOB listening address +# http_listen = 127.0.0.1:2080 # HTTP listening address # default_reqtype = rated # Default request type to consider when missing from requests: <""|prepaid|postpaid|pseudoprepaid|rated>. -# default_tor = call # Default Type of Record to consider when missing from requests. -# default_tenant = cgrates.org # Default Tenant to consider when missing from requests. +# default_category = call # Default Type of Record to consider when missing from requests. +# default_tenant = cgrates.org # Default Tenant to consider when missing from requests. # default_subject = cgrates # Default rating Subject to consider when missing from requests. -# rounding_method = *middle # Rounding method for floats/costs: <*up|*middle|*down> -# rounding_decimals = 4 # Number of decimals to round float/costs at +# rounding_decimals = 10 # System level precision for floats +# http_skip_tls_veify = false # If enabled Http Client will accept any TLS certificate +# xmlcfg_path = # Path towards additional config defined in xml file [balancer] # enabled = false # Start Balancer service: . [rater] -enabled = true # Enable RaterCDRSExportPath service: . +enabled = true # Enable RaterCDRSExportPath service: . # balancer = # Register to Balancer as worker: <""|internal|127.0.0.1:2013>. [scheduler] -enabled = true # Starts Scheduler service: . +enabled = true # Starts Scheduler service: . [cdrs] -enabled = true # Start the CDR Server service: . +enabled = true # Start the CDR Server service: . # extra_fields = # Extra fields to store in CDRs for non-generic CDRs -mediator = internal # Address where to reach the Mediator. Empty for disabling mediation. <""|internal> + mediator = internal # Address where to reach the Mediator. Empty for disabling mediation. <""|internal> +# cdrstats = # Address where to reach the cdrstats service: +# store_disable = false # When true, CDRs will not longer be saved in stordb, useful for cdrstats only scenario [cdre] -# cdr_format = csv # Exported CDRs format -# extra_fields = # List of extra fields to be exported out in CDRs -export_dir = /tmp/cgrates/cdre # Path where the exported CDRs will be placed - +# cdr_format = csv # Exported CDRs format +# data_usage_multiply_factor = 0.0 # Multiply data usage before export (eg: convert from KBytes to Bytes) +# cost_multiply_factor = 0.0 # Multiply cost before export (0.0 to disable), eg: add VAT +# cost_rounding_decimals = -1 # Rounding decimals for Cost values. -1 to disable rounding +# cost_shift_digits = 0 # Shift digits in the cost on export (eg: convert from EUR to cents) +# mask_destination_id = # Destination id containing called addresses to be masked on export +# mask_length = 0 # Length of the destination suffix to be masked + export_dir = /tmp/cgrates/cdre # Path where the exported CDRs will be placed +# export_template = cgrid,mediation_runid,tor,accid,reqtype,direction,tenant,category,account,subject,destination,setup_time,answer_time,usage,cost + # Exported fields template <""|fld1,fld2|*xml:instance_name> [cdrc] -# enabled = false # Enable CDR client functionality -# cdrs = internal # Address where to reach CDR server. -# cdrs_method = http_cgr # Mechanism to use when posting CDRs on server -# run_delay = 0 # Sleep interval in seconds between consecutive runs, 0 to use automation via inotify -# cdr_type = csv # CDR file format . -# cdr_in_dir = /var/log/cgrates/cdr/cdrc/in # Absolute path towards the directory where the CDRs are stored. -# cdr_out_dir = /var/log/cgrates/cdr/cdrc/out # Absolute path towards the directory where processed CDRs will be moved. -# cdr_source_id = freeswitch_csv # Free form field, tag identifying the source of the CDRs within CGRS database. -# accid_field = 0 # Accounting id field identifier. Use index number in case of .csv cdrs. -# reqtype_field = 1 # Request type field identifier. Use index number in case of .csv cdrs. -# direction_field = 2 # Direction field identifier. Use index numbers in case of .csv cdrs. -# tenant_field = 3 # Tenant field identifier. Use index numbers in case of .csv cdrs. -# tor_field = 4 # Type of Record field identifier. Use index numbers in case of .csv cdrs. -# account_field = 5 # Account field identifier. Use index numbers in case of .csv cdrs. -# subject_field = 6 # Subject field identifier. Use index numbers in case of .csv CDRs. -# destination_field = 7 # Destination field identifier. Use index numbers in case of .csv cdrs. -# setup_time_field = 8 # Setup time field identifier. Use index numbers in case of .csv cdrs. -# answer_time_field = 9 # Answer time field identifier. Use index numbers in case of .csv cdrs. -# duration_field = 10 # Duration field identifier. Use index numbers in case of .csv cdrs. -# extra_fields = # Extra fields identifiers. For .csv, format: :[...,:] +# enabled = false # Enable CDR client functionality +# cdrs = internal # Address where to reach CDR server. +# run_delay = 0 # Sleep interval in seconds between consecutive runs, 0 to use automation via inotify +# cdr_type = csv # CDR file format . +# csv_separator = , # Separator used in case of csv files. One character only supported and needs to be right after equal sign +# cdr_in_dir = /var/log/cgrates/cdrc/in # Absolute path towards the directory where the CDRs are stored. +# cdr_out_dir = /var/log/cgrates/cdrc/out # Absolute path towards the directory where processed CDRs will be moved. +# cdr_source_id = csv # Free form field, tag identifying the source of the CDRs within CGRS database. +# tor_field = 2 # TypeOfRecord field identifier. Use index number in case of .csv cdrs. +# accid_field = 3 # Accounting id field identifier. Use index number in case of .csv cdrs. +# reqtype_field = 4 # Request type field identifier. Use index number in case of .csv cdrs. +# direction_field = 5 # Direction field identifier. Use index numbers in case of .csv cdrs. +# tenant_field = 6 # Tenant field identifier. Use index numbers in case of .csv cdrs. +# category_field = 7 # Type of Record field identifier. Use index numbers in case of .csv cdrs. +# account_field = 8 # Account field identifier. Use index numbers in case of .csv cdrs. +# subject_field = 9 # Subject field identifier. Use index numbers in case of .csv CDRs. +# destination_field = 10 # Destination field identifier. Use index numbers in case of .csv cdrs. +# setup_time_field = 11 # Setup time field identifier. Use index numbers in case of .csv cdrs. +# answer_time_field = 12 # Answer time field identifier. Use index numbers in case of .csv cdrs. +# usage_field = 13 # Usage field identifier. Use index numbers in case of .csv cdrs. +# extra_fields = # Extra fields identifiers. For .csv, format: :[...,:] [mediator] -enabled = true # Starts Mediator service: . + enabled = true # Starts Mediator service: . +# reconnects = 3 # Number of reconnects to rater/cdrs before giving up. # rater = internal # Address where to reach the Rater: -# rater_reconnects = 3 # Number of reconnects to rater before giving up. -# run_ids = # Identifiers of each extra mediation to run on CDRs -# reqtype_fields = # Name of request type fields to be used during extra mediation. Use index number in case of .csv cdrs. -# direction_fields = # Name of direction fields to be used during extra mediation. Use index numbers in case of .csv cdrs. -# tenant_fields = # Name of tenant fields to be used during extra mediation. Use index numbers in case of .csv cdrs. -# tor_fields = # Name of tor fields to be used during extra mediation. Use index numbers in case of .csv cdrs. -# account_fields = # Name of account fields to be used during extra mediation. Use index numbers in case of .csv cdrs. -# subject_fields = # Name of fields to be used during extra mediation. Use index numbers in case of .csv cdrs. -# destination_fields = # Name of destination fields to be used during extra mediation. Use index numbers in case of .csv cdrs. -# setup_time_fields = # Name of setup_time fields to be used during extra mediation. Use index numbers in case of .csv cdrs. -# answer_time_fields = # Name of answer_time fields to be used during extra mediation. Use index numbers in case of .csv cdrs. -# duration_fields = # Name of duration fields to be used during extra mediation. Use index numbers in case of .csv cdrs. +# cdrstats = internal # Address where to reach the cdrstats service: +# store_disable = false # When true, CDRs will not longer be saved in stordb, useful for cdrstats only scenario + + +[cdrstats] + enabled = true # Starts the cdrstats service: +# queue_length = 50 # Number of items in the stats buffer +# time_window = 1h # Will only keep the CDRs who's call setup time is not older than time.Now()-TimeWindow +# metrics = ASR, ACD, ACC # Stat metric ids to build +# setup_interval = # Filter on CDR SetupTime +# tors = # Filter on CDR TOR fields +# cdr_hosts= # Filter on CDR CdrHost fields +# cdr_sources = # Filter on CDR CdrSource fields +# req_types = # Filter on CDR ReqType fields +# directions = # Filter on CDR Direction fields +# tenants = # Filter on CDR Tenant fields +# categories = # Filter on CDR Category fields +# accounts = # Filter on CDR Account fields +# subjects = # Filter on CDR Subject fields +# destination_prefixes = # Filter on CDR Destination prefixes +# usage_interval = # Filter on CDR Usage +# mediation_run_ids = # Filter on CDR MediationRunId fields +# rated_accounts = # Filter on CDR RatedAccount fields +# rated_subjects = # Filter on CDR RatedSubject fields +# cost_intervals = # Filter on CDR Cost [session_manager] -enabled = true # Starts SessionManager service: . -# switch_type = freeswitch # Defines the type of switch behind: . -# rater = internal # Address where to reach the Rater. -# rater_reconnects = 3 # Number of reconnects to rater before giving up. -# debit_interval = 10 # Interval to perform debits on. -# max_call_duration = 3h # Maximum call duration a prepaid call can last -# run_ids = # Identifiers of additional sessions control. -# reqtype_fields = # Name of request type fields to be used during additional sessions control <""|*default|field_name>. -# direction_fields = # Name of direction fields to be used during additional sessions control <""|*default|field_name>. -# tenant_fields = # Name of tenant fields to be used during additional sessions control <""|*default|field_name>. -# tor_fields = # Name of tor fields to be used during additional sessions control <""|*default|field_name>. -# account_fields = # Name of account fields to be used during additional sessions control <""|*default|field_name>. -# subject_fields = # Name of fields to be used during additional sessions control <""|*default|field_name>. -# destination_fields = # Name of destination fields to be used during additional sessions control <""|*default|field_name>. -# setup_time_fields = # Name of setup_time fields to be used during additional sessions control <""|*default|field_name>. -# answer_time_fields = # Name of answer_time fields to be used during additional sessions control <""|*default|field_name>. -# duration_fields = # Name of duration fields to be used during additional sessions control <""|*default|field_name>. + enabled = true # Starts SessionManager service: +# switch_type = freeswitch # Defines the type of switch behind: +# rater = internal # Address where to reach the Rater <""|internal|127.0.0.1:2013> +# cdrs = # Address where to reach CDR Server, empty to disable CDR capturing <""|internal|127.0.0.1:2013> +# reconnects = 3 # Number of reconnects to rater/cdrs before giving up. +# debit_interval = 10 # Interval to perform debits on. +# min_call_duration = 0s # Only authorize calls with allowed duration bigger than this +# max_call_duration = 3h # Maximum call duration a prepaid call can last [freeswitch] -# server = 127.0.0.1:8021 # Adress where to connect to FreeSWITCH socket. +# server = 127.0.0.1:8021 # Adress where to connect to FreeSWITCH socket. # passwd = ClueCon # FreeSWITCH socket password. # reconnects = 5 # Number of attempts on connect failure. +# min_dur_low_balance = 5s # Threshold which will trigger low balance warnings for prepaid calls (needs to be lower than debit_interval) +# low_balance_ann_file = # File to be played when low balance is reached for prepaid calls +# empty_balance_context = # If defined, prepaid calls will be transfered to this context on empty balance +# empty_balance_ann_file = # File to be played before disconnecting prepaid calls on empty balance (applies only if no context defined) +# cdr_extra_fields = # Extra fields to store in CDRs in case of processing them + +[opensips] +# listen_udp = 127.0.0.1:2020 # Address where to listen for datagram events coming from OpenSIPS +# mi_addr = 127.0.0.1:8020 # Adress where to reach OpenSIPS mi_datagram module +# events_subscribe_interval = 60s # Automatic events subscription to OpenSIPS, 0 to disable it +# reconnects = 3 # Number of attempts on connect failure. + +[derived_charging] +# run_ids = # Identifiers of additional sessions control. +# run_filters = # List of cdr field filters for each run. +# reqtype_fields = # Name of request type fields to be used during additional sessions control <""|*default|field_name>. +# direction_fields = # Name of direction fields to be used during additional sessions control <""|*default|field_name>. +# tenant_fields = # Name of tenant fields to be used during additional sessions control <""|*default|field_name>. +# category_fields = # Name of tor fields to be used during additional sessions control <""|*default|field_name>. +# account_fields = # Name of account fields to be used during additional sessions control <""|*default|field_name>. +# subject_fields = # Name of fields to be used during additional sessions control <""|*default|field_name>. +# destination_fields = # Name of destination fields to be used during additional sessions control <""|*default|field_name>. +# setup_time_fields = # Name of setup_time fields to be used during additional sessions control <""|*default|field_name>. +# answer_time_fields = # Name of answer_time fields to be used during additional sessions control <""|*default|field_name>. +# usage_fields = # Name of usage fields to be used during additional sessions control <""|*default|field_name>. +# combined_chargers = true # Combine accounts specific derived_chargers with server configured ones . [history_server] -enabled = true # Starts History service: . -history_dir = /tmp/cgrates/history # Location on disk where to store history files. -# save_interval = 1s # Interval to save changed cache into .git archive + enabled = true # Starts History service: . +# history_dir = /tmp/cgrates/history # Location on disk where to store history files. +# save_interval = 1s # Interval to save changed cache into .git archive [history_agent] -# enabled = false # Starts History as a client: . + enabled = true # Starts History as a client: . # server = internal # Address where to reach the master history server: [mailer] -# server = localhost # The server to use when sending emails out -# auth_user = cgrates # Authenticate to email server using this user -# auth_passwd = CGRateS.org # Authenticate to email server with this password +# server = localhost # The server to use when sending emails out +# auth_user = cgrates # Authenticate to email server using this user +# auth_passwd = CGRateS.org # Authenticate to email server with this password # from_address = cgr-mailer@localhost.localdomain # From address used when sending emails out diff --git a/data/tutorials/osips_event/cgrates/etc/cgrates/cgrates.cfg b/data/tutorials/osips_event/cgrates/etc/cgrates/cgrates.cfg index 25206c5ff..f5bbe387b 100644 --- a/data/tutorials/osips_event/cgrates/etc/cgrates/cgrates.cfg +++ b/data/tutorials/osips_event/cgrates/etc/cgrates/cgrates.cfg @@ -131,7 +131,7 @@ cdrs = internal # Address where to reach the CDR server for CDR processing # reconnects = 5 # Number of attempts on connect failure. # min_dur_low_balance = 5s # Threshold which will trigger low balance warnings for prepaid calls (needs to be lower than debit_interval) # low_balance_ann_file = # File to be played when low balance is reached for prepaid calls -# empty_balance_context = # If defined, prepaid calls will be transfered to this context on empty balance +# empty_balance_context = # If defined, prepaid calls will be transfered to this context on empty balance # empty_balance_ann_file = # File to be played before disconnecting prepaid calls on empty balance (applies only if no context defined) [opensips] diff --git a/docs/tut_freeswitch_csv.rst b/docs/tut_freeswitch_csv.rst index a95c777e0..3bc8a545a 100644 --- a/docs/tut_freeswitch_csv.rst +++ b/docs/tut_freeswitch_csv.rst @@ -66,7 +66,7 @@ For our tutorial we load again prepared data out of shared folder, containing fo :: - cgr-loader -verbose -path=/usr/share/cgrates/tutorials/fs_csv/cgrates/tariffplans + cgr-loader -verbose -path=/usr/share/cgrates/tariffplans/tutorial To verify that all actions successfully performed, we use following *cgr-console* commands: diff --git a/docs/tut_freeswitch_json.rst b/docs/tut_freeswitch_json.rst index 76ced6dcb..2e807b179 100644 --- a/docs/tut_freeswitch_json.rst +++ b/docs/tut_freeswitch_json.rst @@ -72,7 +72,7 @@ For our tutorial we load again prepared data out of shared folder, containing fo :: - cgr-loader -verbose -path=/usr/share/cgrates/tutorials/fs_json/cgrates/tariffplans + cgr-loader -verbose -path=/usr/share/cgrates/tariffplans/tutorial To verify that all actions successfully performed, we use following *cgr-console* commands: diff --git a/engine/account.go b/engine/account.go index d2d486938..d65031597 100644 --- a/engine/account.go +++ b/engine/account.go @@ -124,6 +124,7 @@ func (ub *Account) debitBalanceAction(a *Action) error { // if it is not found then we add it to the list if !found { a.Balance.Value = -a.Balance.Value + a.Balance.dirty = true // Mark the balance as dirty since we have modified and it should be checked by action triggers ub.BalanceMap[id] = append(ub.BalanceMap[id], a.Balance) if a.Balance.SharedGroup != "" { // add shared group member