[Freeswitch-users] using ssh connection in module python in dialplan

Joel Serrano joel at gogii.net
Mon Mar 26 19:11:08 UTC 2018


Seems to me you might be running freeswitch as a non-root user, and this
user doesn't have access to root's private key referenced in your python
script?

Just a guess though.

On Sun, Mar 25, 2018 at 4:39 AM, Morteza Bashsiz <morteza.bashsiz at gmail.com>
wrote:

> Hi everybody
> I have an asterisk(172.16.1.33) and freeswitch(172.16.1.30)
> My scenario :
>
>    1. Calls come to freeswitch ivr menu
>    2. In ivr calls transfer to asterisk after running an python script
>    freeswitch start recording voice
>    3. In asterisk calls push to an queue
>
> my python script is :
>
> ############################################################
> import paramiko
>
> hostname = '172.16.1.33'
> port = 3022
> username = 'root'
> pkey_file = '/root/.ssh/id_rsa'
>
> def get_agent_id(num):
>     command="asterisk -rx \"pjsip show channels\" | grep -a1 \"CLCID:
> \\\"%s\\\"\" | grep Channel | cut -d \/ -f2 | cut -d\- -f1 " % (num)
>     key = paramiko.RSAKey.from_private_key_file(pkey_file)
>     s = paramiko.SSHClient()
>     s.load_system_host_keys()
>     s.connect(hostname, port, pkey=key)
>     stdin, stdout, stderr = s.exec_command(command)
>     result=str(stdout.read())
>     s.close()
>     return result
>
> #if __name__ == "__main__":
> #    agent_id=get_agent_id('1000')
> #    print (agent_id)
> import freeswitch as freeswitch
> def handler(session, args):
>     caller_num = session.getVariable("caller")
>     agent_num = get_agent_id(caller_num)
>     session.setVariable("AGENT_NUM", agent_num);
>     session.setVariable("CALLER_NUM", caller_num);
> ############################################################
>
>
> my dial plan is :
>
> ############################################################
>
>      <extension name="test_dialplan">
>       <condition field="destination_number" expression="^2605$">
>         <action application="playback" data="phrase:shatel_before_queue"/>
>         <action application="set" data="RECORD_TITLE=Recording
> ${destination_number} ${caller_id_number} ${strftime(%Y-%m-%d %H:%M)}"/>
>         <action application="set" data="RECORD_DATE=${strftime(%Y-%m-%d
> %H:%M)}"/>
>         <action application="set" data="RECORD_STEREO=true"/>
>         <action application="set" data="caller=${caller_id_number}"/>
>         <action application="python" data="test"/>
>         <action application="record_session" data="$${base_dir}/recordings/
> archive/${strftime(%Y-%m-%d-%H-%M-%S)}_${destination_
> number}_${caller_id_number}_${AGENT_NUM}.wav"/>
>         <action application="bridge" data="sofia/internal/261910@$$
> {asterisk_vip}"/>
>       </condition>
>     </extension>
>
> ############################################################
>
>
> *MY PROBLEM IS:*
>
> when i want to use my variable AGENT_NUM it is null
> BUT
> when i use the python manually it returns true value
>
> please help me what is my mistake ??????
>
> _________________________________________________________________________
> Professional FreeSWITCH Consulting Services:
> consulting at freeswitch.org
> http://www.freeswitchsolutions.com
>
> Official FreeSWITCH Sites
> http://www.freeswitch.org
> http://confluence.freeswitch.org
> http://www.cluecon.com
>
> FreeSWITCH-users mailing list
> FreeSWITCH-users at lists.freeswitch.org
> http://lists.freeswitch.org/mailman/listinfo/freeswitch-users
> UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users
> http://www.freeswitch.org
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freeswitch.org/pipermail/freeswitch-users/attachments/20180326/0559ab5a/attachment.html>


More information about the FreeSWITCH-users mailing list