39 lines
960 B
Perl
39 lines
960 B
Perl
#!/usr/bin/perl
|
|
#
|
|
# lvs.alert - Linux Virtual Server alert for mon
|
|
#
|
|
# It can be activated by mon to remove a real server when the
|
|
# service is down, or add the server when the service is up.
|
|
#
|
|
#
|
|
use Getopt::Std;
|
|
getopts ("s:g:h:t:l:P:V:R:W:F:u");
|
|
|
|
$ipvsadm = "/sbin/ipvsadm";
|
|
$protocol = $opt_P;
|
|
$virtual_service = $opt_V;
|
|
$remote = $opt_R;
|
|
|
|
if ($opt_u) {
|
|
$weight = $opt_W;
|
|
if ($opt_F eq "nat") {
|
|
$forwarding = "-m";
|
|
} elsif ($opt_F eq "tun") {
|
|
$forwarding = "-i";
|
|
} else {
|
|
$forwarding = "-g";
|
|
}
|
|
|
|
if ($protocol eq "tcp") {
|
|
system("$ipvsadm -a -t $virtual_service -r $remote -w $weight $forwarding");
|
|
} else {
|
|
system("$ipvsadm -a -u $virtual_service -r $remote -w $weight $forwarding");
|
|
}
|
|
} else {
|
|
if ($protocol eq "tcp") {
|
|
system("$ipvsadm -d -t $virtual_service -r $remote");
|
|
} else {
|
|
system("$ipvsadm -d -u $virtual_service -r $remote");
|
|
}
|
|
};
|