Solved

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

Posted on 2011-03-06
7
1,290 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
  • 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
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

How To Create Custom / Distinctive Ring Tones on Polycom Phones Purpose and Overview When creating a custom ring tone, you have simple aspirations: to make your phone cooler than everyone else's. Perhaps you need a louder ringer. Perhaps you w…
Almost all Internet protocol telephones have built-in switches at the back that allow you to connect your personal computer to one port and use the other port to connect your phone to to a Cisco switch.   Why we need to connect the PC to the pho…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video discusses moving either the default database or any database to a new volume.

706 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now