Mar
15
2009
2

Errors loading Asterisk addons, CDR(Call Detail Records) to MySQL

The other day I was doing an Asterisk 1.2 –> 1.4 upgrade.  I have a MySQL database that Asterisk records the Call Detail Record’s(CDR) too.  I deleted the asterisk 1.2 modules, then compiled/installed asterisk 1.4 & asterisk-addons 1.4.  Being that I hadn’t set up the CDR MySQL stuff in a while I loaded the res_mysql.conf, but I copied it from the cdr_addon.conf file by accident.  Because the two files have similer syntax It took me a while to figure this one out.  I checked all the passwords and I even checked the Asterisk CLI to see if the module loaded.  MySQL was populated with the same tables as before.  I also kept seeing this error (see below).

Possibly a mixed up addon file.

Possibly a mixed up addon file.

The error:

[Mar 15 03:25:44] ERROR[23793]: res_config_mysql.c:629 mysql_reconnect: MySQL RealTime: Failed to connect database server asterisk on  (err 2002). Check debug for more info.

The res_mysql & cdr_mysql have very similer config files, but you can’t ‘cut & paste’ between them.

Sample configuration for res_mysql.conf:

;
[general]
;dbhost = 127.0.0.1
;dbname = asterisk
;dbuser = myuser
;dbpass = mypass
;dbport = 3306
;dbsock = /tmp/mysql.sock

; Sample configuration for cdr_mysql.conf:

[global]
;hostname=database.host.name
;dbname=asteriskcdrdb
;table=cdr
;password=password
;user=asteriskcdruser
;port=3306
;sock=/tmp/mysql.sock
;userfield=1

Be careful not to mix the two between upgrades!

Mar
06
2009
0

Asterisk Voicemail to Email solved with Postfix

A while back I wrote an article for asteriskvoipnews.com about routing loops occurring from misconfigured DNS(or lack there of). My article was about routing loops caused by Asterisk attempting to send mail outside the network when the mail server destination is internal. To correct this issue the Asterisk PBX needs to define a ‘mail relay'(mail relay) on the internal network. This post will discuss using Postfix as an alternative to Sendmail for this purpose.

The goals of this post:

– explain Asterisk voicemail to email routing loops

– LAB: Install Postfix and configure ‘smarthost’ for mail relay

(more…)

Mar
03
2009
0

Mediatrix SIP/PRI Gateway Syslog Server Setup

Recently I was requested to set up syslog service between a Mediatrix PRI to SIP gateway.  The Mediatrix web GUI allows you to send logs to a syslog server; in this case an Asterisk PBX.  Asterisk logs just fine to local facility0 by the way.

I enabled the service and set syslog to accept remote connections.  Yet, I got nothing.  I called a support rep for a vendor that sells these things and he told me that by default Mediatrix logs to local facility7.  So I edited the syslog.conf with the IP Address of the Mediatrix and it worked!  syslog and rsyslog config files should work the same.  I hope this helps.

/etc/rsyslog.conf

# Log cron stuff
cron.*                                                  /var/log/cron
# Everybody gets emergency messages
*.emerg                                                 *
# Save news errors of level crit and higher in a special file.
uucp,news.crit                                          /var/log/spooler
# Save boot messages also to boot.log
#local7.*                                                /var/log/boot.log
#mediatrix IP ADDRESS
local7.*                                            /var/log/mediatrix.log
#
#
#
#
local0.*                        /var/log/asterisk.log

Remember a couple things – rsyslog is a newer version of syslog.  So you might have a ‘rsyslog.conf’ or a ‘syslog.conf’.  Another thing often overlooked is enabling TCP/UDP port 514 and their respective modules.  By default remote logging is disabled in Fedora Distros, and likely others for good reason.

/etc/rsyslog.conf

#### MODULES ####



$ModLoad imuxsock.so    # provides support for local system logging (e.g. via logger command)
$ModLoad imklog.so      # provides kernel logging support (previously done by rklogd)
$ModLoad immark.so      # provides –MARK– message capability



