Brocade SAN switches port count

We manage more than 100+ SAN switches in our storage infrastructure. Keeping track of port availability, status and count are hectic capacity management tasks. If we need to get this data manually, we need to login to each switch, run commands, grab output, do the math and tabulate values. Storage admin job is not an easy one to do!!

Using PERL script we can simplify these tasks. Below PERL script would help us to get above information in a matter of seconds. This output can be exported to excel for further beatification 🙂

use Net::SSH2;
use POSIX;
use MIME::Lite;
open (INPUT, "emc_switch_ips.txt");
my @ip =< INPUT>;
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
my $datestring = sprintf("%02d_%02d_%02d_%02d_%4d",$hour,$min,($mon+1),$mday,($year + 1900));
open OUTPUT, '+>', "emc_result-$datestring.txt" or die $!;
STDOUT->fdopen( \*OUTPUT, 'w' ) or die $!; # redirecting the STDOUT to file
open (PASS, "pass");
use constant BUFLEN => 10_0000 ;
my $user = "admin";
my $password = ;
my $cmdlet = ("switchshow | grep id");
foreach $switch(@ip){
chomp($switch);
print "$switch - Total number of ports\n";
my $ssh = Net::SSH2->new();
        if(!$ssh->connect($switch)){
                print("Connection Failed\n");
                exit(1);
        }
        if(!$ssh->auth_password($user,$password)){
                print("Authentication Failed");
                exit(1);
        }
my $channel = $ssh->channel();
my $command = $channel->exec("$cmdlet") or die $_;
	my $read = $channel->read($buf, BUFLEN );
	warn 'More than ', BUFLEN, ' characters in listing' if $read >= BUFLEN;
	print $buf;
	$channel->close;
my @data = split (/\n/,$buf);
$len=@data;
for ($i=0;$i<$len;$i++){
#print "@data[$i] \n";
@on[$i] = grep (/Online/,@data[$i]);
@no[$i] = grep (/No_Light/,@data[$i]);
#print "Online: @on[$i] \n";
#print "Offline: @no[$i] \n";
}

We need to have a text file with SAN switches IP addresses called “emc_switch_ips.txt” also we need to store user password in a file called “pass”. Thats it! go to shell / CMD and execute the file which gives below output.

OUTPUT:
– Total number of ports
0 0 010000 id N8 No_Light FC
1 1 010100 id N8 No_Light FC
2 2 010200 id N8 No_Light FC
3 3 010300 id N8 No_Light FC
4 4 010400 id N8 No_Light FC
5 5 010500 id N8 No_Light FC
6 6 010600 id N8 No_Light FC
7 7 010700 id N8 No_Light FC
8 8 010800 id N8 No_Light FC (No POD License) Disabled
9 9 010900 id N8 No_Light FC (No POD License) Disabled
10 10 010a00 id N8 No_Light FC (No POD License) Disabled
11 11 010b00 id N8 No_Light FC (No POD License) Disabled
12 12 010c00 id N8 No_Light FC (No POD License) Disabled
13 13 010d00 id N8 No_Light FC (No POD License) Disabled
14 14 010e00 id N8 No_Light FC (No POD License) Disabled
15 15 010f00 id N8 No_Light FC (No POD License) Disabled
On-line Ports= 0
Offline Ports= 16
Total Ports = 16
Overall Total On-line Ports = 0
Overall Total Offline Ports = 16
Overall Total Ports = 16

Advertisements

2 thoughts on “Brocade SAN switches port count

  1. Hi Vinay,

    Your articles are really helpful. Cud u help me on the below query?

    C:\test>perl show_switches.pl
    – Total number of ports
    Authentication Failed

    My pl Script is working fine with normal IP but it is throwing error in NAT IP. Is there any pl module to access devices with NAT ips? or How to fix this?

    Grateful if you could mail me on this.

    BR,
    Sathya.
    sathyajithvinu@gmail.com

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s