Problem with Originate command, via perl Asterisk::AMI module
I made some change and I can’t figure what went wrong.
Program Output:
testbuddy[34] ./simpleAMI.pl 1
Joining already running asterisk
To join again cmd:
asterisk -C/nfs/newadmin/public/users/crs/testbuddy/log/ast40/asterisk/asterisk.conf -r
Successfull Asterisk::AMI(
PeerAddr=>192.168.15.224,
PeerPort=>5039,
UserName=>admin,
Secret=>secret);
Connected to driverIP=192.168.15.224 PeerPort=5039
reload
Registered
Host dnsmgr Username Refresh State Reg.Time
152.148.200.242:5060 N 46005 3585 Registered Fri, 13 Feb 2015 15:41:47
152.148.200.242:5060 N 46004 3585 Registered Fri, 13 Feb 2015 15:41:47
152.148.200.242:5060 N 46003 3585 Registered Fri, 13 Feb 2015 15:41:47
152.148.200.242:5060 N 46002 3585 Registered Fri, 13 Feb 2015 15:41:48
152.148.200.242:5060 N 46001 3585 Registered Fri, 13 Feb 2015 15:41:48
5 SIP registrations.
Asterisk::AMI(Action=>Originate, Callerid=>ADBG0001, Channel=>SIP/46001, Context=>outgoing, Exten=>46002, Priority=>1, Timeout=>20000000)
AMI Response:
$VAR1 = {
'Message' => 'Originate failed',
'ActionID' => '7',
'GOOD' => 0,
'COMPLETED' => 1,
'Response' => 'Error'
};
Sleeping for 20 sec
End of Test
CLI Listing
[ul]
== Parsing ‘/nfs/newadmin/public/users/crs/testbuddy/log/ast40/asterisk/dundi.conf’: Found
[Feb 13 17:00:32] WARNING[25581]: db.c:332 ast_db_put: Couldn’t execute statment: SQL logic error or missing database
[Feb 13 17:00:32] WARNING[25581]: db.c:332 ast_db_put: Couldn’t execute statment: SQL logic error or missing database
– Reloading module ‘res_adsi.so’ (ADSI Resource)
– Reloading module ‘res_calendar.so’ (Asterisk Calendar integration)
– Reloading module ‘res_clialiases.so’ (CLI Aliases)
– Reloading module ‘res_config_curl.so’ (Realtime Curl configuration)
== Parsing ‘/nfs/newadmin/public/users/crs/testbuddy/log/ast40/asterisk/res_curl.conf’: Found
– Reloading module ‘res_config_ldap.so’ (LDAP realtime interface)
== Parsing ‘/nfs/newadmin/public/users/crs/testbuddy/log/ast40/asterisk/res_ldap.conf’: Found
[Feb 13 17:00:32] NOTICE[25581]: res_config_ldap.c:1639 parse_config: No directory user found, anonymous binding as default.
[Feb 13 17:00:32] ERROR[25581]: res_config_ldap.c:1665 parse_config: No directory URL or host found.
[Feb 13 17:00:32] NOTICE[25581]: res_config_ldap.c:1599 reload: Cannot reload LDAP RealTime driver.
– Reloading module ‘res_config_sqlite3.so’ (SQLite 3 realtime config engine)
– Reloading module ‘res_crypto.so’ (Cryptographic Digital Signatures)
– Reloading module ‘res_fax.so’ (Generic FAX Applications)
– Reloading module ‘res_musiconhold.so’ (Music On Hold Resource)
– Reloading module ‘res_phoneprov.so’ (HTTP Phone Provisioning)
== Parsing ‘/nfs/newadmin/public/users/crs/testbuddy/log/ast40/asterisk/sip.conf’: Found
== Parsing ‘/nfs/newadmin/public/users/crs/testbuddy/log/ast40/asterisk/users.conf’: Found
== Parsing ‘/nfs/newadmin/public/users/crs/testbuddy/log/ast40/asterisk/phoneprov.conf’: Found
– Reloading module ‘res_rtp_asterisk.so’ (Asterisk RTP Stack)
– Reloading module ‘res_stun_monitor.so’ (STUN Network Monitor)
== Using SIP RTP CoS mark 5
[Feb 13 17:00:33] WARNING[4552][C-00000008]: chan_sip.c:23016 handle_response_invite: Received response: “Forbidden” from ‘“ADBG0001” sip:asterisk@192.168.15.224;tag=as1ea0bf89’
[/ul]
sip.conf:
; sip.conf
; Created Fri Feb 13 13:51:01 2015
; Path: /nfs/newadmin/public/users/crs/testbuddy/log/ast40/asterisk/sip.conf
;
[general]
disallow=all
allow=G729
allow=G711
allow=ulaw
allow=alaw
registertimeout => 3600
defaultexpiry => 3600
allowexternaldomains = yes
sendrpid = yes
rpid_update = yes ; In certain cases, the only
; method by which a connected line chg ...
;
; OXE
;
register=>46001:password@152.148.200.242:5060/46001
register=>46002:password@152.148.200.242:5060/46002
register=>46003:password@152.148.200.242:5060/46003
register=>46004:password@152.148.200.242:5060/46004
register=>46005:password@152.148.200.242:5060/46005
;
; OXE client sections
;
[46001]
disallow=all
allow=G729
allow=G711
allow=ulaw
allow=alaw
type=peer
host=152.148.200.242
fromuser=46001
username=oxe46001
callerid="oxe46001" <46001>
insecure=invite,port
[46002]
disallow=all
allow=G729
allow=G711
allow=ulaw
allow=alaw
type=peer
host=152.148.200.242
fromuser=46002
username=oxe46002
callerid="oxe46002" <46002>
insecure=invite,port
[46003]
disallow=all
allow=G729
allow=G711
allow=ulaw
allow=alaw
type=peer
host=152.148.200.242
fromuser=46003
username=oxe46003
callerid="oxe46003" <46003>
insecure=invite,port
[46004]
disallow=all
allow=G729
allow=G711
allow=ulaw
allow=alaw
type=peer
host=152.148.200.242
fromuser=46004
username=oxe46004
callerid="oxe46004" <46004>
insecure=invite,port
[46005]
disallow=all
allow=G729
allow=G711
allow=ulaw
allow=alaw
type=peer
host=152.148.200.242
fromuser=46005
username=oxe46005
callerid="oxe46005" <46005>
insecure=invite,port
extensions.conf
; extensions.conf
; Created Fri Feb 13 13:51:01 2015
; Path: /nfs/newadmin/public/users/crs/testbuddy/log/ast40/asterisk/extensions.conf
;
[default]
include => outgoing
include => incoming
exten => _X.,1,Goto(incoming,${EXTEN},1)
[outgoing]
;
; OXE phones
; registrar = ao2-oxe.inse.lucent.com
; registrar ip = 152.148.200.242
;
exten => 46001,1,Verbose(46001 outgoing)
same => n,Wait(1)
same => n,Dial(SIP/46001@152.148.200.242:5060,20,rt)
same => n,wait(99999)
exten => 46002,1,Verbose(46002 outgoing)
same => n,Wait(1)
same => n,Dial(SIP/46002@152.148.200.242:5060,20,rt)
same => n,wait(99999)
exten => 46003,1,Verbose(46003 outgoing)
same => n,Wait(1)
same => n,Dial(SIP/46003@152.148.200.242:5060,20,rt)
same => n,wait(99999)
exten => 46004,1,Verbose(46004 outgoing)
same => n,Wait(1)
same => n,Dial(SIP/46004@152.148.200.242:5060,20,rt)
same => n,wait(99999)
exten => 46005,1,Verbose(46005 outgoing)
same => n,Wait(1)
same => n,Dial(SIP/46005@152.148.200.242:5060,20,rt)
same => n,wait(99999)
[incoming]
;
; OXE phones
; registrar = ao2-oxe.inse.lucent.com
; registrar ip = 152.148.200.242
;
exten => 46001,1,Verbose(46001 incoming)
same => n,answer()
same => n,wait(99999)
exten => 46002,1,Verbose(46002 incoming)
same => n,answer()
same => n,wait(99999)
exten => 46003,1,Verbose(46003 incoming)
same => n,answer()
same => n,wait(99999)
exten => 46004,1,Verbose(46004 incoming)
same => n,answer()
same => n,wait(99999)
exten => 46005,1,Verbose(46005 incoming)
same => n,answer()
same => n,wait(99999)
asterisk.conf:
[directories]
astetcdir=/nfs/newadmin/public/users/crs/testbuddy/log/ast40/asterisk
astmoddir => /usr/lib/asterisk/modules
astvarlibdir => /var/lib/asterisk
astdbdir => /var/lib/asterisk
astkeydir => /var/lib/asterisk
astdatadir => /var/lib/asterisk
astagidir => /var/lib/asterisk/agi-bin
astspooldir => /var/spool/asterisk
astrundir=/nfs/newadmin/public/users/crs/testbuddy/log/ast40
astlogdir=/nfs/newadmin/public/users/crs/testbuddy/log/ast40
astsbindir => /usr/sbin
[options]
live_dangerously = yes
;verbose = 3
;debug = 3
;alwaysfork = yes ; Same as -F at startup.
;nofork = yes ; Same as -f at startup.
;quiet = yes ; Same as -q at startup.
;timestamp = yes ; Same as -T at startup.
;execincludes = yes ; Support #exec in config files.
;console = yes ; Run as console (same as -c at startup).
;highpriority = yes ; Run realtime priority (same as -p at
; startup).
;initcrypto = yes ; Initialize crypto keys (same as -i at
; startup).
;nocolor = yes ; Disable console colors.
;dontwarn = yes ; Disable some warnings.
;dumpcore = yes ; Dump core on crash (same as -g at startup).
;languageprefix = yes ; Use the new sound prefix path syntax.
;systemname = my_system_name ; Prefix uniqueid with a system name for
; Global uniqueness issues.
;autosystemname = yes ; Automatically set systemname to hostname,
; uses 'localhost' on failure, or systemname if
; set.
;mindtmfduration = 80 ; Set minimum DTMF duration in ms (default 80 ms)
; If we get shorter DTMF messages, these will be
; changed to the minimum duration
;maxcalls = 10 ; Maximum amount of calls allowed.
;maxload = 0.9 ; Asterisk stops accepting new calls if the
; load average exceed this limit.
;maxfiles = 1000 ; Maximum amount of openfiles.
;minmemfree = 1 ; In MBs, Asterisk stops accepting new calls if
; the amount of free memory falls below this
; watermark.
;cache_record_files = yes ; Cache recorded sound files to another
; directory during recording.
;record_cache_dir = /tmp ; Specify cache directory (used in conjunction
; with cache_record_files).
;transmit_silence = yes ; Transmit silence while a channel is in a
; waiting state, a recording only state, or
; when DTMF is being generated. Note that the
; silence internally is generated in raw signed
; linear format. This means that it must be
; transcoded into the native format of the
; channel before it can be sent to the device.
; It is for this reason that this is optional,
; as it may result in requiring a temporary
; codec translation path for a channel that may
; not otherwise require one.
;transcode_via_sln = yes ; Build transcode paths via SLINEAR, instead of
; directly.
;runuser = asterisk ; The user to run as.
;rungroup = asterisk ; The group to run as.
;lightbackground = yes ; If your terminal is set for a light-colored
; background.
;forceblackbackground = yes ; Force the background of the terminal to be
; black, in order for terminal colors to show
; up properly.
;defaultlanguage = en ; Default language
documentation_language = en_US ; Set the language you want documentation
; displayed in. Value is in the same format as
; locale names.
;hideconnect = yes ; Hide messages displayed when a remote console
; connects and disconnects.
;lockconfdir = no ; Protect the directory containing the
; configuration files (/etc/asterisk) with a
; lock.
;stdexten = gosub ; How to invoke the extensions.conf stdexten.
; macro - Invoke the stdexten using a macro as
; done by legacy Asterisk versions.
; gosub - Invoke the stdexten using a gosub as
; documented in extensions.conf.sample.
; Default gosub.
; set to yes to allow testing
;live_dangerously = yes ; Enable the execution of 'dangerous' dialplan
; functions from external sources (AMI,
; etc.) These functions (such as SHELL) are
; considered dangerous because they can allow
; privilege escalation.
; Default yes, for backward compatability.
; Changing the following lines may compromise your security.
;[files]
;astctlpermissions = 0660
;astctlowner = root
;astctlgroup = apache
;astctl = asterisk.ctl
[compat]
pbx_realtime=1.6
res_agi=1.6
app_set=1.6
Full test program:
#!/usr/bin/perl -w
use strict;
use warnings;
use Asterisk::AMI;
use Asterisk::config;
use Data::Dumper;
my $outdir = "ast40";
my $running = 1; # 1 - asterisk is alreay running
$running = shift if @ARGV > 0;
# Assumes asterisk started vie:
# asterisk -C /nfs/newadmin/public/users/crs/testbuddy/log/$outdir/asterisk/
# asterisk.conf -c
#
#
my $callid = "ADBG0001";
my $host = "ao1-oxe-ed.inse.lucent.com";
$host = "ao8-ed.inse.lucent.com";
my $hostip = "152.148.200.236";
$hostip = "152.148.200.152";
my $regPort = 5060;
my $registrarip = "152.148.200.236";
$registrarip = "152.148.200.242";
my $phoneNumber = 51206;
$phoneNumber = "46001";
my $channel = "SIP/OXE/$phoneNumber";
$channel = "Local/$phoneNumber";
my $timeout = 20000; # Time Out in msec
my $call_num = 51207;
$call_num = 46002;
my $exten = $call_num; # Not so for ICM
my $context = "default";
my $cmd = qq{asterisk -C}
. qq{/nfs/newadmin/public/users/crs/testbuddy/}
. qq{log/$outdir/asterisk/asterisk.conf}
;
if ($running) {
print "Joining already running asterisk\n";
$cmd .= qq{ -r};
print "To join again cmd:\n$cmd\n";
} else {
print "Starting asterisk\n";
print "via cmd:\n$cmd\n";
print qx{$cmd};
my $amiwait = 5; # Second wait
print "Waiting $amiwait sec\n";
sleep $amiwait;
}
my $astSecret = "secret";
my $astUserName = "admin";
my $driverIp = "192.168.15.224";
my $simPort = 5039;
my $astAMI = Asterisk::AMI->new(PeerAddr => $driverIp,
PeerPort => $simPort,
Username => $astUserName,
Secret => $astSecret
);
if (!defined($astAMI)) {
print("Can't connect to Asterisk::AMI("
. "PeerAddr=>$driverIp"
. ",PeerPort=>$simPort"
. ",UserName=>$astUserName"
. ",Secret=>$astSecret"
. "): $!\n");
exit(1);
}
print "Successfull Asterisk::AMI("
. "\n\tPeerAddr=>$driverIp"
. ",\n\tPeerPort=>$simPort"
. ",\n\tUserName=>$astUserName"
. ",\n\tSecret=>$astSecret"
. ");\n";
print "Connected to driverIP=$driverIp PeerPort=$simPort\n";
print "reload\n";
my $reload_res = AsteriskCliCmd("core reload");
if (!$reload_res || !$reload_res->{'GOOD'}) {
print "core reload failed\n";
exit(1);
}
sleep 1;
my $show_reg = 1;
if ($show_reg) {
my $reg_res = AsteriskCliCmd("sip show registry");
if (!$reg_res || !$reg_res->{'GOOD'}) {
print "core reload failed\n";
exit(1);
}
my $r_cmds = $reg_res->{'CMD'};
print "Registered\n";
foreach my $cmd (@$r_cmds) {
print "$cmd\n";
}
}
###asteriskSetGlobal($astAMI, REGISTRAR => $hostip) or die("bad set global $host");;
###asteriskSetGlobal($astAMI, FROMPHONE => $phoneNumber) or die ("bad set phone");
###asteriskSetGlobal($astAMI, TOPHONE => $call_num) or die "bad set $call_num)";
my $deviceDN = $phoneNumber;
my %acmd = (
Action => 'Originate',
Channel => "SIP/$deviceDN\@$registrarip:$regPort",
### Channel => "SIP/$deviceDN",
### Channel => "SIP/$deviceDN\@$registrarip",
Context => 'outgoing',
Exten => $exten,
Priority => 1,
Callerid => $callid,
Timeout => $timeout * 1000, # In msec
### Async => 1,
);
my $r_ami_cmd = \%acmd;
print "Asterisk::AMI("
. AsteriskCmd2Str($r_ami_cmd)
. ")\n";
my $actionid = $astAMI->send_action($r_ami_cmd);
my $r_resp = $astAMI->get_response($actionid);
print "AMI Response:\n" . Dumper($r_resp) . "\n";
my $waitup = 20;
print "Sleeping for $waitup sec\n";
sleep $waitup;
print "End of Test\n";
#
# Set global variable
sub asteriskSetGlobal { # Returns: 1 iff successful
my (
$astAMI, # AMI ref
$name, # variable name
$value, # Value to set
) = @_;
my $cmd = "dialplan set global $name $value";
my $r_resp = $astAMI->action({
Action => 'Command',
Command => $cmd,
});
if (!defined($r_resp)) {
print "AsteriskSetGlobal:: undefined ($name $value)\n";
return 0;
}
if (!$r_resp->{'GOOD'}) {
print "AsteriskSetGlobal error:" . $r_resp->{'message'} . "\n";
return 0;
}
return 1;
}
#
# CLI cmd
sub AsteriskCliCmd { # Returns: response
my (
$clicmd
) = @_;
return "No AMI connected" if !defined($astAMI);
my %acmdh = (Action=>'Command',
Command=>$clicmd,
);
my $resp = $astAMI->action(\%acmdh);
return $resp;
}
# Asterisk Reteturn to string
# STATIC function
sub AsteriskCmd2Str { # Returns: string version
my (
$r_res, # AMI result hash
) = @_;
return "UNDEF" if !defined($r_res);
my $resstr = "";
for my $key (sort keys %$r_res) {
my $value = $r_res->{$key};
$value = "UNDEF" if !defined($value);
$resstr .= ", " if $resstr ne "";
if (ref $value eq "ARRAY") {
$value = "[" . join(",", @$value) . "]";
}
$resstr .= "$key=>$value";
}
return $resstr;
}