[Serusers] SER Message waiting indicator light Cisco 7940/7960
Java Rockx
javarockx at gmail.com
Tue Mar 1 16:19:41 CET 2005
Patrick,
This is a bash script that externnotify executes
#!/bin/ash
#
# This script is called by Asterisk every time a voice mail is
# left for a subscriber. The CONTEXT, EXTENSION, and VM_COUNT
# are passed by Asterisk.
#
# All we need to do is update a file in /var/spool/asterisk/mwi
# to tell our cron job that we have to send a SIP NOTIFY message
# to a particular UA
#
# This file is referenced in /etc/asterisk/voicemail.conf
#
# NOTE: The $2 argument is passed in to this script in the
# following form: MAILBOX at DOMAIN
#
# example: 4075551212 at default
#
MWI_DIR=/var/spool/asterisk/mwi/
if [ -n ${2} ] ; then
if /bin/touch ${MWI_DIR}/${2} ; then
exit 0
else
exit 1
fi
else
exit 2
fi
The following is executed in CRON every minute. This script actually
notifies the subscribers by sending NOTIFY messages to SER. Please
note that our asterisk is a modified version that stores mailboxes in
a directory hash, so you can modify this to fit your needs.
#!/bin/sh
# 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. After the message is send we delete the processed file
# from VM_HOME so we don't keep resending the same message. Most
# UAs will periodically send a SUBSCRIBE message to the SIP proxy.
# When this occurs the SIP proxy will place a file in the location
# /var/spool/mwi/delay and a less frequent CRON job will process it.
VM_ROOT=/var/spool/asterisk/voicemail
VM_HOME=/var/spool/asterisk/mwi
SIP_SERVER=71.110.20.33
SIP_PORT=5060
SIP_FROM=vmserver
SIP_PASSWORD=heslo
DB_NAME=ser
DB_SERVER=10.255.237.18
DB_OPTIONS="--skip-column-names --connect_timeout=3"
DB_USER=ser
DB_PASSWORD=heslo
# Allow glob expansions to return NULL
shopt -s nullglob
# Sanity check that VM_HOME exists, warn if it does not
if [ ! -d $VM_HOME ] ; then
echo "Cannot chdir to VM_HOME, exiting"
exit 1
fi
for file in $VM_HOME/*
do
file=$( basename $file @default )
# The file existance check may seem redundant, but it is
theoretically possible
# for this script to take longer than 1 cron cycle to run, or
for it to be run
# by hand while another copy is running, so we really do need
this check.
if [ -e ${VM_HOME}/${file}@default ] && [ ${#file} -eq 10 ]; then
QUERY="SELECT subscriber.domain FROM subscriber,
location WHERE subscriber.username='$file' AND subscriber.username =
location.username LIMIT 1"
DOMAIN=`mysql ${DB_OPTIONS} -h ${DB_SERVER}
-u${DB_USER} -p${DB_PASSWORD} -e "$QUERY" ${DB_NAME}`
# If the MySQL call fails, then $DOMAIN will hold the
error message instead
if [ $? -ne 0 ] ; then
echo "Error connecting to MySQL: $DOMAIN"
exit 2
fi
if [ -n "${DOMAIN}" ]; then
MAILBOX=$VM_ROOT/default/${file:0:3}/${file:3:3}/${file:6:4}
# Sanity check that INBOX exists, warn if it does not
if [ ! -d ${MAILBOX} ]; then
echo "${MAILBOX} does not exist"
continue
fi
# Delete all messages with a zero length. If
the subscriber still
# has voice mail files in their INBOX after
this step then notify
# them even if the total is zero, which will
extinguish their MWI
for message in ${MAILBOX}/INBOX/*.gsm
do
if [ ! -s $message ]; then
GSM=`basename $message .gsm`
rm -f ${MAILBOX}/INBOX/$GSM.*
fi
done
TOTAL_MESSAGES=0
NEW_MESSAGES=0
OLD_MESSAGES=0
if [ -d ${MAILBOX}/INBOX ]; then
tmp=( $( echo ${MAILBOX}/INBOX/*.txt ) )
NEW_MESSAGES=${#tmp[*]}
else
NEW_MESSAGES=0
fi
if [ -d ${MAILBOX}/Old ]; then
tmp=( $( echo ${MAILBOX}/Old/*.txt ) )
OLD_MESSAGES=${#tmp[*]}
else
OLD_MESSAGES=0
fi
TOTAL_MESSAGES=$(($NEW_MESSAGES + $OLD_MESSAGES))
if [ "$NEW_MESSAGES" == "0" ]; then
HAS_NEW="no"
else
HAS_NEW="yes"
fi
CONTENT_LENGTH=$(( 34 + ${#HAS_NEW} +
${#NEW_MESSAGES} + ${#OLD_MESSAGES} ))
SEQUENCE=$( printf "%06d" $RANDOM )
(
cat <<-EOM
NOTIFY sip:${file}@${DOMAIN} SIP/2.0
From: <sip:${SIP_FROM}@${DOMAIN}>
To: <sip:${file}@${DOMAIN}>
Contact: <sip:${file}@${SIP_SERVER}>
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
) | /usr/bin/sipsak shoot -a ${SIP_PASSWORD} -s sip:${file}@${DOMAIN} -f -
if [ $? -ne 0 ] ; then
echo "sipsak error for $file"
fi
else
echo "DOMAIN is null for $file"
fi
else
if [ ${#file} -ne 10 ] ; then
echo "Extension was not 10 digits: '$file' (${#file})"
else
echo "Problem with file: ${VM_HOME}/${file}@default"
fi
fi
rm ${VM_HOME}/${file}@default
done
exit 0
On Tue, 1 Mar 2005 10:06:56 -0500, Patrick Baker
<patricksbaker at gmail.com> wrote:
> could you show me an example of the sipsak command for the cisco phone
> - I can then just make an agi that will call it after vm is left.
>
> Best regards,
>
> Patrick B
>
>
> On Tue, 1 Mar 2005 10:03:35 -0500, Java Rockx <javarockx at gmail.com> wrote:
> > Since the SIP UA is registered with SER you'll need to have Asterisk
> > send a NOTIFY message to the user by means of SER.
> >
> > So you can send the NOTIFY to SER with a <From:> header as asterisk
> > and the <To> / R-URI as the Cisco UA.
> >
> > FYI, we do this using sipsak to send the NOTIFY to ser. This is
> > triggered either using the externnotify parameter in the Asterisk
> > voicemail.conf file and by CRON for periodic MWI updates.
> >
> > Regards,
> > Paul
> >
> >
> > On Tue, 1 Mar 2005 09:53:43 -0500, Patrick Baker
> > <patricksbaker at gmail.com> wrote:
> > > Hello,
> > >
> > > I'm sure this may have been asked but, I just wanted clarify how this
> > > would be accomplished. I'm looking to have the MWI light on my cisco
> > > phone turn on when a message is left in VM.
> > >
> > > Here is my current situation:
> > >
> > > sip user -> ser -> asterisk
> > >
> > > Best regards,
> > >
> > > Patrick b.
> > >
> > > _______________________________________________
> > > Serusers mailing list
> > > serusers at lists.iptel.org
> > > http://lists.iptel.org/mailman/listinfo/serusers
> > >
> >
>
More information about the sr-users
mailing list