function get_agent_status($queue, $agent) { global $queue_members; # Connect to AGI $asm = new AGI_AsteriskManager(); $asm->connect(); # Add event handlers to retrieve the answer $asm->add_event_handler('queuestatuscomplete', 'Aastra_asm_event_queues_Asterisk'); $asm->add_event_handler('queuemember', 'Aastra_asm_event_agents_Asterisk'); # Retrieve info while (!$queue_members) { $asm->QueueStatus(); $count++; if ($count == 10) { break; } } # Get info for the given queue $status['Logged'] = False; $status['Paused'] = False; foreach ($queue_members as $agent_a) { if ($agent_a['Queue'] == $queue && $agent_a['Location'] == 'Local/' . $agent . '@from-queue/n' or $agent_a['Queue'] == $queue && $agent_a['Location'] == 'Local/' . $agent . '@from-internal/n') { $status['Logged'] = True; if ($agent_a['Paused'] == '1') { $status['Paused'] = True; } $status['Type'] = $agent_a['Membership']; $status['CallsTaken'] = $agent_a['CallsTaken']; $status['LastCall'] = $agent_a['LastCall']; break; } # Get Penalty $penalty = $asm->database_get('QPENALTY', $queue . '/agents/' . $agent); if ($penalty == '') { $penalty = '0'; } $status['Penalty'] = $penalty; } # Disconnect properly $asm->disconnect(); # Return Status return $status; }
$as->debug = true; } } // && CONNECTING connect($server=NULL, $username=NULL, $secret=NULL) $res = $as->connect($host, $uname, $password); if (!$res) { echo str_params(_("Cannot connect to asterisk manager @%1. Please check manager configuration...\n"), array($host), 1); sleep(60); continue; } if ($verbose > 2) { echo "Connected to asterisk.\n"; } //$res = $as->Ping(); $as->Events('agent,call'); $as->add_event_handler('Join', handle_handler); $as->add_event_handler('Leave', idle_handler); $as->add_event_handler('QueueCallerAbandon', handle_handler); $as->add_event_handler('AgentCalled', handle_handler); $as->add_event_handler('AgentDump', handle_handler); $as->add_event_handler('AgentConnect', handle_handler); $as->add_event_handler('AgentComplete', handle_handler); $as->add_event_handler('QueueMemberRemoved', handle_handler); $as->add_event_handler('QueueMemberAdded', handle_handler); $as->add_event_handler('QueueMemberPaused', handle_handler); $as->add_event_handler('QueueMemberStatus', idle_handler); $as->add_event_handler('*', idle_handler); while ($res = $as->send_request('WaitEvent')) { if ($verbose > 1) { echo "WaitEvent: " . $res['Response'] . "\n"; }
function Aastra_get_queue_entries_Asterisk($queue) { global $queue_entries; # Connect to AGI $asm = new AGI_AsteriskManager(); $asm->connect(); # Add event handlers to retrieve the answer $asm->add_event_handler('queuestatuscomplete', 'Aastra_asm_event_queues_asterisk'); $asm->add_event_handler('queueentry', 'Aastra_asm_event_entries_Asterisk'); # Retrieve info $count = 0; while (!$queue_entries) { $asm->QueueStatus(); $count++; if ($count == 10) { break; } } # Process info $index = 0; if (count($queue_entries) > 0) { foreach ($queue_entries as $entry) { if ($entry['Queue'] == $queue) { $entries[$index] = $entry; $index++; } } } # Disconnect properly $asm->disconnect(); # Return Status if (isset($entries)) { return $entries; } else { return NULL; } }
} } if (!$amihost) { echo date('Y-m-d H:i:s') . " : AMI is not configured. No need to run cycle\n"; exit; } echo date("Y-m-d H:i:s") . " running " . basename(__FILE__) . PHP_EOL; include './lib/phpagi/phpagi-asmanager.php'; $manager = new AGI_AsteriskManager(); echo date('Y-m-d H:i:s') . " : Connecting to AMI... "; if (!$manager->connect($amihost . ":" . $amiport, $amiusername, $amipassword)) { echo " ...Connection failed.\n"; exit; } else { echo " ...Connection established.\n"; $manager->add_event_handler('*', 'dump_events'); } $manager->wait_response(); $latest_check = 0; $checkEvery = 10; // poll every 1 seconds while ($manager->Ping()) { if (time() - $latest_check > $checkEvery) { setGlobal(str_replace('.php', '', basename(__FILE__)) . 'Run', time(), 1); $latest_check = time(); } if (file_exists('./reboot') || isset($_GET['onetime'])) { $manager->disconnect(); $db->Disconnect(); exit; }
function is_agent_logged($agent) { global $queue_members; $queue_members = ''; # Transcode for device and user mode $agent = Aastra_get_userdevice_Asterisk($agent); # Not logged by default $return = False; # Connect to AGI $asm = new AGI_AsteriskManager(); $asm->connect(); # Add event handlers to retrieve the answer $asm->add_event_handler('queuestatuscomplete', 'asm_event_queues'); $asm->add_event_handler('queuemember', 'asm_event_agents'); # Retrieve info while (!$queue_members) { $asm->QueueStatus(); $count++; if ($count == 10) { break; } } # Get info for all the queues foreach ($queue_members as $agent_a) { if ($agent_a['Location'] == 'Local/' . $agent . '@from-queue/n' or $agent_a['Location'] == 'Local/' . $agent . '@from-internal/n') { $return = True; break; } } # Disconnect properly $asm->disconnect(); # Return Status return $return; }