Solved

Macro to set callerid on DAHDI channels for outbound calls through sip trunk

Posted on 2011-03-06
7
1,347 Views
Last Modified: 2013-11-12
We have 5 servers in a cluster with 96 DAHDI channels each and need to find a way to set the outbound callerid without having to write 96 individual config blocks in each of the chan_dahdi.conf files.

In addition to the sip trunk DID phone number each line also has a 5 digit number which we use internally.  We have a mysql database of the person's name, DID, 5 digit ext, and server they're on, but does not include their DAHDI channel.

My thought is to use a macro that runs an agi script to query the db and set the callerid, but I'm not sure how to write the macro.  If the caller is in the [homeoffice] context and the macro is in the [outboundsiptrunk] context, how do I extract the proper info needed to pass to the agi script?
0
Comment
Question by:FishMonger
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 28

Author Comment

by:FishMonger
ID: 35046768
>> the macro is in the [outboundsiptrunk] context

That's not worded well.  The macro is being called from within the [outboundsiptrunk] context.
0
 
LVL 36

Expert Comment

by:grblades
ID: 35056981
Here is an example that I use. To call it you just use the following command. It picks up the original caller by looking at the callerid of the extension and looks up the correct callerid number to use in a database.
${FOO} can be set to 'autowithold' to also look in the data to see whether callerid should be witheld.
$(FOO) set to 'withheld' will force the callerid to be witheld.
${FOO} set to 'force' followed by a number will force the callerid to be set to that number.
AGI(sm-setoutgoingcid.agi,${FOO})

<?php
include_once "ez_sql.php";

function writevar($variable, $value)
  {
  fwrite(STDOUT, "SET VARIABLE " .$variable ." " .$value ."\n");
  fflush(STDOUT);
  return fgets(STDIN);
  }

$agivars = array();
while (!feof(STDIN))
  {
   $agivar = trim(fgets(STDIN));
   if ($agivar === '')
     break;
   $agivar = explode(':', $agivar);
   $agivars[$agivar[0]] = trim($agivar[1]);
  }
extract($agivars);

// if withheld then withhold number
if ($agi_arg_1 == "withheld")
  writevar("CALLERPRES()","prohib");

$callerid="12345678";  \\ YOUR DEFAULT OUTGOING CALLERID
$qry="SELECT withhold, cid FROM autooutgoingcid WHERE extension='" .$agi_callerid ."'";

if ( $result = $db->get_row($qry))
  {
  if ( ($agi_arg_1 == "autowithheld")  && ($result->withhold == "yes") )
    writevar("CALLERPRES()","prohib");
  if (strlen($result->cid) > 3)
    $callerid = $result->cid;
  }

if (strncmp($agi_arg_1,"force",5) == 0)
  $callerid=substr($agi_arg_1,5);

writevar("CALLERID(num)",$callerid);
?>

Open in new window

0
 
LVL 28

Author Comment

by:FishMonger
ID: 35059328
Thanks for the suggestions, but I'm not sure if that will do what I need.  I'm not in the office today, so will have to wait until tomorrow to run some tests.

Just so I know we're on the same page,  here's the basic config I'm thinking of,  but have not tested.

[homeoffice]

ignorepat => 9
include => outboundsiptrunk
; a few other includes

exten => 10180,1,Dial(DAHDI/45,,Tt)


[outboundsiptrunk]

exten => _9xxxxxxx,1,Macro(setcid,arg1)  ; what global var do I need to pass to have the macro then pass exten 10180 to the agi script?
exten => _9xxxxxxx,n,Dial(SIP/${EXTEN:1}@XO)


[macro-setcid]

exten => s,1,AGI(setcid.pl, ${ARG1})


***************

Since I'm a Perl guy, not PHP, my script would be something like the following.


#!/usr/bin/perl

use strict;
use warnings;
use Asterisk::AGI;

$|++;  # turn off buffering

my $agi    = Asterisk::AGI->new;
my %input  = $agi->ReadParse;
my $exten  = $agi->get_variable('callerid');
my $cid    = query_db($exten);

$agi->set_callerid($cid);

sub query_db {
    my $exten = shift;
    my $cid;
    
    # code that queries the db and assigns $cid
    
    return $cid;
}

Open in new window

0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 36

Expert Comment

by:grblades
ID: 35059752

exten => _9xxxxxxx,1,Macro(setcid,arg1)  ; what global var do I need to pass to have the macro then pass exten 10180 to the agi script?

Assuming you have the phone 10180 is setup to have 10180 as its default callerid then this information will be sent to the agi script as part of the standard set of variables (agi_callerid in this specific case). See http://www.voip-info.org/wiki/view/Asterisk+AGI
0
 
LVL 28

Author Comment

by:FishMonger
ID: 35062726
We are not (or at least what to avoid) hard coding the callerid for individual extensions.  When we dial out through the sip trunk, the default callerid for any extension is the DID number that we use to authenticate with our provider.

So, if we don't hard code the callerid, would asterisk default to using the extension (10180 in this case) when it passes the vars to the agi script or would it set it to "unknown"?  I guess I'll test that tomorrow, but I assume it will be set to "unknown".

The agi_extension var would seem to be what I want, but my reading of the wiki would indicate otherwise.
0
 
LVL 36

Accepted Solution

by:
grblades earned 500 total points
ID: 35067238
agi_extension is basically the same as the $[EXTEN} variable in the dialplan so if you look at it in the context of an outgoing call it will contain the number dialed not the calling number.

If you dont set a callerid for an extension in asterisk then it will be set by whatever phone you are using. If you dont set a particular value in the phone then most default to using the authentication name.
0
 
LVL 28

Author Comment

by:FishMonger
ID: 35069695
Well, while I was having a day off they decided they could wait the extra day for me come back in ant write the agi script so they hard coded the callerid and several other parameters for all 480 extensions.  Personally I think that's a messy way of handling it, but it's not the first time where they did this kind of thing.

We just migrated our home office from Centrex lines to the SIP trunk and from the start (which has been a 6 month process) I brought up the callerid subject multiple times and was told not to worry about because we were going to use a single callerid for everyone.  Then on Saturday just before I went home they were in a panic because the CEO was upset because no-one had their proper callerid.
0

Featured Post

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Ever wanted to query Cisco Call Manager CDR records from MS SQL Server? Here's how! CUCM can be configured to upload a CDR file to a given FTP server every minute. This article will show you how to set this up, schedule the import of this data an…
Implementing Avaya's One-X portal is pretty painless, until you want to deploy this to the Android and iPhone clients when these clients are outside of your network. The clients will also work within your local network. Here is our experience and so…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

732 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question