The following sections in the config file can be used to configure accounting.
The section defines a list of modules that will be performing accounting. The accounting is for logging gatekeeper on/off events and call start/stop/update events. Each accounting module logs received events to a module specific storage. Such storage can be a plain text file or a RADIUS server and many more. The configuration is very similar to the one for gatekeeper authentication (see [Gatekeeper::Auth]).
All CDRs are also sent to the status port and can be used by external applications.
acctmod=actions
<acctmod> := FileAcct | RadAcct | SQLAcct | StatusAcct | SyslogAcct | CapacityControl | ...
<actions> := <control>[;<event>,<event>,...]
<control> := optional | required | sufficient | alternative
<event> := start | stop | connect | update | on | off
start
- a call has been started and a Setup message has been received (only available in routed mode),connect
- a call has been connected (only available in routed mode),update
- a call is active and the periodic update is performed
to reflect the new call duration. Frequency of such updates is determined
by AcctUpdateInterval variable from
[CallTable]
section,stop
- a call has been disconnected (removed from the GK call table),on
- the gatekeeper has been started,off
- the gatekeeper has been shut down.ok
- the event has been logged successfully by this module,fail
- the module failed to log the event,next
- the event has not been logged by this module, because the module
is not configured for/does not support this event type.required
- if the module fails to log an event, the final status
is set to failure and the event is passed down to any remaining
modules,optional
- the module tries to log an event, but the final status
is not affected by success or failure (except when the module
is last on the list). The event is always passed down
to any remaining modules,sufficient
- the module determines the final status. If an event
is logged successfully, no remaining modules are processed.
Otherwise the final status is set to failure and the event
is passed down to any remaining modules,alternative
- if the module logs an event successfully, no remaining
modules are processed. Otherwise the final status is
not modified and the event is passed down to any remaining
modules.Currently supported accounting modules:
FileAcct
A plain CDR text file logger. It outputs status line like CDR lines to a specified text file. This module supports only stop accounting event. Configuration settings are read from [FileAcct] section.
RadAcct
This module performs RADIUS accounting. It supports all event types (start, stop, update, on, off). See the section [RadAcct] for configuration details.
SQLAcct
This module performs direct SQL accounting. It supports (start, connect, stop, update) event types. See the section [SQLAcct] for configuration details.
StatusAcct
This module logs all accounting events on the status port. It can be used to interface to external application in real-time. It supports (start, connect, stop, update) event types. See the section [StatusAcct] for configuration details.
SyslogAcct
This module logs all accounting events on the Unix syslog. It supports (start, connect, stop, update) event types. See the section [SyslogAcct] for configuration details.
CapacityControl
This module performs inbound call volume logging, required for CapacityControl
authentication module to work correctly. See the section
[CapacityControl]
for details.
default
This is a special pseudo module - it is used to set the final status if preceding modules have not determined it. The format is as follows:
default=<status>[;<event>,<event>,...]
<status> := accept | fail
<event> := start | stop | update | on | off
The sample configuration #1 (try to log call start/stop with RADIUS server, and always write a CDR to a text file):
RadAcct=optional;start,stop
FileAcct=required
The sample configuration #2 (try to log call start/stop with RADIUS server, if it fails use a CDR log file):
RadAcct=alternative;start,stop
FileAcct=sufficient;stop
default=accept
The sample configuration #3 (always log call start and stop events with RADIUS server, if it fails for call stop event, use a CDR file to store call info):
RadAcct=alternative;start,stop
FileAcct=sufficient;stop
default=fail;start
This accounting module writes CDR lines to a specified text file. The CDR format can be a standard one (the same as displayed by the status interface) or a customized one (using parametrized query string).
DetailFile=FULL_PATH_AND_FILENAME
N/A
A full path to the CDR plain text file. If a file with the given name already exists, new CDRs will be appended at the end of the file.
StandardCDRFormat=0
1
Use a CDR format compatible with the status interface CDR format (1
)
or build a custom CDR strings from the CDRString parametrized string.
The StandardCDRFormat is equivalent to this definition:
TimestampFormat=RFC822
CDRString=CDR|%n|%{CallId}|%d|%{connect-time}|%{disconnect-time}|%{caller-ip}:%{caller-port}|%{caller-epid}|%{callee-ip}:%{callee-port}|{callee-epid}|%{dest-info}|%{src-info}|%g;
CDRString=%s|%g|%u|%{Calling-Station-Id}|%{Called-Station-Id}|%d|%c
N/A
If StandardCDRFormat is disabled (0) or not specified at all,
this parametrized string instructs the gatekeeper how to build a custom
CDRs. Parameters are specified using %
character and can be one letter
(like %n
) or longer (like %{CallId}
). Any remaining characters that
are not parameter names are simply copied to a final CDR string. The following
parameters are recognized:
%g
- gatekeeper name%n
- call number (not unique after gatekeeper restart)%d
- call duration (seconds)%t
- total call duration (from Setup to Release Complete)%c
- Q.931 disconnect cause (decimal integer) as originally received%{cause-translated}
- Q.931 disconnect cause (decimal integer) after translation rules%r
- who disconnected the call (-1 - unknown, 0 - the gatekeeper, 1 - the caller, 2 - the callee)%p
- PDD (Post Dial Delay) in seconds%s
- unique (for this gatekeeper) session identifier (Acct-Session-Id)%u
- H.323 ID of the calling party%{gkip}
- IP address of the gatekeeper%{CallId}
- H.323 call identifier (16 hex 8-bit digits)%{ConfId}
- H.323 conference identifier (16 hex 8-bit digits)%{CallLink}
- Linked H.323 conference identifier (billing account for H.450 call transfer)%{setup-time}
- timestamp string for Q.931 Setup message%{alerting-time}
- timestamp string for Q.931 Alerting message%{connect-time}
- timestamp string for a call connected event%{disconnect-time}
- timestamp string for a call disconnect event%{ring-time}
- time a remote phone was ringing for (from Alerting till Connect or Release Complete)%{caller-ip}
- signaling IP address of the caller%{caller-port}
- signaling port of the caller%{callee-ip}
- signaling IP address of the called party%{callee-port}
- signaling port of the called party%{src-info}
- a colon separated list of source aliases%{dest-info}
- a colon separated list of destination aliases%{Calling-Station-Id}
- calling party number%{Called-Station-Id}
- called party number (rewritten)%{Dialed-Number}
- dialed number (as received from the calling party)%{caller-epid}
- endpoint identifier of the calling party%{callee-epid}
- endpoint identifier of the called party%{call-attempts}
- number of attempts to establish the calls (with failover this can be > 1)%{last-cdr}
- is this the last CDR for this call ? (0 / 1) only when using failover this can be 0%{media-oip}
- caller's RTP media IP (only for H.245 routed/tunneled calls)%{codec}
- audio codec used during the call (only for H.245 routed/tunneled calls)%{bandwidth}
- bandwidth for this callTimestampFormat=Cisco
N/A
Format of timestamp strings printed in CDR strings. If this setting is not specified, a global one from the main gatekeeper section is applied.
Rotate=hourly | daily | weekly | monthly | L... | S...
N/A
If set, the CDR file will be rotated based on this setting. Hourly rotation
enables rotation once per hour, daily - once per day, weekly - once per week
and monthly - once per month. An exact rotation moment is determined by a combination
of RotateDay and RotateTime. During rotation, an existing file is renamed
to CURRENT_FILENAME.YYYYMMDD-HHMMSS, where YYYYMMDD-HHMMSS is replaced with
the current timestamp, and new CDRs are logged to an empty file.
In addition, rotation per number of CDRs written (L...) and per file size (S...)
is supported. The L
prefix specifies a number of CDR lines written,
the S
prefix specifies CDR file size. k
and m
suffixes can
be used to specify thousands (kilobytes) and millions (megabytes).
See the examples for more details.
[FileAcct]
DetailFile=/var/log/gk/cdr.log
[FileAcct]
DetailFile=/var/log/gk/cdr.log
Rotate=hourly
RotateTime=45
[FileAcct]
DetailFile=/var/log/gk/cdr.log
Rotate=daily
RotateTime=23:00
[FileAcct]
DetailFile=/var/log/gk/cdr.log
Rotate=weekly
RotateDay=Sun
RotateTime=00:59
[FileAcct]
DetailFile=/var/log/gk/cdr.log
Rotate=monthly
RotateDay=31
RotateTime=23:00
[FileAcct]
DetailFile=/var/log/gk/cdr.log
Rotate=L10000
[FileAcct]
DetailFile=/var/log/gk/cdr.log
Rotate=S10k
This accounting module sends accounting data to a RADIUS server. Module configuration is almost the same as for RADIUS authenticators (see [RadAuth] and [RadAliasAuth] for more details on the parameters).
Servers=SERVER1[:AUTH_PORT:ACCT_PORT[:SECRET]];SERVER2[:AUTH_PORT:ACCT_PORT[:SECRET]];...
N/A
RADIUS servers to send accounting data to. If no port information is given,
port number from DefaultAcctPort
is be used. If no secret is set,
the default shared secret from SharedSecret
is used. Server names could
be either IP addresses or DNS names.
Servers
lines:Servers=192.168.1.1
Servers=192.168.1.1:1645:1646
Servers=192.168.1.1:1645:1646:secret1
Servers=radius1.mycompany.com:1812:1813
Servers=radius1.mycompany.com;radius2.mycompany.com
Servers=radius1.mycompany.com:1812:1813:secret1;radius2.mycompany.com:1812:1813:secret2
LocalInterface=IP_OR_FQDN
N/A
Particular local network interface that RADIUS client should use in order to communicate with RADIUS servers.
RadiusPortRange=10000-11000
N/A
By default (if this option is not set) RADIUS client allocates ports dynamically as specified by the operating system. If you want to restrict RADIUS client to use ports from a particular range only - set this parameter.
DefaultAcctPort=PORT_NO
1813
Default port number to be used for RADIUS accounting requests,
if not overridden by Servers
attribute.
SharedSecret=SECRET
N/A (empty string)
A secret used to authenticate this GnuGk (NAS client) to RADIUS
server. It should be a cryptographically strong password. This is the default
value used, if no server-specific secret is set in the Servers
.
If EncryptAllPasswords
is enabled, or a KeyFilled
variable is defined
in this section, the password is in encrypted form and should be created using
the addpasswd
utility.
RequestTimeout=TIMEOUT_MS
2000
(milliseconds)Timeout (milliseconds) for RADIUS server response to a request sent by GnuGk. If no response is received within this time period, next RADIUS server is queried.
IdCacheTimeout=TIMEOUT_MS
9000
(milliseconds)Timeout (milliseconds) for RADIUS request 8-bit identifiers to be unique.
SocketDeleteTimeout=TIMEOUT_MS
60000
(milliseconds) - 60 sTimeout for unused RADIUS sockets to be closed.
RequestRetransmissions=NUMBER
2
How many times a single RADIUS request is transmitted to every configured RADIUS server (if no response is received).
RoundRobinServers=BOOLEAN
1
RADIUS requests retransmission method.
AppendCiscoAttributes=BOOLEAN
0
If set, Cisco Vendor Specific RADIUS attributes are included in RADIUS requests (h323-conf-id,h323-call-origin,h323-call-type).
TimestampFormat=ISO8601
N/A
Format of timestamp strings sent in RADIUS attributes. If this setting is not specified, a global one from the main gatekeeper section is applied.
UseDialedNumber=BOOLEAN
0
Select Called-Station-Id number type between the original one (as dialed
by the user) - UseDialedNumber=1
- and the rewritten one - UseDialedNumber=0
.
This accounting module stores accounting information directly to an SQL database. Many configuration settings are common with other SQL modules.
Driver=MySQL | PostgreSQL | Firebird
N/A
SQL database driver to use. Currently, MySQL
, PostgreSQL
and Firebird
drivers
are implemented.
Host=DNS[:PORT] | IP[:PORT]
localhost
SQL server host address. Can be in the form of DNS[:PORT]
or IP[:PORT]
.
Like sql.mycompany.com
or sql.mycompany.com:3306
or 192.168.3.100
.
Database=billing
billing
The database name to connect to.
Username=gnugk
The username used to connect to the database.
Password=secret
The password used to connect to the database.
If the password is not specified, a database connection attempt
without any password will be made.
If EncryptAllPasswords
is enabled, or a KeyFilled
variable is defined
in this section, the password is in an encrypted form and should be created
using the addpasswd
utility.
StartQuery=INSERT ...
N/A
Defines SQL query used to insert a new call record to the database. The query
is parametrized - that means parameter replacement is made before each query
is executed. Parameter placeholders are denoted by % character and can be one
letter (like %u) or whole strings (like %{src-info}). Specify %% to embed
a percent character inside the query string (like %%).
For SQLAcct
the following parameters are defined:
%g
- gatekeeper name%n
- call number (not unique after gatekeeper restart)%d
- call duration (seconds)%t
- total call duration (from Setup to Release Complete)%c
- Q.931 disconnect cause (hexadecimal integer)%r
- who disconnected the call (-1 - unknown, 0 - the gatekeeper, 1 - the caller, 2 - the callee)%p
- PDD (Post Dial Delay) in seconds%s
- unique (for this gatekeeper) call (Acct-Session-Id)%u
- H.323 ID of the calling party%{gkip}
- IP address of the gatekeeper%{CallId}
- H.323 call identifier (16 hex 8-bit digits)%{ConfId}
- H.323 conference identifier (16 hex 8-bit digits)%{setup-time}
- timestamp string for Q.931 Setup message%{alerting-time}
- timestamp string for Q.931 Alerting message%{connect-time}
- timestamp string for a call connected event%{disconnect-time}
- timestamp string for a call disconnect event%{ring-time}
- time a remote phone was ringing for (from Alerting till Connect or Release Complete)%{caller-ip}
- signaling IP address of the caller%{caller-port}
- signaling port of the caller%{callee-ip}
- signaling IP address of the called party%{callee-port}
- signaling port of the called party%{src-info}
- a colon separated list of source aliases%{dest-info}
- a colon separated list of destination aliases%{Calling-Station-Id}
- calling party number%{Called-Station-Id}
- called party number (rewritten Dialed-Number)%{Dialed-Number}
- dialed number (as received from the calling party)%{caller-epid}
- endpoint identifier of the calling party%{callee-epid}
- endpoint identifier of the called party%{call-attempts}
- number of attempts to establish the calls (with failover this can be > 1)%{last-cdr}
- is this the last CDR for this call ? (0 / 1) only when using failover this can be 0%{media-oip}
- caller's RTP media IP (only for H.245 routed/tunneled calls)%{codec}
- audio codec used during the call (only for H.245 routed/tunneled calls)%{bandwidth}
- bandwidth for this callSample query string:
INSERT INTO call (gkname, sessid, username, calling, called)
VALUES ('%g', '%s', '%u', '%{Calling-Station-Id}', '%{Called-Station-Id}')
StartQueryAlt=INSERT ...
N/A
Defines SQL query used to insert a new call record to the database in case
the StartQuery
failed for some reason (the call already exists, for example).
The syntax and parameters are the same as for StartQuery
.
UpdateQuery=UPDATE ...
N/A
Defines SQL query used to update call record in the database with the current
call state. The syntax and parameters are the same as for StartQuery
.
Sample query string:
UPDATE call SET duration = %d WHERE gkname = '%g' AND sessid = '%s'
StopQuery=UPDATE ...
N/A
Defines SQL query used to update call record in the database when the call
is finished (disconnected). The syntax and parameters are the same
as for StartQuery
.
Sample query string:
UPDATE call SET duration = %d, dtime = '%{disconnect-time}' WHERE gkname = '%g' AND sessid = '%s'
StopQueryAlt=INSERT ...
N/A
Defines SQL query used to update call record in the database when the call
is finished (disconnected) in case the regular StopQuery
failed (because
the call record does not yet exist, for example). The syntax and parameters
are the same as for StartQuery
.
Sample query string:
INSERT INTO call (gkname, sessid, username, calling, called, duration)
VALUES ('%g', '%s', '%u', '%{Calling-Station-Id}', '%{Called-Station-Id}', %d)
TimestampFormat=MySQL
N/A
Format of timestamp strings used in queries. If this setting is not specified, a global one from the main gatekeeper section is used.
MinPoolSize=5
1
Number of concurrent SQL connections in the pool. The first available connection in the pool is used to store accounting data.
The SQLAcct module is designed to adapt to whatever database structure you already have. You can define all queries so they fit your existing tables. But here is an example what those tables might look like in MySQL and you can use these as a starting point.
Create a new database; here we use the name 'GNUGK':
create database GNUGK;
Then create a table in this database to store you accounting data; we call the table 'CDR'.
create table GNUGK.CDR (
gatekeeper_name varchar(255),
call_number int zerofill,
call_duration mediumint unsigned zerofill,
index duration_idx (call_duration),
disconnect_cause smallint unsigned zerofill,
index dcc_idx (disconnect_cause),
acct_session_id varchar(255),
h323_id varchar(255),
gkip varchar(15),
CallId varchar(255),
ConfID varchar(255),
setup_time datetime,
connect_time datetime,
disconnect_time datetime,
caller_ip varchar(15),
index srcip_idx (caller_ip),
caller_port smallint unsigned zerofill,
callee_ip varchar(15),
index destip_idx (callee_ip),
callee_port smallint unsigned zerofill,
src_info varchar(255),
dest_info varchar(255),
Calling_Station_Id varchar(255),
Called_Station_Id varchar(255),
index dialednumber_idx (Called_Station_Id (20)),
Dialed_Number varchar(255)
);
Then you need to create a username for accessing the data.
GRANT delete,insert,select,update ON GNUGK.* TO 'YourDesiredUsername'@'localhost' IDENTIFIED BY 'APassword';
With this command you will permit accessing the data from only the local server. If you need to access these data from any other computer then you have to set the proper security options.
Then you can add the following settings into your gnugk.ini file to insert and update the history of the calls into your database.
[Gatekeeper::Acct]
SQLAcct=optional;start,stop,update
FileAcct=sufficient;stop
[FileAcct]
DetailFile=Add your desire path here something like /var/log/cdr.log
StandardCDRFormat=0
CDRString=%g|%n|%d|%c|%s|%u|%{gkip}|%{CallId}|%{ConfId}|%{setup-time}|%{connect-time}|%{disconnect-time}|%{caller-ip}|%{caller-port}|%{callee-ip}|%{callee-port}|%{src-info}|%{dest-info}|%{Calling-Station-Id}|%{Called-Station-Id}|%{Dialed-Number}
Rotate=daily
RotateTime=23:59
[SQLAcct]
Driver=MySQL
Database=GNUGK
Username=YourDesiredUsername
Password=APassword
StartQuery= insert into CDR (gatekeeper_name, call_number, call_duration, disconnect_cause, acct_session_id, h323_id, gkip, CallId, ConfId, setup_time, connect_time, disconnect_time, caller_ip, caller_port, callee_ip, callee_port, src_info, dest_info, Calling_Station_Id, Called_Station_Id, Dialed_Number) values ('%g', '%n', %d, %c, '%s', '%u', '%{gkip}', '%{CallId}', '%{ConfId}', '%{setup-time}', '%{connect-time}', '%{disconnect-time}', '%{caller-ip}', '%{caller-port}', '%{callee-ip}', '%{callee-port}', '%{src-info}', '%{dest-info}', '%{Calling-Station-Id}', '%{Called-Station-Id}', '%{Dialed-Number}')
StartQueryAlt= insert into CDR (gatekeeper_name, call_number, call_duration, disconnect_cause, acct_session_id, h323_id, gkip, CallId, ConfID, setup_time, connect_time, disconnect_time, caller_ip, caller_port, callee_ip, callee_port, src_info, dest_info, Calling_Station_Id, Called_Station_Id, Dialed_Number) values ('%g', '%n', %d, %c, '%s', '%u', '%{gkip}', '%{CallId}', '%{ConfID}', '%{setup-time}', '%{connect-time}', '%{disconnect-time}', '%{caller-ip}', '%{caller-port}', '%{callee-ip}', '%{callee-port}', '%{src-info}', '%{dest-info}', '%{Calling-Station-Id}', '%{Called-Station-Id}', '%{Dialed-Number}')
UpdateQuery= update CDR set call_duration=%d where gatekeeper_name='%g' and acct_session_id='%s'
StopQuery= update CDR set call_duration=%d, disconnect_cause=%c, disconnect_time='%{disconnect-time}' where gatekeeper_name='%g' and acct_session_id='%s'
StopQueryAlt= insert into CDR (gatekeeper_name, call_number, call_duration, disconnect_cause, acct_session_id, h323_id, gkip, CallId, ConfID, setup_time, connect_time, disconnect_time, caller_ip, caller_port, callee_ip, callee_port, src_info, dest_info, Calling_Station_Id, Called_Station_Id, Dialed_Number) values ('%g STOP Alt', '%n', %d, %c, '%s', '%u', '%{gkip}', '%{CallId}', '%{ConfID}', '%{setup-time}', '%{connect-time}', '%{disconnect-time}', '%{caller-ip}', '%{caller-port}', '%{callee-ip}', '%{callee-port}', '%{src-info}', '%{dest-info}', '%{Calling-Station-Id}', '%{Called-Station-Id}', '%{Dialed-Number}')
TimestampFormat=MySQL
This accounting module sends all accounting information to the status port where it can be used to interface to external systems in real time.
StartEvent=CALL|Start|%{CallId}
CALL|Start|%{caller-ip}:%{caller-port}|%{callee-ip}:%{callee-port}|%{CallId}
Defines the event to display for a new call. The string is parametrized with the same variables as the other accounting modules (See [SQLAcct]).
StopEvent=CALL|Stop|%{CallId}
CALL|Stop|%{caller-ip}:%{caller-port}|%{callee-ip}:%{callee-port}|%{CallId}
Defines the event when a call is finished (disconnected). The syntax and parameters are the same as for StartEvent
. This event is equivalent to the old status port CDR event, but more flexible.
UpdateEvent=CALL|Update|%{CallId}
CALL|Update|%{caller-ip}:%{caller-port}|%{callee-ip}:%{callee-port}|%{CallId}
Defines event used to update the current call state. The syntax and parameters are the same as for StartEvent
.
ConnectEvent=CALL|Connect|%{CallId}
CALL|Connect|%{caller-ip}:%{caller-port}|%{callee-ip}:%{callee-port}|%{CallId}
Defines the event when a call is connected. The syntax and parameters are the same as for StartEvent
.
TimestampFormat=MySQL
N/A
Format of timestamp strings used in events. If this setting is not specified, a global one from the main gatekeeper section is used.
This accounting module sends accounting information to the Unix syslog and is not available on Windows. The local syslog daemon will then route the messages according to the it's configuration (generally /etc/syslog.conf).
SyslogFacility=LOG_LOCAL1
LOG_USER
Set the syslog facility to one of LOG_USER, LOG_DAEMON, LOG_AUTH, LOG_LOCAL0, LOG_LOCAL1, LOG_LOCAL2, LOG_LOCAL3, LOG_LOCAL4, LOG_LOCAL5, LOG_LOCAL6, LOG_LOCAL7.
SyslogLevel=LOG_NOTICE
LOG_INFO
Set the syslog level to on one LOG_EMERG, LOG_ALERT, LOG_CRIT, LOG_ERR, LOG_WARNING, LOG_NOTICE, LOG_INFO, LOG_DEBUG.
StartEvent=CALL|Start|%{CallId}
CALL|Start|%{caller-ip}:%{caller-port}|%{callee-ip}:%{callee-port}|%{CallId}
Defines the event to display for a new call. The string is parametrized with the same variables as the other accounting modules (See [SQLAacct]).
StopEvent=CALL|Stop|%{CallId}
CALL|Stop|%{caller-ip}:%{caller-port}|%{callee-ip}:%{callee-port}|%{CallId}
Defines the event when a call is finished (disconnected). The syntax and parameters are the same as for StartEvent
. This event is equivalent to the old status port CDR event, but more flexible.
UpdateEvent=CALL|Update|%{CallId}
CALL|Update|%{caller-ip}:%{caller-port}|%{callee-ip}:%{callee-port}|%{CallId}
Defines event used to update the current call state. The syntax and parameters are the same as for StartEvent
.
ConnectEvent=CALL|Connect|%{CallId}
CALL|Connect|%{caller-ip}:%{caller-port}|%{callee-ip}:%{callee-port}|%{CallId}
Defines the event when a call is connected. The syntax and parameters are the same as for StartEvent
.
TimestampFormat=MySQL
N/A
Format of timestamp strings used in events. If this setting is not specified, a global one from the main gatekeeper section is used.