From fc2476633b5050f03b143bf2b2611a9185d389ac Mon Sep 17 00:00:00 2001 From: DanB Date: Tue, 31 Mar 2015 18:42:51 +0200 Subject: [PATCH] Kamailio max session time fix from nanoseconds to seconds --- .../kamevapi/cgrates/etc/cgrates/cgrates.cfg | 178 ------------------ sessionmanager/kamevent.go | 4 + sessionmanager/kamevent_test.go | 2 +- 3 files changed, 5 insertions(+), 179 deletions(-) delete mode 100644 data/tutorials/kamevapi/cgrates/etc/cgrates/cgrates.cfg diff --git a/data/tutorials/kamevapi/cgrates/etc/cgrates/cgrates.cfg b/data/tutorials/kamevapi/cgrates/etc/cgrates/cgrates.cfg deleted file mode 100644 index 19ceb0bde..000000000 --- a/data/tutorials/kamevapi/cgrates/etc/cgrates/cgrates.cfg +++ /dev/null @@ -1,178 +0,0 @@ -# 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] -# ratingdb_type = redis # Rating subsystem database: . -# 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. -# accountdb_type = redis # Accounting subsystem database: . -# 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_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 stordb. -# 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_max_open_conns = 0s # Maximum database connections opened -# stordb_max_idle_conns = -10 # Maximum database connections idle -# dbdata_encoding = msgpack # The encoding used to store object data in strings: -# 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_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_decimals = 10 # System level precision for floats -# http_skip_tls_veify = false # If enabled Http Client will accept any TLS certificate -# tpexport_dir = /var/log/cgrates/tpe # Path towards export folder for offline Tariff Plans -# xmlcfg_path = # Path towards additional config defined in xml file - -[balancer] -# enabled = false # Start Balancer service: . - -[rater] -enabled = true # Enable RaterCDRSExportPath service: . -# balancer = # Register to Balancer as worker: <""|internal|127.0.0.1:2013>. - -[scheduler] -enabled = true # Starts Scheduler service: . - -[cdrs] -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> -cdrstats = internal # Address where to reach the cdrstats service. Empty to disable stats gathering from raw CDRs <""|internal|x.y.z.y:1234> -# 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 -# 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 = /var/log/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. -# run_delay = 0 # Sleep interval in seconds between consecutive runs, 0 to use automation via inotify -# cdr_format = csv # CDR file format . -# field_separator = , # Separator used in case of csv files. One character only supported and needs to be right after equal sign -# data_usage_multiply_factor = 1 # Conversion factor for data usage -# 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: . -# reconnects = 3 # Number of reconnects to rater/cdrs before giving up. -# rater = internal # Address where to reach the Rater: -# cdrstats = # Address where to reach the cdrstats service. Empty to disable stats gathering out of mediated CDRs <""|internal|x.y.z.y:1234> -# 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 = false # 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. -# 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 = /var/log/cgrates/history # Location on disk where to store history files. -# save_interval = 1s # Interval to save changed cache into .git archive - -[history_agent] -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 -# from_address = cgr-mailer@localhost.localdomain # From address used when sending emails out - diff --git a/sessionmanager/kamevent.go b/sessionmanager/kamevent.go index c3f81fbd2..e8c55847d 100644 --- a/sessionmanager/kamevent.go +++ b/sessionmanager/kamevent.go @@ -306,6 +306,10 @@ func (kev KamEvent) AsKamAuthReply(maxSessionTime float64, authErr error) (*KamA if kar.TransactionLabel, err = strconv.Atoi(kev[KAM_TR_LABEL]); err != nil { return nil, err } + if maxSessionTime != -1 { // Convert maxSessionTime from nanoseconds into seconds + maxSessionDur := time.Duration(maxSessionTime) + maxSessionTime = maxSessionDur.Seconds() + } kar.MaxSessionTime = int(utils.Round(maxSessionTime, 0, utils.ROUNDING_MIDDLE)) kar.AuthError = authErr diff --git a/sessionmanager/kamevent_test.go b/sessionmanager/kamevent_test.go index 2a2835ce3..0ff8fca29 100644 --- a/sessionmanager/kamevent_test.go +++ b/sessionmanager/kamevent_test.go @@ -55,7 +55,7 @@ func TestNewKamEvent(t *testing.T) { func TestKevAsKamAuthReply(t *testing.T) { expectedKar := &KamAuthReply{Event: CGR_AUTH_REPLY, TransactionIndex: 29223, TransactionLabel: 698469260, MaxSessionTime: 1200} - if rcvKar, err := kamEv.AsKamAuthReply(1200.0, nil); err != nil { + if rcvKar, err := kamEv.AsKamAuthReply(1200000000000.0, nil); err != nil { t.Error(err) } else if !reflect.DeepEqual(expectedKar, rcvKar) { t.Error("Received KAR: ", rcvKar)