Saturday, July 24, 2010

trixbox as voicemail system on cisco call manager

Recently I had a customer asked how to connect a trixbox to cisco call manager for use as a voicemail system.  It's actually not too hard to achieve, although it does require some manual customizations.  Here only the trixbox side will be covered, as far as I am aware, all the you need to do on the cisco side is to add a voicemail "pilot" number and the IP address of our trixbox, in our case we will be using 6199.   This setup does have some security concerns as there are no logins.  With that said as long as you don't have any outbound routes setup then they can't make any calls, but they could potentially access the voicemail.
Ok lets get down to the setup.  Login to the admin area of your trixbox webpanel.
What we need to do is create a custom context for the handling of the calls.  to do this we goto pbx->config file editor.   Then select extensions_custom.conf on the left hand side in that file we are going to create our custom context for handling calls.
[cisco-voicemail]
exten => _6199,1,Set(DEST=${CALLERID(number)})
exten => _6199,n,Macro(exten-vm,${DEST},${DEST})

the _6199 means 6199 is the number dialed. Then in the first line I get the callerid number and create a variable called DEST.  Then I use a predefined macro to call the voicemail in line 2

Ok... So that seems straight forward enough, but you need to create all the extensions in such a way so that they go into this context and goto the voicemail.

To do that you create a basic sip extension by putting the extension number in and then just put the voicemail information in.  Save it.  You will probably get an error about not having a sip password, just accept that.  Then you need to click on the extension you have just created to edit it.  The parts you need to change are this:

context = cisco-voicemail
qualify = no

From there you should be able to use the voicemail :)

that's great, but what about MWI ( Message Waiting Indicator ).  So in order to get that going we need to do a little more configuration.  That configuration is a custom notification command to the phone using the SIP notify.  below is the script I have used, it has some very basic parts and doesn't give a total of the old messages, as the cisco handsets didn't have the ability to display that information, so I removed a whole bunch of code from the original script and modified it slightly to make it fast and simple.  Below is the script, but in order to make that script work you need to tell asterisk to use it.  in voicemail.conf

externnotify = /var/lib/asterisk/script/notify-sip.sh

Here is the actual script used, if you are to use it all that will be require to change are the SIP_SERVER and the DOMAIN
#!/bin/bash
 
# This script send the SIP NOTIFY message to UA. The NOTIFY message
# can either enable or disable the UA message indicator. The script
# looks for any file in $VM_HOME and creates the NOTIFY message
#
# The actual NOTIFY message is sent to the SIP proxy by the sipsak
# utilty.  This script can be called from Asterisk when a voice mail
# is left to notify immediately, and it can also be called from a cron
# job to send out message notifications to all users with voicemail
#
# Adapted from the script found on [Serusers] mailing list:
# http://lists.iptel.org/pipermail/serusers/2005-May/019684.html
# 
# Adaptations by Josh Mahonin (jmahonin@cbnco.com), with credit to the 
# original creator.

# If Asterisk called us, save its parameters
VM_CONTEXT=$1
EXTENSION=$2
VM_COUNT=$3


# Voice mail file type
VM_TYPE=wav

# SIP settings
SIP_SERVER=ASTERISK_IP
SIP_PORT=5060
SIP_FROM=voicemail
user=${EXTENSION}
DOMAIN=DESTINATION_IP


SEQUENCE=$( printf "%06d" $RANDOM )
if [ $VM_COUNT -gt 0 ]
then
 HAS_NEW="yes"
else
 HAS_NEW="no"
fi

NEW_MESSAGES=$VM_COUNT
OLD_MESSAGES=0
CONTENT_LENGTH=$(( 34 + ${#HAS_NEW} + ${#NEW_MESSAGES} + ${#OLD_MESSAGES} ))

(
        cat <<-EOM
NOTIFY sip:${user}@${DOMAIN} SIP/2.0
From: 
To: 
Contact: 
Call-ID: ${SEQUENCE}@${SIP_SERVER}
CSeq: ${SEQUENCE} NOTIFY
Event: message-summary
Content-Type: application/simple-message-summary
Content-Length: ${CONTENT_LENGTH}

Messages-Waiting: ${HAS_NEW}
Voicemail: ${NEW_MESSAGES}/${OLD_MESSAGES}
 
EOM
) > out.msg
cat out.msg | /usr/bin/sipsak -s sip:${user}@${DOMAIN} -f -

        if [ $? -ne 0 ] ; then
            logger -t notify-script "Error: sipsak was not successful sending to $user"
        fi
 
exit 0

Saturday, June 26, 2010

Montioring trixbox via snmp

One of the hard things when you have a system out there is how to make sure that you know when something goes wrong.  There are a number of ways this can be achieved, but Seeing that it's not likely to be the only system you need to monitor you will want to setup a monitoring server somewhere.  After much deliberation I decided to go with monitoring it via snmp because it's an general standard that works well for monitoring and most monitoring systems that use snmp collect some good data that I can use at a glance.  Personally I use opennms to monitor, but you probably already have your own, or else you wouldn't be here.
Let's get down to business, trixbox systems have the snmp support built in, they just need to be told how to do it.  To make sure that you have all the packages

yum -y install net-snmp net-snmp-devel net-snmp-utils bzip2-devel newt-devel lm_sensors-devel

Now that we have everything we need we just need to tell snmp how to get the info... The info I have is for snmp version 3,  which is the most secure.

echo "#trixbox user
rwuser trixboxsnmp priv
createUser trixboxsnmp SHA !ChangemE! AES" >> /etc/snmp/snmp.conf

This command adds the trixboxsnmp user to the snmp, don't forget to change the password.
Now we need to setup the snmp agent for asterisk:

echo "# trixbox configuration
master agentx
agentXSocket /var/agentx/master
agentXPerms 0660 0550 asterisk asterisk" >> /etc/snmp/snmpd.conf

Now we need to configure asterisk to use the snmp agent.  To do that we need to configure the asterisk file res_snmp.conf.  Below is the configuration you need in there, it's the whole file, so you can make sure that your file looks like this /etc/asterisk/res_snmp.conf

;
; Configuration file for res_snmp
;

[general]
; We run as a subagent per default -- to run as a full agent
; we must run as root (to be able to bind to port 161)
subagent = yes
; SNMP must be explicitly enabled to be active
enabled = yes


Now we are ready to go. all we have to do is restart asterisk and snmp

/etc/init.d/snmpd restart
/etc/init.d/snmptrapd restart
amportal restart


That is pretty much it, although there is a little permission issue with the agentx dir so we need to do the following so that asterisk can update the agent file, this is how to fix it and get it all

chmod 755 /var/agentx

Now we just need to setup our monitoring server to collect the data.  If you are using opennms, here is a link to get it going on there
http://www.opennms.org/blog/?p=227

Monday, March 29, 2010

Welcome to Open Source Your Life

Welcome to my new blog, Open Source Your Life.
As a small business owner working with OSS ( Open Source Software ) I work hard to find ways in which I can help the community understand the benefits of such technology and their uses, here you will find tidbits that I find interesting and tips/techniques that I have picked up along the way.  I hope that you find that this useful and share the information along the chain.

Enjoy
Tom