Loop,
The voipinfo examples are pretty extensive, and if you are familiar
with perl, should be easy to adapt....
In order to connect to the asterisk manager, you will need to add a
user and password to /etc/asterisk/manager.conf - and make sure that
your asterisk boxes firewall (iptables) accepts connections on port
5038 from wherever you are running your script.
... You need to do a full restart of asterisk after updating the
manager.conf (I think) ...
If you are still at a complete loss, here is a script that I use to
read info from an asterisk box, as well as on that writes infor to the
asterisk internal database....
You will need to put your hostname userid and password in ... and load
a couple of pretty standard perl modules ....
You will notice from the comments, that I ripped these in whole cloth
from the examples on the voip-info site -
The subroutines are the crucial bit - write a stream to the manager
and read back the response - in you case you would want to write
"extensions reload" ...
You may want ot parse the reponse to the reload command for exeption
or errors, or look for a value that you think should/would appear on
the console if you issued the same command.
Also, for something as simple as reloading extensions, you could just
use the perl system() function ...
#!/usr/bin/perl
my $reload_cmd = '/usr/sbin/asterisk -rx "extensions reload"';
system ($reload_cmd);
# end of simple script
... run this on the asterisk box, and you should see the results of an
extensions reload on screen (it works here) ...
aloha,
dave
more interesing expamples:
........................................ readcfa
..................................
#!/usr/bin/perl
# Asterisk Queue Viewer
# Uses management interface to query call queues on a machine
# (C) 2003 David C. Troy -- dave at toad.net
# This program is free software, distributed under the terms of the
# GNU General Public License
use IO::Socket;
use CGI qw(:standard);
use CGI::Carp qw/fatalsToBrowser/;
$roc = $ARGV[0];
$did = $ARGV[1];
print $roc;
print $did;
$host = "your.hostname.com";
$port = 5038;
$user = "youruser";
$secret = "yourpass";
$EOL = "\015\012";
$BLANK = $EOL x 2;
$remote = IO::Socket::INET->new(
Proto => 'tcp', # protocol
PeerAddr=> $host, # Address of server
PeerPort=> $port, # port of server
Reuse => 1
) or die "$!";
$remote->autoflush(1); # Send immediately
# Login and get our booty from Asterisk
$logres = send_cmd("Action: Login${EOL}Username: $user${EOL}Secret:
$secret$BLANK");
$qinfo = send_cmd("Action: COMMAND\r\ncommand: database showkey
$roc/$did/CFA$BLANK$EOL");
$logres = send_cmd("Action: Logoff$BLANK");
close $remote; # Close socket
print $qinfo;
sub read_conn {
my $buf="";
while (<$remote>) {
last if $_ eq $EOL;
s/$EOL/\n/g;
$buf .= $_;
}
return $buf
}
sub send_cmd { my $cmd = @_[0];
my $buf="";
print $remote $cmd;
$buf = read_conn();
return $buf;
}
............................. writecfa ..................................
#!/usr/bin/perl
# Asterisk Queue Viewer
# Uses management interface to query call queues on a machine
# (C) 2003 David C. Troy -- dave at toad.net
# This program is free software, distributed under the terms of the
# GNU General Public License
use IO::Socket;
use CGI qw(:standard);
use CGI::Carp qw/fatalsToBrowser/;
$roc = $ARGV[0];
$did = $ARGV[1];
$cfa = $ARGV[2];
print $roc;
print $did;
print $cfa;
$host = "your.host.com";
$port = 5038;
$user = "youruser";
$secret = "yourpass";
$EOL = "\015\012";
$BLANK = $EOL x 2;
$remote = IO::Socket::INET->new(
Proto => 'tcp', # protocol
PeerAddr=> $host, # Address of server
PeerPort=> $port, # port of server
Reuse => 1
) or die "$!";
$remote->autoflush(1); # Send immediately
# Login and get our booty from Asterisk
$logres = send_cmd("Action: Login${EOL}Username: $user${EOL}Secret:
$secret$BLANK");
$qinfo = send_cmd("Action: COMMAND\r\ncommand: database put $roc
$did/CFA $cfa$BLANK$EOL");
$logres = send_cmd("Action: Logoff$BLANK");
close $remote; # Close socket
print $qinfo;
sub read_conn {
my $buf="";
while (<$remote>) {
last if $_ eq $EOL;
s/$EOL/\n/g;
$buf .= $_;
}
return $buf
}
sub send_cmd { my $cmd = @_[0];
my $buf="";
print $remote $cmd;
$buf = read_conn();
return $buf;
}
On 12/26/06, Loop Z <[EMAIL PROTECTED]> wrote:
Hi, Would you please explain that thing clearly. I didn't understand
what you said sir. Will you please explain me with an example
On 12/26/06, Dave Price <[EMAIL PROTECTED]> wrote:
> Your perl application can open a connection to the manager interface
> of you asterisk, and issue the command there.
>
> These examples should get you started:
>
> http://www.voip-info.org/wiki/view/Asterisk+manager+Examples
>
> aloha,
> dave
>
>
> On 12/26/06, Loop Z <[EMAIL PROTECTED]> wrote:
> > Hi All,
> >
> > I want to fire an asterisk Command through perl (AGI) program. How is
> > that possible? For example., i want to fire "extensions reload" in my
> > asterisk console via my perl program. Please send me a valid reply as
> > soon as possible
> >
> > --
> > Regards and Love
> >
> > --LoopZ Technologies--
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> >
> >
>
>
> --
> aloha,
> dave
>
--
Regards and Love
--LoopZ Technologies--
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]