opensips 的ACC模块提供了类似CDR的功能,可以记录通话详单。但是,模块缺省记录的内容有限。我们可以看一下缺省建立的acc表结构:
name | type | size | default | null | key | extra attributes | description |
---|---|---|---|---|---|---|---|
id |
unsigned int |
10 |
default | no | primary | autoincrement | |
method |
string |
16 |
'' | no | |||
from_tag |
string |
64 |
'' | no | |||
to_tag |
string |
64 |
'' | no | |||
callid |
string |
64 |
'' | no | |||
sip_code |
string |
3 |
'' | no | |||
sip_reason |
string |
32 |
'' | no | |||
time |
datetime |
not specified |
default | no | |||
duration |
unsigned int |
11 |
0 | no | |||
ms_duration |
unsigned int |
11 |
0 | no | |||
setuptime |
unsigned int |
11 |
0 | no | |||
created |
datetime |
not specified |
NULL | yes |
这在计费应用中往往是不够的,比如,没有主被叫信息。
幸运的是,ACC模块提供了扩展功能。通过acc_extra伪变量,让我们可以记录可能的扩展信息,其信息源可以来自SIP信息,也可以来自其它模拟导入的伪变量。相当方便。
定义语法
指定扩展信息的实现是通过extra_field 实现的,它通过指定标签名进行赋值。这些信息的标签名,通过acc_extra伪变量定义。没有没有指定tag名,那么其值就会被视为log_value。
其语法定义格式如下:
backend : tag -> log_name (';'tag -> log_name)*
backend : tag (';' tag)*
其中backend指定扩展内容输出到何处,可选值有log, db, aaa, evi,其后跟着一个冒号,后面是tag列表。如果有个箭头,箭头前表示脚本中伪变量名,箭头后表示输出终端的字段名。
扩展字段的内容,在整个呼叫过程中始终可见。具体实例:
modparam("acc", "extra_fields", "log: a -> test_a")
modparam("acc", "extra_fields", "db: a -> test_a")
# for syslog-based accounting, use any text you want to be printed
# if setting $acc_extra(a) you will see "My_a_Field=<value> in logs
# if setting $acc_extra(b) you will see "b=<value> in logs
modparam("acc", "extra_fields", "log: a->My_a_Field; b")
# for mysql-based accounting, use the names of the columns
# $acc_extra(a) = <value> results in setting col_a with <value> in db
modparam("acc", "extra_fields", "db: a->col_a; col_b")
# for AAA-based accounting, use the names of the AAA AVPs
modparam("acc", "extra_fields","aaa:a->AAA_SRC;b->AAA_DST")
# evi definition example
modparam("acc", "extra_fields","a->2345;b->2346")