[Asterisk-Users] paging agi
Jeremy
Jeremy at specialtel.com
Fri Jan 27 00:23:27 MST 2006
Hello Everyone,
I've been playing with an agi script for paging sip phones.
page.agi will take all available sip extensions and assign them to the
global variable PAGE_GROUP. Allowing the phones to be paged from the
dialplan with the new Page cmd. Extensions to be excluded are presented as
arguments to the agi. Each time a page is made this agi refreshes the global
variable. This works with both my aastra and polycom phones. It should be
easily modified for other sip phones. The agi itself is a compliation of
allpage.agi & allcall.agi, with a few changes.
Copy this script to your agi-bin:
#!/usr/bin/perl
#
# page.agi - Original file was allpage.agi by Rob Thomas 2005.
# With parts of allcall.agi Original file by John Baker
# Modified by Jeremy Betts 2006
#
#
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of Version 2 of the GNU General
# Public License as published by the Free Software Foundation
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# page.agi will take all available sip extensions and assign them to the
# global variable PAGE_GROUP. Allowing the phones to be paged from the #
# dialplan with the new Page cmd.
# Each time a page is made this agi refreshes the global variable.
# This works with both my aastra and polycom phones.
# It should be easily modified for other sip phones
#
#
#
#Check for Telnet
if (eval "require Net::Telnet;") {
use Net::Telnet;
} else {
print "VERBOSE \"Net::Telnet NOT INSTALLED - this is required\"
0\n";
exit 0;
}
# You need to configure this: Your manager API username and password. This
# is the information from /etc/asterisk/manager.conf. You need something
like
# this in it:
# [admin]
# secret = amp111
# deny=0.0.0.0/0.0.0.0
# permit=127.0.0.0/255.0.0.0
# read = system,call,log,verbose,command,agent,user
# write = system,call,log,verbose,command,agent,user
# IF that's what you have in your conf file, this is what you should have
here:
my $mgruser = "admin";
my $mgrpass = "amp111";
my $mgrport = 5038;
# set our array of phones that we will NOT be paging
@bypass = @ARGV;
# Get our needed info for idle sip phones
@sips = grep(/^\s+\d+\s.*/, `asterisk -rx "show hints"`);
# Now check each sip phone to see if it's in use and also
# against our exclude list. If it passes both, it's
# added to our array of calls to make
foreach $sipline (@sips) {
my ($junk0, $exten, $junk1, $chan, $state, $junk2) = split(/ +/,
$sipline,6);
unless (($state ne "State:Idle") || (grep(/$exten/i, @bypass))) {
push (@mypage, "$exten");
}
}
$page= join ("&SIP/", @mypage);
print "$page";{
# Open connection to AGI and set Global Variable PAGE_GROUP
# to our completed array of sip phones
my $tn = new Net::Telnet ( Port => $mgrport,
Prompt => '/.*[\$%#>] $/',
Output_record_separator => '',
Input_Log=> "/tmp/input.log",
Output_Log=> "/tmp/output.log",
Errmode => 'return', );
$tn->open("127.0.0.1");
$tn->waitfor('/0\n$/');
$tn->print("Action: Login\n");
$tn->print("Username: $mgruser\n");
$tn->print("Secret: $mgrpass\n");
$tn->print("Events: off\n\n");
my ($pm, $m) = $tn->waitfor('/Authentication (.+)\n\n/');
if ($m =~ /Authentication failed/) {
print "VERBOSE \"Incorrect MGRUSER or MGRPASS - unable to connect to
manager interface\" 0\n";
exit;
}
$tn->print("Action: Setvar\n");
$tn->print("Variable: PAGE_GROUP\n");
$tn->print("Value: $page\n\n");
$tn->print("Action: Logoff\n\n");
$tn->close;
}
Then add the following to your dialplan:
exten => *61,1,Set(TIMEOUT(absolute) = 15)
exten => *61,n,AGI(page.agi|<arg>|<arg>)
exten => *61,n,SetCallerID("Page:${CALLERIDNAME}" <${CALLERIDNUM}>)
exten => *61,n,Set(_ALERT_INFO="Ring Answer")
exten => *61,n,SIPAddHeader(Call-Info: answer-after=0)
exten => *61,n,Page(SIP/${PAGE_GROUP})
exten => *61,n,Hangup()
Hope this is helpfull for others. Works great for me, no more waiting for
page to hang up! As soon as the paging phone is hung up all paged phones
hang up.
More information about the asterisk-users
mailing list