此篇將說明 Voicemail如何整合進資料庫,這個整合主要目的有兩項:
檢查需要的模組
root@pbx:/usr/src/asterisk $ asterisk -rx "module show like odbc" Module Description Use Count res_odbc.so ODBC resource 0 func_odbc.so ODBC lookups 0 cdr_odbc.so ODBC CDR Backend 0 res_config_odbc.so Realtime ODBC configuration 0 cdr_adaptive_odbc.so Adaptive ODBC CDR backend 0 5 modules loaded
如果缺少這些模組,必須重編安裝 Asterisk。
cd /usr/src cd asterisk ./configure make menuselect
Voicemail Build Options > [*] ODBC_STORAGE
Notes:
* 如果此項出現 XXXX,請確定 Linux 已經安裝 unixODBC-devel, libtool。
* 預設是 FILE_STORAGE,編譯時兩者只能選擇其一。
make clean make amportal stop make install amportal start
安裝 ODBC driver for MySQL
root@pbx:/usr/src/asterisk $ rpm -q mysql-connector-odbc mysql-connector-odbc-3.51.26r1127-1.el5
編輯 /etc/odbcinst.ini
# Example driver definitinions # # # # Included in the unixODBC package #[PostgreSQL] #Description = ODBC for PostgreSQL #Driver = /usr/lib/libodbcpsql.so #Setup = /usr/lib/libodbcpsqlS.so #FileUsage = 1 # # # Driver from the MyODBC package # Setup from the unixODBC package [MySQL] Description = ODBC for MySQL Driver = /usr/lib/libmyodbc.so Setup = /usr/lib/libodbcmyS.so FileUsage = 1
重要:在 CentOS 5.5,找不到檔案 /usr/lib/libmyodbc.so,但有 /usr/lib/libmyodbc3.so,所以必須修改如下:
# Driver from the MyODBC package # Setup from the unixODBC package [MySQL] Description = ODBC for MySQL Driver = /usr/lib/libmyodbc3.so <----- 改這裡 Setup = /usr/lib/libodbcmyS.so FileUsage = 1
選擇:如果有需要連接到 MS-SQL,可以再加上
[ms-sql] Description = TDS connection Driver = /usr/lib/libtdsodbc.so Setup = /usr/lib/libtdsS.so UsageCount = 1 FileUsage = 1
編輯 /etc/odbc.ini
[asterisk-connector] Driver = MySQL Database = asterisk_vm_recording Server = localhost Socket = /var/lib/mysql/mysql.sock User = db_user Password = db_pass
Notes:
* Driver 必須與 odbcinst.ini 內容相同。
* Database 要儲存錄音檔的資料庫名稱
驗證設定
isql -v asterisk-connector +---------------------------------------+ | Connected! | | | | sql-statement | | help [tablename] | | quit | | | +---------------------------------------+ SQL> show databases; +-----------------------------------------------------------------+ | Database | +-----------------------------------------------------------------+ | information_schema | | Hotel | | asterisk | | asterisk_vm_recording | | asteriskcdrdb | | mya2billing | | mysql | | test | | vtigercrm520 | | vtigercrm_evs | +-----------------------------------------------------------------+ SQLRowCount returns 10 10 rows fetched SQL> quit
編輯 /etc/asterisk/res_odbc.conf
[asterisk] enabled => yes dsn => asterisk-connector pre-connect => yes
Notes:
dsn 必須與 odbc.ini 內容相同
驗證設定
# amportal stop # amportal start # asterisk -rx "odbc show" ODBC DSN Settings ----------------- Name: asterisk DSN: asterisk-connector Pooled: No Connected: Yes
編輯 /etc/asterisk/vm_general.inc(如果是 vanilla asterisk,改成 voicemail.conf)
format=wav49 odbcstorage=asterisk odbctable=voicemessages
Notes:
odbcstorage 必須與 res_odbc.conf 內容相同。
選用:如果需要在 Dialplan 定義某個 SQL statement,例如:
SELECT ext from extensions WHERE extensionsID =3
編輯 /etc/asterisk/func_odbc.conf,加上這些
[MY-EXT-ID] dsn=asterisk-connector readsql=SELECT ext from extensions WHERE extensionsID =3
在編寫 Dialplan 時可以加上 ${ODBC_MY-EXT-ID()} 用來取出指定的資料庫資料,範例:
[ODBC-test] exten => s,1,wait(5) exten => s,n,saydigits(${ODBC_MY-EXT-ID()}) exten => s,n,Dial(SIP/${ODBC_MY-EXT-ID()}) exten => s,n,Voicemail(${ODBC_MY-EXT-ID()}) exten => s,n,hangup
Tips:
* ODBC 抓取資料庫在 dialplan 的用法是 ${ODBC_YOUR-STRING()}。
建立資料庫 asterisk_vm_recording
mysql>create database asterisk_vm_recording; mysql>exit
新增資料庫匯入檔 db-schema.sql:
CREATE TABLE `voicemessages` ( `id` int(11) NOT NULL auto_increment, `msgnum` int(11) NOT NULL default '0', `dir` varchar(80) default '', `context` varchar(80) default '', `macrocontext` varchar(80) default '', `callerid` varchar(40) default '', `origtime` varchar(40) default '', `duration` varchar(20) default '', `mailboxuser` varchar(80) default '', `mailboxcontext` varchar(80) default '', `recording` longblob, `flag` varchar(128) default '', PRIMARY KEY (`id`), KEY `dir` (`dir`) ) ENGINE=InnoDB;
匯入資料庫
mysql -uroot -p asterisk_vm_recording < db-schema.sql
到這裡已經完成了將 Voicemail 錄音檔儲存至資料庫的設定,不過 Voicemail 的設定,例如信箱密碼,留言的通知信箱等等仍維持使用 voicemail.conf 的檔案來管理,如果要將此改成資料庫形式來管理,繼續下面的步驟。
選用:附檔區有一個 php 檔,可以將轉換前的語音留言 WAV 檔匯入資料庫。
編輯 /etc/asterisk/res_mysql.conf,增加一個段落。
或者不想新增資料庫,也能使用內建的 [general]。
... ; for Voicemail Realtime Mode [asterisk_vm_conn] dbhost = 127.0.0.1 dbname = asterisk_vm dbuser = db_user dbpass = db_pass dbport = 3306 dbsock = /var/lib/mysql/mysql.sock
編輯 /etc/asterisk/extconfig.conf
; This is used for Voicemail Realtime Mode voicemail => mysql,asterisk_vm_conn,voicemail_users
Tips:
mysql : driver name
asterisk_vm: 必須與 res_mysql.conf 內容相同
voicemail_users: table name
建立資料庫 asterisk_vm