If you’ve ever used the MySQL module with Asterisk, you’ve probably had loads of fun formatting queries.

This query:

SELECT * FROM accounts WHERE extension = '${EXTEN}'
AND enabled = 'Y' AND balance > 0.00 LIMIT 1;

Becomes:

SELECT\ *\ FROM\ accounts\ WHERE\ extension\ =\ \'${EXTEN}\'\
AND\ enabled\ =\ \'Y\'\ AND\ balance\ >\ 0.00\ LIMIT\ 1;

That probably doesn’t seem too difficult, but if you have huge queries, it’s really easy to miss a character that needs to be escaped. Needless to say, if you put code like that into production, your PBX is going to die when the dialplan hits that code.

I finally threw together a script to do this automatically.

Now, I can run:

asterisk-format-query <<'QUERY'
SELECT * FROM accounts WHERE extension = '${EXTEN}'
AND enabled = 'Y' AND balance > 0.00 LIMIT 1;
QUERY

NOTE: Above, I used a quoted heredoc. This prevents your shell from trying to interpolate things like ${EXTEN}.

I’ve been playing around with the Asterisk Manager lately (which is pretty damn cool, if you ask me).

There doesn’t seem to be a list of all the commands available on voip-info right now, so I’m posting these here for my own reference.

These are the Manager commands available on Asterisk 1.4

AbsoluteTimeout: Set Absolute Timeout (Priv: call,all)
AgentCallbackLogin: Sets an agent as logged in by callback (Priv: agent,all)
AgentLogoff: Sets an agent as no longer logged in (Priv: agent,all)
Agents: Lists agents and their status (Priv: agent,all)
ChangeMonitor: Change monitoring filename of a channel (Priv: call,all)
Command: Execute Asterisk CLI Command (Priv: command,all)
DBGet: Get DB Entry (Priv: system,all)
DBPut: Put DB Entry (Priv: system,all)
Events: Control Event Flow (Priv: <none>)
ExtensionState: Check Extension Status (Priv: call,all)
Getvar: Gets a Channel Variable (Priv: call,all)
Hangup: Hangup Channel (Priv: call,all)
ListCommands: List available manager commands (Priv: <none>)
Logoff: Logoff Manager (Priv: <none>)
MailboxCount: Check Mailbox Message Count (Priv: call,all)
MailboxStatus: Check Mailbox (Priv: call,all)
MeetmeMute: Mute a Meetme user (Priv: call,all)
MeetmeUnmute: Unmute a Meetme user (Priv: call,all)
Monitor: Monitor a channel (Priv: call,all)
Originate: Originate Call (Priv: call,all)
Park: Park a channel (Priv: call,all)
ParkedCalls: List parked calls (Priv: <none>)
PauseMonitor: Pause monitoring of a channel (Priv: call,all)
Ping: Keepalive command (Priv: <none>)
PlayDTMF: Play DTMF signal on a specific channel. (Priv: call,all)
QueueAdd: Add interface to queue. (Priv: agent,all)
QueuePause: Makes a queue member temporarily unavailable (Priv: agent,all)
QueueRemove: Remove interface from queue. (Priv: agent,all)
Queues: Queues (Priv: <none>)
QueueStatus: Queue Status (Priv: <none>)
Redirect: Redirect (transfer) a call (Priv: call,all)
SetCDRUserField: Set the CDR UserField (Priv: call,all)
Setvar: Set Channel Variable (Priv: call,all)
SIPpeers: List SIP peers (text format) (Priv: system,all)
SIPshowpeer: Show SIP peer (text format) (Priv: system,all)
Status: Lists channel status (Priv: call,all)
StopMonitor: Stop monitoring a channel (Priv: call,all)
UnpauseMonitor: Unpause monitoring of a channel (Priv: call,all)
UserEvent: Send an arbitrary event (Priv: user,all)
WaitEvent: Wait for an event to occur (Priv: <none>)

I know I’ve blogged this before, but these are the steps I took most recently to get Asterisk running on a fresh Ubuntu Server (Dapper) installation. The instructions will also work on Feisty or Gutsy server.

# apt-get install linux-headers-`uname -r` build-essential libssl-dev libncurses5-dev libspeex-dev sox sox-dev
# mkdir /usr/src/asterisk
# cd /usr/src/asterisk
# wget http://downloads.digium.com/pub/asterisk/releases/asterisk-1.4.18.tar.gz
# wget http://downloads.digium.com/pub/zaptel/zaptel-1.4.9.2.tar.gz
# tar -vzxf zaptel-1.4.9.2.tar.gz
# cd zaptel-1.4.9.2.tar.gz
# ./configure
# make
# make install
# make config
# cd ..
# tar -vzxf asterisk-1.4.18.tar.gz
# cd asterisk-1.4.18
# ./configure
# make
# make install
# asterisk
# asterisk -r

If all goes well, you should see the Asterisk console.

Note: I am not 100% sure which repos have the packages mentioned, but I had the universe and multiverse repos added so my sources.list for apt.

It took forever, but this ended up working to get Asterisk to compile:

apt-get install libssl-dev libncurses5-dev libspeex-dev sox sox-dev \
  build-essential manpages-dev libasound2-dev ssh \
  linux-headers-2.6.15-23-server

Fuck Fedora.

I’m having trouble getting the required MySQL Perl mods installed so I can use MySQL with Asterisk… but I guess I’ll figure it out sooner or later.