This program changes the status for a list of Real Servers to maintenance mode. It performs the following functions:
- For each IP address in a list, it sets the status of the Real Server to maintenance. The Barracuda Load Balancer will not direct any new client connections or requests to a Real Server in maintenance mode;
- It displays the Real Server state to confirm that the state has changed.
To run maint.pl, at a command prompt type:perl maint.pl
maint.pl
#!/usr/bin/perl
use strict; use warnings;
use XML::RPC; use LWP::UserAgent;
# Service parameters my $service_ip = '192.168.132.214' ; my $service_protocol = 'TCP' ; my $service_port = '80' ;
# Server parameters my $server_ips = '15.15.15.11,15.15.15.12' ; my $server_port = '80' ;
my $method_change = "server.change_state" ; my $action = 'maintenance' ; #disable/enable/maintenance my $service_id = "$service_ip:$service_port:$service_protocol" ; my @server_ip = split(",",$server_ips); my $service_show = 'status/state' ; my $result;
# Create the XML::RPC objectmy $ua = LWP::UserAgent->new ; $ua->timeout( 60 ); my $xmlrpc = XML::RPC->new ( 'https://10.5.126.63/cgi-mod/api.cgi?password=admin', 'lwp_useragent' => $ua );
#Change Real Server status for the IP addresses in the list#to maintenance mode
my $disable_parameters = { vip => $service_id, port => $server_port, action => $action };
foreach my $ip (@server_ip){ $disable_parameters->{'ip'} = $ip; print "Setting status for server $ip to $action.\n"; $result = $xmlrpc->call($method_change, $disable_parameters ); print "$result->{'msg'}\n";
#Show the Real Server state now $result = $xmlrpc->call( 'service.show', { vip => $service_id, port => $server_port, ip => $ip, show => $service_show } ); my $instance_id = "$ip" . ":" . "$server_port"; print "Server status: $result->{$service_id}{$instance_id}{'state'}\n"; }