Asterisk call log records

最後更新: 2015-07-23

 

目錄

基本設定

cdr.conf
 - Setting
 - Disable CSV
 - cvs log example

cdr_mysql.conf

cdr_adaptive_odbc.conf

設定檔

Default: /var/log/asterisk/cdr.conf

Default: /var/log/asterisk/cdr-csv

查看 load 了什麼 modules

module show like cdr_

    cdr_sqlite.so                      # without a way to rotate it
    cdr_csv.so                         # in comma-separated text files
    cdr_syslog.so

自動載入要的 module

/etc/asterisk/modules.conf

[modules]
autoload=yes

preload => res_odbc.so
noload => pbx_gtkconsole.so

load => cdr_csv.so

 


查看設定

 

server*CLI> cdr show status

Call Detail Record (CDR) settings
----------------------------------
  Logging:                    Enabled
  Mode:                       Simple
  Log unanswered calls:       No

* Registered Backends
  -------------------
    radius
    csv
    cdr-custom
    Adaptive ODBC
    res_config_sqlite

 


cdr.conf

 

Setting

/etc/asterisk/cdr.conf

[general]

enable=yes

; if you try to dial 3 extensions, you will get 3 CDR
; Calls which get offered to an outgoing line, but are unanswered, are still logged
unanswered = yes


; report each call that fails to complete due to congestion conditions.
congestion = yes


; Default is "no"
usegmtime = yes

cvs log example

"","201","221","DLPN_all_user","""ivan"" <201>","SIP/201-00000011","SIP/221-00000012","Dial","SIP/221","2013-10-25 08:12:16","2013-10-25 08:12:36","2013-10-25 08:13:28",72,52,"ANSWERED","DOCUMENTATION","1382688736.154",""
"","201","221","DLPN_all_user","""ivan"" <201>","SIP/201-00000013","SIP/221-00000014","Dial","SIP/221","2013-10-25 08:19:56","2013-10-25 08:20:11","2013-10-25 08:21:31",95,80,"ANSWERED","DOCUMENTATION","1382689196.198",""

意思:

accountcode: ""

src: "201"
dst: "221"

dst: "DLPN_all_user"

