of course
[code]#!/usr/bin/perl -w
this is bbNotify.agi
free to use, don’t abuse.
copyright baconbuttie 2006
use DBI;
use Asterisk::AGI;
use IO::Socket;
my $AGI = new Asterisk::AGI;
my %input = $AGI->ReadParse();
my $debug = 3; # Debug level, lower to reduce logging
my $port=10629; # Always this !!
my $message; # Message depends on ARG3
my $mydata = $ARGV[0]; # Data value to look for
my $keyword = $ARGV[1]; # Keyword to search db for
my $msgtype = $ARGV[2]; # Used to determine message start
my $caller = $ARGV[3]; # CallerID for this notification
#$caller = $AGI->get_variable(‘callerid’);
if ($debug >= 2) {debug("Data = ".$mydata,3);}
if ($debug >= 2) {debug("Keyword = ".$keyword,3);}
if ($debug >= 2) {debug("Message Type = ".$msgtype,3);}
if ($debug >= 2) {debug("CallerID = ".$caller,3);}
if ($debug >= 2) {
foreach $key (keys %input) {
debug("$key = ".$input{$key},3);
}
}
get record set ipaddresses for matching keyword/value pairs
my $dbh = DBI->connect(“dbi:mysql:asterisk”,“mysqluser”,“mysqlpassword”) or die(“Connect failed”);
my $query = “SELECT ipaddress AS ipaddress FROM notify WHERE keyword = ‘$keyword’ AND mydata = ‘$mydata’”;
if ($debug >= 2) {debug("Notify Query = ".$query,3);}
my $sth = $dbh->prepare($query) or die(“Couldn’t prepare statement”);
$sth->execute;
if($sth->rows == 0)
{
debug(“No Notify Destinations found”,3);
exit 0;
}
else
{
# determine the message we’re sending
if($msgtype eq “1”) {$message = "Home call from : ".$caller;}
elsif($msgtype eq “2”) {$message = "Business call from : ".$caller;}
elsif($msgtype eq “3”) {$message = "Internal call for $mydata from : ".$caller;}
elsif($msgtype eq “4”) {$message = "Group call from : ".$caller;}
elsif($msgtype eq “5”) {$message = "Unused : ".$caller;}
elsif($msgtype eq “6”) {$message = "Unused : ".$caller;}
# go through recordset, sending message to each
while (($ipaddress) = $sth->fetchrow_array) {
print “$ipaddress\n”;
$socket=IO::Socket::INET->new(PeerAddr=> $ipaddress, PeerPort=> $port, Proto=> 'tcp', Type=> SOCK_STREAM) or die "Can't talk to host";
print $socket $message;
close $socket;
}
$dbh->disconnect;
exit 1;
}
sub debug
{
my $string = shift;
my $level = shift || 3;
if ($debug) {
$AGI->verbose($string, $level);
}
return(0);
}
exit 0;
[/code]
and i call it with something like
you need a db table to find the ip address of the corresponding extension, but you should be able to work that out ok.