# Provides UDP syslog reception
$ModLoad imudp.so
$UDPServerRun 514



# Provides TCP syslog reception
$ModLoad imtcp.so
InputTCPServerRun 514

In conclusion…  Syslog servers are absolutely nesasarry to get Mediatrix SIP/PRI gateways operational with the carrier.  They are a solid appliance, but difficult to configure because of all the options.  Good luck.

Jan
23
2009
2

Asterisk Troubleshooting and Using nmap to determine port status of SIP and IAX2

nmap is a commonly used tool distributed with Linux (and available for many OSes) for mapping networks and port scanning.  Since almost every networked application runs on TCP/IP it is crucial to have the ability to troubleshoot every layer of the stack(OSI model).  A misconfigured firewall can easily cause hours of frustration.

We will use Asterisk as an example but the following tutorial could easily be applied to any network application.  If you run Asterisk PBX systems across many networks you have probably encountered firewalls.  Errant firewalls can cause huge headaches.  In some cases you may question if access to SIP & IAX2 ports on the firewall are being blocked.

Conventional wisdom:

[matt@mattcom1 ~]$ telnet localhost 22
Trying 127.0.0.1…
Connected to localhost.
Escape character is ‘^]’.
SSH-2.0-OpenSSH_5.1

Using Telnet to verify that a port is listening for incoming connections is great for a host of common TCP applications like smtp(25), http(80) or FTP(21).  But for large scale port mapping and network scanning you may need a beefier tool.  In comes nmap.

Lets start with some nmap basics then run through the IAX2/SIP scenario. Below is nmap with the ‘-O’ switch and my local subnet at home.  The ‘-O’ switch will set nmap to determine remote host Operating System.  192.168.1.0 means network (range) and ‘/24’ tells us that it is a 24 bit subnet mask or ‘255.255.255.0’.

[root@mattcom1 ~]# nmap -O 192.168.1.0/24


