On Thu, 19 Jan 2006, Laurentiu STEFAN wrote:

Se gaseste pe net un script care sa testeze ISP-urile si daca unu din ele nu 
merge sa trimita pachetele pe ISP-ul celalalt?

Teoretic este:
ISP1 - Retea 1
ISP2 - Retea 2
Dar, daca pica unu din ISP-uri, ambele retele sa iasa pe un singur ISP...

Multumesc anticipat.
_______________________________________________
RLUG mailing list
[email protected]
http://lists.lug.ro/mailman/listinfo/rlug


e facut wrap, dar merge :)


#!/usr/bin/perl

# Run from cron (set with "crontab -e")
# example: "0-59/2 * * * * /path/to/switchisp" runs this every 2 minutes

# Best IPs to test for general use may be last IPs at ISPs before routing out to Net
# Best IP to test if a single remote site is most important is that site's

# If perl not at /usr/bin/perl change first line to point to it

# Before running install Net::Ping from http://freeware.roobik.com/netping/
# (untar, cd to directory, "perl Makefile.PL; make; make install")
# or perl -MCPAN -eshell and install Net::Ping
# This script is NOT Copyrighted :)

use Net::Ping;

# User settings
# _____________

$ip = "/sbin/ip";  # Location of "ip" on system

$gw1 = "gw1";  # Gateway 1 IP
$dev1 = "eth1";  # Device (e.g., eth2)
$tip1 = "ispip1";  # Upstream IP to test
$src1 = "src1";  # Source address for outgoing packets
$wei1 = "1";  # Weight

$gw2    = "gw2";     # Gateway 2 IP
$dev2   = "eth2";               # Device (e.g., eth1)
$tip2   = "ispip2";    # Upstream IP to test
$src2   = "src2";     # Source address for outgoing packets
$wei2   = "2";                  # Weight


$pings  = "4";                  # Number of pings to send
$good   = "2";                  # Number of pings that must be good

$tab    = "default";            # Table to set routes in

$logfile = "/var/log/checkroutes.log"; # File to log messages to


# create timestamp for log
# ________________________

sub TimeStamp {

        # subroutine to create a "nice" looking timestamp
        # that doesn't rely on the system's 'date' command

        my @days = ('Sun','Mon','Tue','Wed','Thu','Fri','Sat');
my @months = ('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep',
                'Oct','Nov','Dec');

my ($sec,$min,$hour,$dom,$mon,$year,$wday,$yday,$isd) = localtime(time); my $timestamp = sprintf("%3s %3s %02d %4d %02d:%02d:%02d", $days[$wday],
                $months[$mon], $dom, $year+1900, $hour, $min, $sec);

        return $timestamp;
}

# be sure routes are set via appropriate gateways to test IPs
# ___________________________________________________________

$checkro = `$ip ro ls`;
if (!($checkro =~ /$tip1/)) {
        system ("$ip ro add to $tip1 via $gw1 src $src1");
}
if (!($checkro =~ /$tip2/)) {
        system ("$ip ro add to $tip2 via $gw2 src $src2");
}

# test if $gw1 and/or $gw2 currently in table $tab
# ________________________________________________

$checkgw = qx/$ip ro ls /;

if ($checkgw =~ /$gw1/) {
        $check1 = 1;
} else {
        $check1 = 0;
}

if ($checkgw =~ /$gw2/) {
        $check2 = 1;
} else {
        $check2 = 0;
}

# ping the test IPs $tip1 and $tip2
# _________________________________

$i=0;
$p = Net::Ping->new("icmp");
while ($i < $pings) {
        if ($p->ping($tip1)) {
                $ping1++;
        }
        $i++;
}
$p->close();

if ($ping1 >= $good) {
        $live1 = 1;
} else {
        $live1 = 0;
}

$i=0;
$p = Net::Ping->new("icmp");
while ($i < $pings) {
        if ($p->ping($tip2)) {
                $ping2++;
        }
        $i++;
}
$p->close();

if ($ping2 >= $good) {
        $live2 = 1;
} else {
        $live2 = 0;
}

# If the current default in table $tab does not match the ping results then
# if only one route's test IP is pingable change the default to that route
# or if both test IPs are pingable change the default to use both
# or if neither test IPs are pingable change the default to use both
# (might as well continue to try them, if we're not going anywhere anyway)
# _________________________________________________________________________

# add new default route
# ________________________

        if (($live1 == 1)&&($live2 == 0)) {
system ("$ip route del default;$ip route add default via $gw1;$ip route flush cache");
        } elsif (($live1 == 0)&&($live2 == 1)) {
system ("$ip route del default;$ip route add default via $gw2;$ip route flush cache");
        } else {
system ("$ip route del default;$ip route add default via $gw1;$ip route flush cache");
        }
# log
# ___

if (($live1 == 1)&&($live2 == 1)) {
        $log = "ISP1 is UP, ISP2 is UP";
} elsif (($live1 == 0)&&($live2 == 0)) {
        $log = "ISP1 is DOWN, ISP2 is DOWN (!!BIG FAT WARNING!!)";
} elsif (($live1 == 1)&&($live2 == 0)) {
        $log = "ISP1 is UP, ISP2 is DOWN";
} elsif (($live1 == 0)&&($live2 == 1)) {
        $log = "ISP1 is DOWN, ISP2 is up";
}

open(LOG, ">>$logfile");
print LOG &TimeStamp . " - $log\n";
close(LOG);

------------

e luat de pe net. nu mai stiu exact de unde.




Best regards,

Florin Samareanu
IT Dept.
Ro Group International SRL
Depozitelor St., No. 41-43

Mobile: +40-722388299
Fixed:  +40-248215510




_______________________________________________
RLUG mailing list
[email protected]
http://lists.lug.ro/mailman/listinfo/rlug

Raspunde prin e-mail lui