clid: """ivan"" <201>"

channel: "SIP/201-00000011"
dstchannel: "SIP/221-00000012"

lastapp: "Dial"
lastdata: "SIP/221"

start: "2013-10-25 08:12:16"
answer: "2013-10-25 08:12:36"
end: "2013-10-25 08:12:36"
duration(seconds): 72
billsec: 52
disposition(ANSWERED, NO ANSWER, BUSY, FAILED): ANSWERED
amaflags(DOCUMENTATION, BILL, IGNORE etc): DOCUMENTATION

* End Call 時才寫 log

Disable CSV

;[csv]
;usegmtime=yes    ; log date/time in GMT.  Default is "no"
;loguniqueid=yes  ; log uniqueid.  Default is "no"
;loguserfield=yes ; log user field.  Default is "no"
;accountlogs=yes  ; create separate log file for each account code. Default is "yes"

 


cdr_mysql.conf (已被廢棄的 )

 

/etc/asterisk/cdr_mysql.conf

[global]
hostname=localhost
dbname=asterisk
table=cdr
password=asterisk
user=asterisk
sock=/var/run/mysqld/mysqld.sock
timezone=UTC

charset=utf-8

[columns]
;static "<value>" => <column>
;alias <cdrvar> => <column>
alias start => calldate
;alias clid => <a_field_not_named_clid>
;alias src => <a_field_not_named_src>
;alias dst => <a_field_not_named_dst>
;alias dcontext => <a_field_not_named_dcontext>
;alias channel => <a_field_not_named_channel>
;alias dstchannel => <a_field_not_named_dstchannel>
;alias lastapp => <a_field_not_named_lastapp>
;alias lastdata => <a_field_not_named_lastdata>
;alias duration => <a_field_not_named_duration>
;alias billsec => <a_field_not_named_billsec>
;alias disposition => <a_field_not_named_disposition>
;alias amaflags => <a_field_not_named_amaflags>
;alias accountcode => <a_field_not_named_accountcode>
;alias userfield => <a_field_not_named_userfield>
;alias uniqueid => <a_field_not_named_uniqueid>

asterisk cdr mysql

 

Setting

;hostname=database.host.name
;dbname=asteriskcdrdb
;table=cdr
;password=password
;user=asteriskcdruser
;port=3306
;sock=/tmp/mysql.sock
;timezone=UTC

charset=koi8r

[columns]
;alias src => <a_field_not_named_src>
;alias dst => <a_field_not_named_dst>

DB schema

CREATE TABLE cdr (
        calldate datetime NOT NULL default '0000-00-00 00:00:00',
        clid varchar(80) NOT NULL default '',
        src varchar(80) NOT NULL default '',
        dst varchar(80) NOT NULL default '',
        dcontext varchar(80) NOT NULL default '',
        channel varchar(80) NOT NULL default '',
        dstchannel varchar(80) NOT NULL default '',
        lastapp varchar(80) NOT NULL default '',
        lastdata varchar(80) NOT NULL default '',
        duration int(11) NOT NULL default '0',
        billsec int(11) NOT NULL default '0',
        disposition varchar(45) NOT NULL default '',
        amaflags int(11) NOT NULL default '0',
        accountcode varchar(20) NOT NULL default '',
        uniqueid varchar(32) NOT NULL default '',
        userfield varchar(255) NOT NULL default ''
);

 


cdr_adaptive_odbc.conf

 

* This module allows you to choose which columns of data built into Asterisk are stored in your table,
* permits you to add additional columns that you can populate with the CDR() dialplan function.
* You can even store different parts of CDR data to different tables and databases, if that is required.

CDR Contents

src
dst
channel
dstchannel
start
answer
end
duration
billsec              # seconds between the answer and end
disposition          # NO ANSWER, FAILED, BUSY, ANSWERED, or UNKNOWN.
uniqueid             # The unique ID for the src channel.

 

update column "route_rate" on mysql

exten => _NXXNXXXXXX,1,Verbose(1,Example of adaptive ODBC usage)
   same => n,Set(CDR(route_rate)=0.01)
   same => n,Dial(SIP/my_itsp/${EXTEN})
   same => n,Hangup()

+--------------+----------+---------+------------+
| src          | duration | billsec | route_rate |
+--------------+----------+---------+------------+
| 0000FFFF0008 | 37       | 30      | 0.01       |
+--------------+----------+---------+------------+

ALTER TABLE

每次

sql> ALTER TABLE cdr ADD COLUMN route_rate varchar(10);

後都要

*CLI> module reload cdr_adaptive_odbc.so

Configure

; cdr_adaptive_odbc.conf
[adaptive_connection]
connection=asterisk
table=cdr
;usegmtime=yes ; defaults to no
alias start=calldate
;alias src => source
;alias channel => source_channel
;alias dst => dest
;alias dstchannel => dest_channel

Checking

 

cdr show active

# 在 call 中

Channels with Call Detail Record (CDR) Information
--------------------------------------------------
Channel                   Dst. Channel              LastApp         Start    Answer   End      Billsec  Duration
PJSIP/507-00000002        PJSIP/mytrunk_endpoint-00 Dial            13:04:05          13:04:16 00000000 00000011
PJSIP/mytrunk_endpoint-00 <none>                    AppDial         13:04:05          13:04:16 00000000 00000010

# 接聽了

Channels with Call Detail Record (CDR) Information
--------------------------------------------------
Channel                   Dst. Channel              LastApp         Start    Answer   End      Billsec  Duration
PJSIP/507-00000002        PJSIP/mytrunk_endpoint-00 Dial            13:04:05 13:04:29 13:04:31 00000001 00000026

 

 

Creative Commons license icon Creative Commons license icon