[asterisk-ha-clustering] Hi All
JR Richardson
jmr.richardson at gmail.com
Mon Jan 7 19:32:21 CST 2008
> 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";
>
> }
> }
> }
> ?>
>
Very nice. That is very intense script for each call.
JR
--
JR Richardson
Engineering for the Masses
More information about the asterisk-ha-clustering
mailing list