We use cookies on our website to ensure we provide you with the best experience on our website. By using our website, you agree to the use of cookies for analytics and personalized content.This website uses cookies. More Information
It seems like your browser didn't download the required fonts. Please revise your security settings and try again.
Barracuda Load Balancer

Sample Program - Changing Real Server Status to Maintenance Mode

  • Last updated on

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.

Edit the IP addresses – should be the WAN IP address of your Barracuda Load Balancer, is the VIP address of an existing Service, and and are the IP addresses of the Real Servers to be put into maintenance mode. You can put more Real Servers in the $server_ips list, just be sure to separate them by a comma (,). Change the password to the API password for the Barracuda Load Balancer.

You can also modify this program to disable the Real Servers or make them active again by changing the value of the $action parameter to disable or enable.

To run maint.pl, at a command prompt type:
perl maint.pl



use strict;
use warnings;

use XML::RPC;
use LWP::UserAgent;

# Service parameters
my $service_ip = '' ;
my $service_protocol = 'TCP' ;
my $service_port = '80' ;

# Server parameters
my $server_ips = ',' ;
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 object
my $ua = LWP::UserAgent->new ;
$ua->timeout( 60 );
my $xmlrpc = XML::RPC->new (
            '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";
  "Server status: $result->{$service_id}{$instance_id}{'state'}\n";


Related Articles
Last updated on