It appears there is no AMI library being used in the system. AST_update contains code to use the AMI protocol to interface with asterisk's manager interface using perl's telnet library. I'm at odds with this, to not introduce any extra source files into the system I would have to use the same approach. Directly interface with AMI using telnet. There are many setup / tear down and message formatting routines for ami usage through telnet scripted into AST_update. If I simply used the same code, we would have code in two places that does the exact same thing. If code in one area updates, we would have to update it in the other area. The right thing to do seems to be to abstract the AMI functionality into a lib and use it anywhere astguiclient needs to access AMI functionality. I'm guessing this hasn't been done because there is only one place AMI functionality has been used, so DRY principles would not have needed to have been enforced. Then again, you use originate commands through AMI in the timeonVDADall screen. Looking into the source, the script triggers the agent api via ajax call which inserts a record into some sort of mysql based AMI command queue. Seems that AST_manager_send.pl reads this queue and reformats the request to be passed to AST_send_action_child. AST_send_action_child then reimplements the same setup/teardown code in AST_update to send commands to AMI.
- Code: Select all
$telnet_port = '5038' if (!$telnet_port);
### connect to asterisk manager through telnet
my $tn = new Net::Telnet (Port => $telnet_port,
Prompt => '/.*[\$%#>] $/',
Output_record_separator => '',
Errmode => "return");
#$fh = $tn->dump_log("$PATHlogs/SAC_telnet_log.txt"); # uncomment for telnet log
my $telnet_login;
if ($ASTmgrUSERNAMEsend) {
$telnet_login = $ASTmgrUSERNAMEsend;
} else {
$telnet_login = $ASTmgrUSERNAME;
}
$tn->open($telnet_host);
$tn->waitfor('/[01]\n$/'); # print login
$tn->print("Action: Login\nUsername: $telnet_login\nSecret: $ASTmgrSECRET\n\n");
$tn->waitfor('/Authentication accepted/'); # waitfor auth accepted
$tn->buffer_empty;
Its not that much setup / teardown. Its just odd that so many scripts are talking to each other with no capability to return results the opposite direction. I do understand how systems grow, and I can see how that might have happened as vicidial developed.
The lib I use for AMI actually uses asterisk's http interface, though it may not provide some of the level of queueing and dispatch logging control that the existing system provides, it does provide 2 way communication with AMI. This will allow the IP for the extension/phone/station to be retrieved in just 3-4 lines.
- Code: Select all
<?php
require 'asterisk_ajam.php';
$a=new AsteriskAJAM();
$response=$a->SendCommand(array(
'action'=>'sipshowpeer',
'peer'=>"512"
));
?>
I'm fine with either approach or one you suggest. Direct Telnet, AJAM lib, or cron job to change permissions on asterisk.ctl ? (Remember the whole reason we need one of these options is to fetch the IP of a station based on its sip registration data). Maybe we could just implement a cron job to dump sip registration data into the database and run it on cron. Another possibility outside of the box is to just log the IP the user logged in from. The sip registration method would fail if the agent were not using a softphone. If we use the IP they logged into the web interface with, we can bypass all the asterisk sip show peer stuff and just add a routine to log the IP then grab it from the DB when we need it. Thoughts?