Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Computing > Cisco > Cisco CSS load balance weighted round-robin perl script

Reply
Thread Tools

Cisco CSS load balance weighted round-robin perl script

 
 
Michael Osten
Guest
Posts: n/a
 
      02-14-2007
For the archives, and since I didn't find anything when I searched for
it. I wrote this script to log into our Cisco CSS 11503 and change
the weight of each service so that when a machine is in trouble,
traffic is directed away from it to the under utilized machines.

Cisco CSS load balance weighted round-robin perl script - download
here: http://www.bleepyou.com/wordpress/?p=12

#!/usr/bin/perl

use Sys::Hostname;
use POSIX qw(setsid);
use Net::SNMP;
use Net::Telnet;

chdir `/’;
umask 0;
open STDIN,`/dev/null’;
open STDERR,`>/dev/null’;
defined(my $pid = fork);
exit if $pid;
setsid;

while(1) {
###Do the below every minute

sleep 60;

###This connects to each host and gets the 1 minute load average via
snmp, you need snmp install ###and configured on each host of course.
You will need one of ###these for each host behind the ###CSS. This
give an example of 2 machines behind the CSS, but of course you can
have more by ###duplicating the sections of code below and changing
the variables.

my ($session, $error) = Net::SNMP->session(
-hostname => shift || `192.168.0.1′ ,
-community => shift || `public’,
-port => shift || 161
);

if (!defined($session)) {
printf(”ERROR: %s.\n”, $error);
}

my $sysUpTime = ‘.1.3.6.1.4.1.2021.10.1.3.1′;

my $result = $session->get_request(
-varbindlist => [$sysUpTime]
);

if (!defined($result)) {
printf(”ERROR: %s.\n”, $session->error);
$session->close;
}
$sc = (”%s”, $result->{$sysUpTime});
$session->close;

my ($session, $error) = Net::SNMP->session(
-hostname => shift || ‘192.168.0.2′,
-community => shift || ‘public’,
-port => shift || 161
);

if (!defined($session)) {
printf(”ERROR: %s.\n”, $error);
}

my $sysUpTime = ‘.1.3.6.1.4.1.2021.10.1.3.1′;

my $result = $session->get_request(
-varbindlist => [$sysUpTime]
);

if (!defined($result)) {
printf(”ERROR: %s.\n”, $session->error);
$session->close;
}
$sc = (”%s”, $result->{$sysUpTime});
$session->close;

##This is the load value when your servers get freaky and start
malfunctioning.

$loadvalue = “7.00″;

if ($sc > $loadvalue){
$scweight = “1″;
}
if ($sc <= $loadvalue){
$scweight = “10″;
}

###This is where it logs into the CSS and sets the weight for the
service for this machine.

open(SC, “</tmp/sc.status”);
chomp($line = <SC>);
close SC;
if ($line eq $scweight){
print “SC: Do Nothing\n”;
}
if ($line ne $scweight){
print “SC: Do Something\n”;
open(SC, “>/tmp/sc.status”);
print SC “$scweight”;
close SC;
###Start the CSS login and do stuff
$host = “css.domain.com”;
$login = “Username”;
$password = “Password”;
#
$t = new Net::Telnet (Timeout => 10, Prompt => ‘/ $/’);
$t->open($host);
$t->login(’Username’, ‘Password’);
$t->cmd(”conf t”);

#machine 1 smtp port 25
$t->cmd(”service smtp”);
$t->cmd(”weight $scweight”);

#machine 1ftp port 21
$t->cmd(”service ftp21″);

#machine 1 http port 80
$t->cmd(”service http”);
$t->cmd(”weight $scweight”);

#machine 1 pop3 port 110
$t->cmd(”service pop3″);
$t->cmd(”weight $scweight”);

#machine 1imap port 143
$t->cmd(”service imap”);
$t->cmd(”weight $scweight”);

#machine 1 https port 443
$t->cmd(”service ssl”);
$t->cmd(”weight $scweight”);
}

###Change the CSS for machine 2

open(TI, “</tmp/ti.status”);
chomp($line = <TI>);
close TI;
if ($line eq $tiweight){
print “TI: Do Nothing\n”;
}
if ($line ne $tiweight){
print “TI: Do Something\n”;
open(TI, “>/tmp/ti.status”);
print TI “$tiweight”;
close TI;
##Start the CSS login and do stuff
$host = “css.domain.com”;
$login = “Username”;
$password = “Password”;
$t = new Net::Telnet (Timeout => 10, Prompt => ‘/ $/’);
$t->open($host);
$t->login(’Username’, ‘Password’);
$t->cmd(”conf t”);

#machine 2 ftp port 20
$t->cmd(”service ftp20″);
$t->cmd(”weight $tiweight”);

#machine 2 smtp port 25
$t->cmd(”service smtp”);
$t->cmd(”weight $tiweight”);

#machine 2 ftp port 21
$t->cmd(”service ftp21″);
$t->cmd(”weight $tiweight”);

#machine 2 http port 80
$t->cmd(”service http”);
$t->cmd(”weight $tiweight”);
#machine 2 pop3 port 110
$t->cmd(”service pop3″);
$t->cmd(”weight $tiweight”);

#machine 2 imap port 143
$t->cmd(”service imap”);
$t->cmd(”weight $tiweight”);

#machine 2 https port 443
$t->cmd(”service ssl”);
$t->cmd(”weight $tiweight”);

}

}

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
weighted mean; weighted standard error of the mean (sem) C Barrington-Leigh Python 1 09-10-2010 02:03 AM
Life Balance Coaching: Balance Work And Life Like A Pro 88059355 Digital Photography 1 01-06-2008 07:32 PM
Minimum (Cisco, obsolete) HW/SW for UBRL, QoS, Fairness, Weighted Fairness experimentation Jeff Miller Cisco 4 03-24-2007 11:30 AM
CSS load balance to multiple ports? Jeff Cisco 1 11-16-2003 03:13 PM
Affects of a PL filter on white balance and white balance (D100) jeff liss Digital Photography 1 09-05-2003 02:07 PM



Advertisments