Query extension status and do something


(Hunteralberto) #1

Hi guys,

I’m not a huge expert in Asterisk, but love the solution…

How can I do a script that query an extension status (register or unregistered) an if it’s unregistered make a call to a xxx-xxx-xxxx number and play a recording.

Thanks,


#3

If your extension was ‘6904’ and your recording is ‘your-recording.wav’ in /var/lib/asterisk/sounds/(your-language)/custom , then a good start would be (from a shell)

`[[ “$(rasterisk -x ‘sip show peer 6904’|grep Status)” =~ OK ]]||echo -e “Channel: Local/xxxxxxxxxx@from-internal\nApplication: Playback\nData: custom/your-recording\n” > /tmp/call.file;mv /tmp/call.file /var/spool/asterisk/outgoing/

edited as per @PitzKey checks for ‘qualified’

this for chan-sip for chan-pjsip you will need to similarly query pjsip’s endpoints

[[ "$(rasterisk -x 'pjsip show endpoints'|grep Endpoint|grep 6904)" =~ Unavailable ]]&& echo -e "Channel: Local/xxxxxxxxxx@from-internal\nApplication: Playback\nData: custom/your-recording\n" > /tmp/call.file;mv /tmp/call.file /var/spool/asterisk/outgoing/

Be aware that endpoints in chan_pjsip are “less unique” than in chan_sip


(Itzik) #4

I would do!= Reachable because before going into the Unknown status it’s in the UNREACHABLE status.


(Hunteralberto) #5

Thank @dicko!!

Now, how can I configure this script to be active when a agent login in a queue.

Example: The extension 6904 login to queue 100. Immediately the script is active checking every 3 minute if the extension is available. If not, execute the script you send me. If the agent logout, deactivate the script.

I use chan_sip.

Thanks,


#6

several ways, ami or dialplan , but as you are just polling and the agents are presumably dynamic

[[ $(rasterisk -x "queue show 100" | grep 6904) ]] && echo loggedin

would prunt loggedin when logged in and not when logged out , so prepend that test then && to the script and set a cronjob to call it at “*/3 9-17 * * 1-5”


(system) closed #7

This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.