app_dbodbc
This is original Brian’s re-implementation of the Asterisk database using unixODBC.
This allows for easy creation of dialplan modifiers that link into a GUI with a back-end database.
Install
rpm -ivh unixODBC*rpm
rpm -ivh MyODBC*rpm
cp app_dbodbc.c /usr/src/asterisk/apps/
vi /usr/src/asterisk/apps/Makefile +28
add in the end of line: app_dbodbc.so
vi /usr/src/asterisk/apps/Makefile +110
app_dbodbc.so: app_dbodbc.o
$(CC) $(SOLINK) -o $@ ${CYGSOLINK} $< ${CYGSOLIB} -lodbc
cd /usr/src/asterisk
make
make install
Configure
This assumes using MySQL database on RedHat – will vary for other DBs & slightly for other OS’s.
Configure MySQL:
- Add a database called ‘asterisk’
- Create a user with full read/write access to this database
- Add a table within this database called ‘astdb’
- Add 3 fields to the structure of this table: ‘astfamily’, ‘astkey’ & ‘astvalue’
vi /etc/odbcinst.ini
[MySQL]
Description = ODBC for MySQL
Driver = /usr/lib/libmyodbc.so
Setup = /usr/lib/libodbcmyS.so
FileUsage = 1
vi /etc/odbc.ini
[MySQL-asterisk]
Description = MySQL Asterisk database
Trace = Off
TraceFile = stderr
Driver = MySQL
SERVER = localhost
USER =
PASSWORD =
PORT = 3306
DATABASE = asterisk
Test ODBC:
isql -v MySQL-asterisk myusername mypassword
vi /etc/asterisk/odbc.conf
[global]
dsn=MySQL-asterisk
username=myusername
password=mypassword
Usage
- ODBCget(varname=family/key):
Retrieves a value from the Asterisk database and stores it in the given variable. Always returns 0. If the requested key is not found, jumps to priority n+101 if available.
- ODBCput(family/key=value):
Stores the given value in the Asterisk database. Always returns 0.
- ODBCdel(family/key):
Deletes a key from the Asterisk database. Always returns 0.
- ODBCdeltree(family[/keytree]):
Deletes a family or keytree from the Asterisk database. Always returns 0.
and if you use the extented version:
- ODBCLookupCIDName:
Looks up Caller*ID number on the the active channel in the ODBC database (family ‘cidname’) and sets the Caller*ID name. Does nothing if no Caller*ID was received on the channel. This is useful if you do not subscribe to Caller*ID name delivery, or if you want to change the names on some incoming calls. Always returns 0.
- ODBCLookupBlacklist:
Looks up the Caller*ID number on the active channel in the ODBC database. If the number is found, and if there exists a priority n + 101, where ‘n’ is the priority of the current instance, then the channel will be setup to continue at that priority level. Otherwise, it returns 0. Does nothing if no Caller*ID was received on the channel. Example: database put blacklist name/number> 1
See also
- Asterisk database
- Asterisk configuration from database
- Asterisk GUI
- unixODBC
- Asterisk cdr odbc – has some general info on configuring unixODBC
- Asterisk | FAQ | Tips & Tricks