Help with AGI in queue status

I am new to programming, trying to create a PHP AGI to check a queue status before placing the call on that queue. If the Queue has more than 10 calls waiting then i want to play an IVR saying the “Queue is busy” if call waiting is less than 10, call will directly placed on queue. I have the dial plan ready for this. But, need the AGI to execute below command and give an verbose as BUSY or FREE – help please.

asterisk -rx ‘queue show queue_name’ | grep queue_name
queue_name has 5 calls (max unlimited) in ‘rrmemory’ strategy (7s holdtime, 146s talktime), W:0, C:82720, A:26544, SL:4.4% within 0s

This is the one i came up with, but it didn’t work :frowning:

#!/usr/bin/php -q

<?php require 'phpagi-2.20/phpagi.php'; $agi = new AGI; #calls=$agi->exec(asterisk -rx 'queue show queue_name' | grep queue_name | awk '{print $3}'); if($calls < 7) {$queue_status = busy} else {$queue_status = free} $agi->set_variable('queue_status',$queue_status); <? I have the dial plan based on the output here - If $queue_status = Free, i skip IVR if busy it play the BUSY IVR.

Got it working from the dial plan itself, without AGI. :slight_smile: