How to monitor certain Queues with Chanspy

In this installment of pbx.ninja, we are going to talk about listening to specific queues with FreePBX.

Previously, we showed you how to How to barge with freepbx, and now this is how to spy on queues that may each have their own members.

Basically here is the theory:
We are going to add a SPYGROUP variable to each channel that comes in to a queue, and then add in a custom subroutine that creates a chanspy hook into all channels with that queue number.

Procedure:
You will need to patch FreePBX. At the bottom of the posts there is a patch for 2.9 and 2.10+

This patch modified FreePBX to add dialplan which adds the SPYGROUP, which is how we monitor a specific queue.

After successfully modifying the functions.inc, we need to edit /etc/asterisk/extensions_custom.conf

Add the following code (1 time hint: if you already have an ext-local-custom context, then add that line there, don’t make 2 of them):


[ext-local-custom]
exten => _*200X.,1,Gosub(sub-my-chanspy,s,1(${EXTEN:4}))

[sub-my-chanspy]
;include => app-chanspy-custom
exten => s,1,Macro(user-callerid,)
exten => s,n,Answer
exten => s,n,Wait(1)
exten => s,n,ChanSpy(,g(q${ARG1}))
exten => s,n,Hangup

Now, make a minor change in FreePBX and then apply config to make freepbx recreate the dialplan and reload it. Now you can spy on any channel in your queue.

If your primary queue is 5000 Try it out by dialing *2005000.

Note: This will only spy on calls that come into the queue AFTER you apply these changes, so it won’t let you spy on active calls made before the change.

Expert tip: If you want the ability to barge,as well as listen, then add the d flag to the ChanSpy command.

exten => s,n,ChanSpy(,dg(q${ARG1}))

Now you can switch modes by pressing 4,5,and 6
4 – Spy/Listen
5 – Whisper
6 – Barge

Hope you enjoyed today’s tip!
If this article helps you, please +1! ( At the bottom of the post )

Patch Files:(If the diff fails, just look for lines 390-397, and insert the 2 lines with a + on them, between the lines without them)
For 2.9 – /var/www/html/admin/modules/queues/functions.inc.php

***************
*** 390,397 ****
// Inform all the children NOT to send calls to destinations or voicemail
//
$ext->add('ext-queues', $exten, '', new ext_setvar('__NODEST', '${EXTEN}'));
+ //add SPYGROUP=q1000
+ $ext->add('ext-queues',$exten,'', new ext_set('__SPYGROUP','q'.$exten));

// deal with group CID prefix
if ($grppre != '') {
--- 390,395 ----

For 2.10: /var/www/html/admin/modules/queues/functions.inc.php/dialplan.php

***************
*** 120,127 ****
* Virtual Queue Settings, dialplan designed so these can be changed by other modules and those changes
* will override the configured changes here.
*/
+ //add SPYGROUP=q1000
+ $ext->add($c,$exten,'', new ext_set('__SPYGROUP','q'.$exten));
// deal with group CID prefix
$ext->add($c, $exten, '', new ext_set('QCIDPP', '${IF($[${LEN(${VQ_CIDPP})}>0]?${VQ_CIDPP}' . ':' . ($grppre == '' ? ' ':$grppre) . ')}'));
$ext->add($c, $exten, '', new ext_execif('$["${QCIDPP}"!=""]', 'Macro', 'prepend-cid, ${QCIDPP}'));
--- 120,125 ----

Tagged with: , , , , , , ,
Posted in FreePBX
2 comments on “How to monitor certain Queues with Chanspy
  1. joshua says:

    Hey,

    Thanks for all your tips. I’m trying to record an entire conversation using MixMonitor() in asterisk 11, including when someone is whispering on the line. But i cannot record what the third one whispers only the initial conversation.
    Do you know if it is even possible please ?

    • hackrr says:

      You need to add the record option to chanspy, with an optional[,but strongly preferred] prefix.

      Example:
      exten => _*222x.#/100,n,ChanSpy(sip/65,qwr(monitorrec))

Leave a Reply

Your email address will not be published. Required fields are marked *

*