Sweethearts : Asterisk and ODBC
I love driving Asterisk with a database. It makes configuring Asterisk on the fly so much easier, and makes for easier development that interfaces with Asterisk in some form.
What is ODBC? ODBC is an Open Database Connector. When talking about ODBC, I’m talking about UnixODBC – obviously.
In lame men’s terms, ODBC is a connector that allows me to connect to many different database interfaces. It can be MYSQL, PostgreSQL, MSSQL, and so on. I configure my database types in one file, and configure the databases (with logins) in another file. Then I can much more easily connect to my database from my application.
So what does that mean to you? Maybe nothing. But for me, it’s awesome. Especially in terms of Asterisk. The Asterisk community understands the value of being able to interface with with the database. As mentioned above, I love it because I like to house my dialplans right within a database, so I can modify them without reloading Asterisk. This is especially important when the dialplan is several thousand lines long. Additional benefits include writing CDR data to databases (perhaps ones that aren’t natively supported by Asterisk – now you can with ODBC.)
So how do you install ODBC and get it working with Asterisk? That’s the easy part.
I’m going to assume that you are running Asterisk on CentOS. If not, you’re on your own. CentOS is preferred.
To Install:
yum install unixODBC unixODBC-devel
Easy enough huh? Okay, let’s configure it. Start by editing /etc/odbcinst.ini
If you plan on using PostgreSQL it should be ready to go. You might have to adjust the socket path, depending on your system. For MySQL, using the following:
[MySQL]
Description = ODBC for MySQL
Driver = /usr/lib/libmyodbc3.so
Setup = /usr/lib/libodbcmyS.so
FileUsage = 1
Again, you may have to adjust the Driver Path depending on your system. Now we just need to setup the database connections. Do this by editing /etc/odbc.ini
[asterisk]
Description = Asterisk realtime
Driver = MySQL
Socket = /var/lib/mysql/mysql.sock
Server = localhost
User = asterisk
Pass = yourpassword
Database = asterisk
Option = 3[crazyapp]
Description = My Crazy Apps database
Driver = MySQL
Socket = /var/lib/mysql/mysql.sock
Server = 192.168.15.166
User = databaseuser
Pass = yourpassword
Database = crazyappdatabase
Option = 3
Okay, you’re done! But wait! How do I use it with Asterisk? Oh yea, that part. Now we need to let Asterisk know that ODBC is available. If you have already compiled Asterisk, that’s not a problem. You will just have to recompile.
cd /usr/src/asterisk-1.6.2.7
./configure
make menuselect
make && make install
If I can stress anything at all, it’s to make sure that you re-run ./configure — this is what tells Asterisk ODBC is there. ‘make menuselect’ is another key part. Here’s where we select the functions and applications that would be using ODBC. A few off the top of my head:
‘cdr_odbc’
This one is for inputting CDR data into a database. If you were previously compiling Asterisk-Addons just to have CDR_MYSQL – no need now!
‘res_config_odbc’
This is for realtime over ODBC instead of MySQL. Again, if you were previously compiling Asterisk-Addons, no need now!
‘ODBC Storage’
This one is perfect. You can store voicemails in a database.
Okay, so we have recompiled Asterisk. Give Asterisk a quick restart. Now we can start using ODBC within Asterisk. I’ll be posting some more articles soon which will feature using ODBC for Asterisk Realtime, CDR, Voicemail Storage, and using it within the dialplan. So make sure you check back soon.
[...] we compile Asterisk, so that we can compile func_ODBC, res_ODBC and cdr_ODBC, etc. Check out a previous article here for how to setup [...]
[...] in my previous post, I wrote about how useful ODBC is to Asterisk and I showed how to install it. Now we will explore [...]