[asterisk-ha-clustering] Hi all

Matt Riddell matt at venturevoip.com
Sun Jan 6 19:35:53 CST 2008


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Just thought I'd post little bits of what we do so far:

It kinda wouldn't work unless you have the same routing and billing, but
here goes:

#!/usr/bin/php -q
<?php

function is_alive($server, $type){
  if($server == NULL || $type == NULL)
    return false;
  $ping = "/usr/sbin/asterisk -rx '".$type." show peer ".$server."' |
grep -a Status";
  $output;
  $retval = 0;
  exec($ping,$output,$retval);
  return is_string(strstr($output[0], "OK"));
}

$db_name="cdr";
$db_user="xxx";
$db_pass="xxx";
$connection = mysql_connect("data.venturevoip.com",$db_user, $db_pass);
mysql_select_db($db_name, $connection);

$result = mysql_query("select * from providers where active<>0");

while($row = mysql_fetch_row($result)){
  if($row[7] != NULL){
    $server = $row[5];
    if($row[8] != NULL)
      $server = $row[8];
    $alive = is_alive(str_replace(" ", '', strtolower($server)),$row[7]);

    if($alive === TRUE && $row[2] === "2"){
      echo "Changing provider ".$row[1]." to avaliable\n";
      $query = "update providers set active = 1 where providerid like
".$row[0];
      mysql_query($query) or die(mysql_error());
    }else if ($alive === FALSE && $row[2] === "1"){
      echo "Changing provider ".$row[1]." to unavaliable\n";
      $query = "update providers set active = 2 where providerid like
".$row[0];
      mysql_query($query) or die(mysql_error());
    }else{
      echo "Nothing to change for ".$row[1]." ($row[0]) - ALIVE: $alive\n";

    }
  }
}
?>

Sorry about the word wrapping!

Basically we have a few tables:

sellrates - price each destination is sold for to the customer - one
entry per destination

rates - every provider's destination and price (including profit and
exchange rates where applicable). Each rate also has a weight (for
reducing or increasing the likelihood that a particular rate will be
chosen).

providers - the provider table specifies the contact details for each
provider, the type of peer (iax or sip), and the peer name that they are
shown as.  It also contains a status flag (0 for leave off we don't want
to use this provider at this time, 1 for active but check them once a
minute and 2 for active but because they are currently unreachable don't
use them).

We then run two scripts, one for routing and one for billing.  The
routing script first finds the price from sellrates and saves it to a
channel variable.  This is the price the customer will be charged for
the call (no matter how much it costs us).

We then look through the providers and find which are active (status=1).

We then get the longest match on the phone number from each provider
(i.e. if I dial 6434742112 <http://www.snapanumber.com/> a New Zealand
provider may be able to match 6434 whereas a US based provider will
probably only match 64).

Once we have this collection of rates from each provider we first remove
any which have a weight higher than the lowest rate we found.

So for example:

Provider 1: weight 80 cost $2
Provider 2: weight 80 cost $3
Provider 3: weight 90 cost $0.01

So, we are then left with just Provider 1 and Provider 2 (even though
Provider 3 is cheaper, we know they are not good at providing that rate
- - either because the ping time is too high or there is packet loss/echo).

Final step is to chose the actual provider to use.  Since we just have a
rate at $2 and a rate at $3 we would chose the $2 rate.

The call is made via Provider 1.

In the h extension we run deadagi with the billing script.

It takes the channel variable that was set for pricing at the beginning,
works out how the channel ended and charges the customer's account.

That's the basics of it, there is also call length limiting and realtime
updating of customer balances but I won't go in to that.

Hope that makes a bit of sense!

 :)

Oh, and each of our customers is connected to each server, and each
server is running this script every minute, so even if one of our
servers is unable to complete the call, chances are another will.

Final fall back is that each server has PRI.  Obviously we would prefer
not to be using the PRI for international calls as we lose money on that
but the call has to go through whether our providers have problems or not.

- --
Kind Regards,

Matt Riddell
Director
_______________________________________________

http://www.venturevoip.com (Great new VoIP end to end solution)
http://www.venturevoip.com/news.php (Daily Asterisk News - html)
http://www.venturevoip.com/newrssfeed.php (Daily Asterisk News - rss)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFHgYH5DQNt8rg0Kp4RAj6NAJwNzZWj/Uk+T+H3ECpd4RFDEWAyvQCgpvXZ
rGVNJDOOPWl7SH72FbNX5S4=
=FnyY
-----END PGP SIGNATURE-----



More information about the asterisk-ha-clustering mailing list