Realtime sip+voicemail mwi ; externnotify feature request


#1

after following various bits of info, I’m real close to having a work-around for MWI with SIP devices registered via Asterisk realtime. In summary, the approach I followed is consistent with this lead:
mail.iptel.org/pipermail/seruser … 11545.html

I had to make various modifications to the scripts to solve problems I encountered, make it work with voicemail contexts, etc.

Here is the main nasty part… this setup assumes that end devices register via SER, so it’s OK to send a NOTIFY message to @<domain.com> toward SER and let it resolve the endpoint IP address via its registration database. I have endpoints registered directly to Asterisk, so I need to send my NOTIFY messages to their explicit IP address.

Only way I can do this is to add mySQL queries to the shell scripts that process MWI (to get IP addr from asterisk.sip_peers), but it would be nicer if I could get this via externnotify= in the voicemail.conf file.

FEATURE REQUEST: enable externnotify= to have access to IP addr of the registered endpoint associated with a mailbox context. Better yet, just add support in voicemail to look up user in database and make MWI work natively with realtime sip.


#2

FYI to folks interested in this work-around… here’s how I have it working in my system (all SIP endpoints registered to Asterisk and using canreinvite=yes instead of registering endpoints via SER)…

>>>>> in voicemail.conf
externnotify=/usr/bin/mwi2spool

>>>>> in /usr/bin/mwi2spool
#!/bin/sh

USE: this script is to be called via system() command in Asterisk dialplan

and also via the externnotify= parameter in voicemail.conf

PURPOSE: enable MWI on and off on phones when asterisk can’t directly

respond because sip friends are in realtime database

BEHAVIOR: “touches” files in the spool directory which a

cron jobs later processes. The cron job is where we actually

send the SIP NOTIFY back to the UAs

CONTEXT=$1
EXTENSION=$2
VM_COUNT=$3
touch /var/spool/asterisk/mwi/$EXTENSION@$CONTEXT

>>>>> in /etc/crontab
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
HOME=/

run-parts

* * * * * root run-parts /etc/cron.minutely
01 * * * * root run-parts /etc/cron.hourly
02 4 * * * root run-parts /etc/cron.daily
22 4 * * 0 root run-parts /etc/cron.weekly
42 4 1 * * root run-parts /etc/cron.monthly

>>>>> in "/etc/cron.minutely/mwi-transmit
#!/bin/sh
mwi-transmit >> /var/log/asterisk/mwi_log 2>&1

>>>>> in /usr/bin/mwi-transmit
#!/bin/sh

This script sends the SIP NOTIFY message to UAs. 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 via

the template in $TEMPLATE.

The actual NOTIFY message is sent to the SIP proxy by the sipsak

utilty. After the message is sent we delete the processed file

from VM_HOME so we don’t keep resending the same message.

VM_ROOT=/var/spool/asterisk/voicemail
MWI_SPOOL=/var/spool/asterisk/mwi
TEMPLATE=/etc/mwi/notify.msg

cd $MWI_SPOOL

look for filenames of form user@context

files are put here by a script triggered by externnotify= in /etc/asterisk/voicemail.conf

mwi_touched_files=find . -type f -print
if [ ! “$mwi_touched_files” == “” ]
then

for file in $mwi_touched_files
do
echo “date +%Y-%m-%d" "%H:%M:%S: processing $file"
LEN=expr length $file
# need to strip off leading “./” from each file name returned by find
LEN=expr $LEN - 2
file=expr substr $file 3 $LEN
IDX1=expr index "$file" \@
IDX2=$(($IDX1 + 1))
IDX1=$(($IDX1 - 1))
MAILBOX=expr substr $file 1 $IDX1
DOMAIN=expr substr $file $IDX2 $LEN
CLIENT_IP=”mysql -u asterisk -pasterisk -B -e"select ipaddr from asterisk.sip_peers where name='$MAILBOX'" | tail -1"
TOTAL_MESSAGES=find $VM_ROOT/$DOMAIN/$MAILBOX -name "*.txt" | wc -l | sed 's/^ *\(.*\) *$/\1/'
NEW_MESSAGES=find $VM_ROOT/$DOMAIN/$MAILBOX/INBOX -name "*.txt" | wc -l | sed 's/^ *\(.*\) *$/\1/'
OLD_MESSAGES=$(($TOTAL_MESSAGES - $NEW_MESSAGES))

    if [ "$NEW_MESSAGES" == "0" ]; then
            HAS_NEW="no"
    else
            HAS_NEW="yes"
    fi
                                                                                                                                      
    CONTENT_LENGTH=$((34 + `expr length $HAS_NEW` + 
                           `expr length $NEW_MESSAGES` + 
                           `expr length $OLD_MESSAGES`))
                                                                           
    CMD="s/!SUBSCRIBER!/$MAILBOX@$CLIENT_IP/g;s/!MAILBOX!/$MAILBOX/g;
         s/!CONTENT_LENGTH!/$CONTENT_LENGTH/g;
         s/!HAS_MESSAGE!/$HAS_NEW/g;
         s/!NEW_COUNT!/$NEW_MESSAGES/g;
         s/!OLD_COUNT!/$OLD_MESSAGES/g"
    echo "$CMD" > /tmp/mwi-sed-script

    cat /etc/mwi/notify.msg | sed -f /tmp/mwi-sed-script > /tmp/mwi-sip-msg
    `/usr/local/bin/sipsak shoot -f /tmp/mwi-sip-msg -s sip:$MAILBOX@$CLIENT_IP`
    rm ./$file
    echo "`date +%Y-%m-%d" "%H:%M:%S`: MWI sent ($HAS_NEW) to $file"

done
fi

>>>>> special thanks to “Paul” upon whose work this is based

Thanks,
Scott