Starting Nmap 4.68 ( http://nmap.org ) at 2009-01-23 16:31 PST
Interesting ports on 192.168.1.1:
Not shown: 1714 closed ports
PORT   STATE SERVICE
80/tcp open  http
MAC Address: 00:0F:66:CA:B7:B7 (Cisco-Linksys)
No exact OS matches for host (If you know what OS is running on it, see http://nmap.org/submit/ ).
TCP/IP fingerprint:
OS:SCAN(V=4.68%D=1/23%OT=80%CT=1%CU=39191%PV=Y%DS=1%G=Y%M=000F66%TM=497A617
OS:A%P=i386-redhat-linux-gnu)SEQ(SP=0%GCD=64%ISR=50%TI=I%II=I%SS=S%TS=U)SEQ
OS:(SP=A%GCD=A%ISR=50%TI=I%II=I%SS=S%TS=U)OPS(O1=M5B4%O2=M5B4%O3=M5B4%O4=M5
OS:B4%O5=M5B4%O6=M5B4)WIN(W1=16D0%W2=16D0%W3=16D0%W4=16D0%W5=16D0%W6=16D0)E
OS:CN(R=Y%DF=N%T=96%W=3%O=%CC=N%Q=U)T1(R=Y%DF=N%T=96%S=O%A=S+%F=AS%RD=0%Q=)
OS:T2(R=Y%DF=N%T=96%W=80%S=Z%A=S%F=AR%O=%RD=0%Q=)T3(R=Y%DF=N%T=96%W=100%S=Z
OS:%A=S+%F=AR%O=%RD=0%Q=)T4(R=Y%DF=N%T=96%W=400%S=A%A=S%F=AR%O=%RD=0%Q=)T5(
OS:R=Y%DF=N%T=96%W=7A69%S=Z%A=S+%F=AR%O=%RD=0%Q=)T6(R=Y%DF=N%T=96%W=8000%S=
OS:A%A=S%F=AR%O=%RD=0%Q=)T7(R=Y%DF=N%T=96%W=FFFF%S=Z%A=S+%F=AR%O=%RD=0%Q=)U
OS:1(R=Y%DF=N%T=96%TOS=0%IPL=38%UN=0%RIPL=G%RID=G%RIPCK=G%RUCK=G%RUL=G%RUD=
OS:G)IE(R=Y%DFI=N%T=96%TOSI=Z%CD=S%SI=S%DLI=S)


Network Distance: 1 hop


Interesting ports on 192.168.1.2:
Not shown: 1714 closed ports
PORT   STATE SERVICE
80/tcp open  http
MAC Address: 00:90:4C:91:00:01 (Epigram)
Device type: general purpose
Running: Linux 2.4.X
OS details: Linux 2.4.18 – 2.4.32 (likely embedded)
Uptime: 0.115 days (since Fri Jan 23 13:45:46 2009)
Network Distance: 1 hop


All 1715 scanned ports on 192.168.1.105 are filtered
MAC Address: 00:1E:8C:B4:17:D8 (Asustek Computer)
Too many fingerprints match this host to give specific OS details
Network Distance: 1 hop


Interesting ports on 192.168.1.108:
Not shown: 1711 closed ports
PORT     STATE SERVICE
135/tcp  open  msrpc
139/tcp  open  netbios-ssn
445/tcp  open  microsoft-ds
3389/tcp open  ms-term-serv
MAC Address: 00:1C:C4:2E:7F:33 (Hewlett Packard)
Device type: general purpose
Running: Microsoft Windows Vista
OS details: Microsoft Windows Vista
Uptime: 0.055 days (since Fri Jan 23 15:12:49 2009)
Network Distance: 1 hop


Interesting ports on 192.168.1.254:
Not shown: 1709 closed ports
PORT     STATE SERVICE
22/tcp   open  ssh
111/tcp  open  rpcbind
139/tcp  open  netbios-ssn
445/tcp  open  microsoft-ds
2000/tcp open  callbook
6000/tcp open  X11
Device type: general purpose
Running: Linux 2.6.X
OS details: Linux 2.6.17 – 2.6.24
Uptime: 0.207 days (since Fri Jan 23 11:34:02 2009)
Network Distance: 0 hops


OS detection performed. Please report any incorrect results at http://nmap.org/submit/ .
Nmap done: 256 IP addresses (5 hosts up) scanned in 32.049 seconds


Okay so if you look at my local Asterisk server(192.168.1.254) you will notice that many ports are open but none of them are SIP(5060)or IAX2(4569).  Why is that?  Below the ‘-sT’ switch means SYN scan of TCP ports.

[root@mattcom1 ~]# nmap -sT 192.168.1.254


Starting Nmap 4.68 ( http://nmap.org ) at 2009-01-23 17:37 PST
Interesting ports on 192.168.1.254:
Not shown: 1709 closed ports
PORT     STATE SERVICE
22/tcp   open  ssh
111/tcp  open  rpcbind
139/tcp  open  netbios-ssn
445/tcp  open  microsoft-ds
2000/tcp open  callbook
6000/tcp open  X11

Even though Asterisk is up with a Polycom Soundpoint IP attached no SIP port appears open.  The mystery is solved if we take a close look at how a SIP calls are initiated.  SIP calls are initiated on UDP port 5060.  After the initial handshake the client opens up a series of RTP streams for audio, video, or whatever media is being relayed through SIP.  If we change the flags on the nmap tool we can see if the port is open.

[root@mattcom1 ~]# nmap -sU -p 5060 192.168.1.254


Starting Nmap 4.68 ( http://nmap.org ) at 2009-01-23 18:51 PST
Interesting ports on 192.168.1.254:
PORT     STATE         SERVICE
5060/udp open|filtered sip

We SYN scanned port UDP 5060 and the ‘STATE’ is ‘open|filtered’.  When asterisk is shut down… or the port is blocked, as we can see below…

[root@mattcom1 ~]# nmap -sU -p 5060 192.168.1.254


Starting Nmap 4.68 ( http://nmap.org ) at 2009-01-23 19:12 PST
Interesting ports on 192.168.1.254:
PORT     STATE  SERVICE
5060/udp closed sip


Nmap done: 1 IP address (1 host up) scanned in 0.114 seconds

The same is true for IAX2 as SIP.  When Asterisk is off the ‘STATE’ shows ‘closed’. One last note, the ‘open|filtered’ state could legitimately be filtered, but by checking when Asterisk(or whatever UDP service) is on and off you can tell for sure.  I got some great information at nmap.org, I encourage anyone interested to check it out.

Oct
15
2008
0

Simple Bash script that copy’s a directory of files and renames them with a Time Stamp

NOTE: I myself am a novice with BASH. I hate scripting, but hey, it’s necessary part of most sysadmin jobs. I came across several hurdles (like changing a name and adding a time stamp in the same loop). I hope this document helps. Please click on my adds, they help pay for the hosting. Thanks and enjoy.

-Matt

—————————————————————–

In this scenario I have a customer that I did a custom Asterisk(Open Source PBX) installation for.  They want the capability to backup all voicemails for management to review.  So naturally I made a cron job that copied Asterisk voicemails to a web directory that was htaccess protected.   It seemed to work except I forgot that asterisk copies messages in the format ‘msg001.wav’.

The problem is that if a user erases the messages in his/her mailbox, then the next new incoming voicemail is named ‘msg001’ again. Next, the voicemail gets copied to the web directory and overwrites the original ‘msg001’.  So my challenge is to create a cron job, that copies the new messages and then renames them on the fly with a new name and an appended time stamp.

Every minute the script copies Asterisk voicemail accounts to another arbitrary directory.   Two loops are run on the contents of that directory matching the pattern ‘5???/mess*'(or in Asterisk syntax 5XXX/mess.).  In the case of my customer their VM boxes are all 5XXX(5001,5002,etc..).  The first loops adds a time stamp from when the voicemail was originally created.  The second loop strips ‘message??’ and replaces it with ‘voicemail_’. The result being something like: ‘voicemail_2008-09-15-03:14:09.wav’. I have to change the messages part because if I dont the first loop will add a second time stamp to previously stamped files.

At the end of the script we want to delete the message00?.txt file, because it is not relevent to simply downloading voicemail and may confuse some users. Also we have to change the owner/group to apache so the web server has permission to host the files.

The voicemail are protected with ‘.htaccess’ file, but with some additional work we could make user access based on PAM, LDAP, or MySQL.

Avaya sells voicemail auditing servers for $40,000 per server. But with the Open Source Asterisk PBX and a simple BASH script we can create a comparable system for under $1,000. However this script can be re-purposed for copying and renaming files for any task. Take care.

-Matt

script:

#!/bin/bash



#set -x



# Variable containing array
#==========================================================================



DIRECTORY1=”/var/spool/asterisk/voicemail/default/????”
DIRECTORY2=”/var/www/html/voicemail/”
AUDIT=”/var/www/html/voicemail/????/INBOX/msg*.wav”
MSGFILES=”/var/www/html/voicemail/????/INBOX/msg????.txt”



# copy files to web directory
cp -ruvp $DIRECTORY1 $DIRECTORY2



#rename those files with a time stamp
for i in $AUDIT ;



do mv $i $i$(date -r $i +%F-%T).wav ;



done



#——————————————————



#strip the ‘messages’ part of the name and replace w/ ‘voicemail’
for i in $AUDIT ;



do mv “$i” “${i/msg????.wav/voicemail_}” ;



done



# remove any msg????.txt files



rm -rf $MSGFILES



chown -R apache $DIRECTORY2
chgrp -R apache $DIRECTORY2

With Apache, Asterisk and this simple BASH script we have just created a web accessible way to check and back up voicemail!