[SOLVED] call feature code or dial from script or CLI

General discussions about Asterisk.

Moderators: Moderator, Support

[SOLVED] call feature code or dial from script or CLI

Postby rudycox » Wed Jan 27, 2016 5:46 am

Hi, my goal is to activate a time condition when a specific extension is off-line.
My office very often closes after the time set in the TimeGroup, and I would like to override it using a cron script that monitors a softphone status installed on a pc that is surely online until the office closes

I wrote this bash script to monitor the status of the that extension (12) and the status of the time condition (feature code *275), but I cannot "dial" this feature code from the script.

I tried "originate SIP/12 extension *275@from-internal", but it doesn't work

Can some help me please?
Thank you in advance for any answer

this is the script
Code: Select all
#!/bin/bash

#Check softphone status whose estension is 12
PC=`/usr/sbin/asterisk -r -x "sip show peers" | grep "12/12" |awk '{print $2}'`;
#if online is: 192.168.1.10
#if offline is: (Unspecified)

#Check Time Condition status whose feature code is *275
STATO=`/usr/sbin/asterisk -r -x "core show hint *275" |awk 'NR==1{split($3,a,":");print a[2]}'`;
#if activated is: InUse
#if deactivated is: Idle

echo $PC
echo $STATO


if [ "$PC" != "192.168.1.10" ] &&  [ "$STATO" == "Idle" ]; then
#pc is off-line   
echo "try to set  NightTime"
/usr/sbin/asterisk -r -x "originate SIP/12 extension *275@from-internal"
elif [ "$PC" == "192.168.1.10" ] && [ "$STATO" == "InUse" ]; then
echo "try to set DayTime"
/usr/sbin/asterisk -r -x "originate SIP/12 extension *275@from-internal"
else
echo ""
fi

Last edited by rudycox on Sat Jan 30, 2016 4:09 am, edited 1 time in total.
rudycox
Newsterisk
 
Posts: 2
Joined: Wed Jan 27, 2016 2:35 am

Re: call feature code from script or CLI

Postby rudycox » Fri Jan 29, 2016 7:29 am

Solved
The solution might be useful to someone.

The dial command for the cli is included in module chan_oss.so

Before to load the module, edit oss.conf
change:
Code: Select all
;context =default

to:
Code: Select all
context = timeconditions-toggles

and save
(I tried to set overridecontext = yes to pass a command like: console dial *275@timeconditions-toggles , but it doesn't work, or better, worked only once)

edit modules.conf
change:
Code: Select all
noload => chan_oss.so

to:
Code: Select all
load => chan_oss.so

and save
(so next time you reboot the module is loaded)

now from cli:
Code: Select all
*CLI>module load chan_oss.so


try if it works (*275 is my Time Condition feature code)
Code: Select all
*CLI>console dial *275


in freepbx you should see
Current Override: Temporary Override matching state

redo
Code: Select all
*CLI>console dial *275
in freepbx you should see
Current Override: No Override

schedule the script in cron like ( I set it to run every 30 seconds ):
Code: Select all
* * * * * /usr/bin/perl /root/check_sip_ext-2notte.pl; sleep 30 ; /usr/bin/perl /root/check_sip_ext-2notte.pl


This is the new script:
check_sip_ext-2notte.pl

Code: Select all
   
#!/bin/bash

    #Check softphone status whose estension is 12
    PC=`/usr/sbin/asterisk -r -x "sip show peers" | grep "12/12" |awk '{print $2}'`;
    #if online is: 192.168.1.10
    #if offline is: (Unspecified)

    #Check Time Condition status whose feature code is *275
    STATO=`/usr/sbin/asterisk -r -x "core show hint *275" |awk 'NR==1{split($3,a,":");print a[2]}'`;
    #if activated is: InUse
    #if deactivated is: Idle

# on production comment all echo lines below
    echo $PC
    echo $STATO


    if [ "$PC" != "192.168.1.10" ] &&  [ "$STATO" == "Idle" ]; then
    #pc is off-line   
    echo "try to set  NightTime"
    /usr/sbin/asterisk -r -x "console dial *275"
    elif [ "$PC" == "192.168.1.10" ] && [ "$STATO" == "InUse" ]; then
    echo "try to set DayTime"
    /usr/sbin/asterisk -r -x "console dial *275"
    else
    echo ""
    fi


Don't forget to make the file executable ;-)
Code: Select all
chmod +x check_sip_ext-2notte.pl


Note: on Pc I installed a very lightweight SIP softphone (microsip)

Rudy
rudycox
Newsterisk
 
Posts: 2
Joined: Wed Jan 27, 2016 2:35 am


Return to Asterisk General

Who is online

Users browsing this forum: No registered users and 8 guests