Daily health checks of SAN devices is one of the boring activities for a SAN admin but it is critical to the team, company and customer. So, how to ensure accurate health checks are performed by the team which is a boring task. I fail-back to automation since I’ve done this in the past and yields better results.
So, What I did to perform Cisco SAN MDS health checks?
Perl is my companion from past few years and I’ve been using it under the guidance of Nagarajan sir. He helped me to kickstart learning Perl. This is an ode to my Guru, Rajan Sir.
Requirements:
- Install Strawberry Perl Downloadable @ http://strawberryperl.com/
- Install Modules Net::SSH2, MIME::Lite and optionally Net:: Telnet [Reference:http://perl.about.com/od/packagesmodules/qt/perlcpan.htm%5D
- Copy scripts and execute 🙂
Advantages:
You can use Perl on heterogeneous OS and coding is simple and easily readable if documented properly 🙂
Please find the script below which is working for Cisco MDS switches. I’ve used basic health check commands according to my requirements. Please feel free to add additional commands and do share with me.
First to begin with you need a text file called as ips.txt in c:\scripts\ [or whatever you like] add all Cisco switches IP address in this file.
E.g: ips.txt
10.10.10.100 10.10.10.101 10.10.10.102
Please copy below code to text file and save as c:\scripts\cisco_hc.pl [or whatever you like]. Open CMD and execute “perl cisco_hc.pl” [without quotes]. If Perl and modules are properly configured, Workstation where Perl is able to communicate SAN switches via SSH and username and password replaced with the one you use then you would get a output file in the same folder with file name “Cisco-<today’s date>.txt”
#!/usr/bin/perl
use Net::SSH2;
use warnings;
use strict;
use diagnostics;
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
my $datestring = sprintf(“%4d_%02d_%02d_%02d”,($year + 1900),($mon+1),$mday,$hour);
my $sw;
use constant BUFLEN => 10_0000 ;
my $user = “Username”;
my $password = “password”;
my $buf;
#get ip’s
# open file
open(FILE, “c:/scripts/ips.txt”) or die(“Unable to open file”);
# read file into an array
my @data = <FILE>;
# print output to file
open OUTPUT, ‘+>’, “Cisco-$datestring.txt” or die $!; # create / open the out.txt for STDOUT redirection
open ERROR, ‘+>’, “err-$datestring.txt” or die $!; # create / open the err.txt for errors redirection
STDOUT->fdopen( \*OUTPUT, ‘w’ ) or die $!; # redirecting the STDOUT to file
STDERR->fdopen( \*ERROR, ‘w’ ) or die $!; # redirecting the errors to file
foreach $sw (@data)
{
my $ssh = Net::SSH2->new();
if(!$ssh->connect($sw)){
print(“Connection Failed\n”);
exit(1);
}
if(!$ssh->auth_password($user,$password)){
print(“Authentication Failed”);
exit(1);
}
print “#####################################################################################\n”;
print “Status report of Cisco Switch with IP:$sw \n”;
print “#####################################################################################\n”;
# Printing clock
print “Switch Time:\n”;
my $channel = $ssh->channel();
my $command = $channel->exec(“show clock”) or die $_;
my $read = $channel->read($buf, BUFLEN );
warn ‘More than ‘, BUFLEN, ‘ characters in listing’ if $read >= BUFLEN;
print “$buf\n”;
# Printing hardware status
$buf =””;
my $channel = $ssh->channel();
my $command = $channel->exec(“sh hardware”) or die $_;
my $read = $channel->read($buf, BUFLEN );
warn ‘More than ‘, BUFLEN, ‘ characters in listing’ if $read >= BUFLEN;
print “$buf\n”;
# Printing fcns database
print “FCNS Database \n”;
$buf =””;
my $channel = $ssh->channel();
my $command = $channel->exec(“sh fcns database”) or die $_;
my $read = $channel->read($buf, BUFLEN );
warn ‘More than ‘, BUFLEN, ‘ characters in listing’ if $read >= BUFLEN;
print “$buf\n”;
# Printing flogi database
print “FLOGI Database \n”;
$buf =””;
my $channel = $ssh->channel();
my $command = $channel->exec(“sh flogi database”) or die $_;
my $read = $channel->read($buf, BUFLEN );
warn ‘More than ‘, BUFLEN, ‘ characters in listing’ if $read >= BUFLEN;
print “$buf\n”;
print “#####################################################################################\n”;
print “END of Report \n”;
print “#####################################################################################\n”;
}
exit;
Benefits:
1. We can schedule the script to run at certain time using Task Scheduler to send out output via emails on regular basis
2. Accurate information received and a copy of output available via emails
3. Free from monotonous tasks
Sample output:
[Note: Trimmed / modified output do not show actual serial / part / etc.. numbers. I’ve randomly typed, removed or replaced them for confidentiality]
#####################################################################################
Status report of Cisco Switch with IP:<IP>
#####################################################################################
Switch Time:
16:02:44.357 CET Sat Jun 22 2013
Cisco Nexus Operating System (NX-OS) Software
TAC support: http://www.cisco.com/tac
Documents: http://www.cisco.com/en/US/products/ps9372/tsd_products_support_series_home.html
Copyright (c) 2002-2012, Cisco Systems, Inc. All rights reserved.
The copyrights to certain works contained herein are owned by
other third parties and are used and distributed under license.
Some parts of this software are covered under the GNU Public
License. A copy of the license is available at
http://www.gnu.org/licenses/gpl.html.
Software
BIOS: version 1.0.19
loader: version N/A
kickstart: version 5.2(6b)
system: version 5.2(6b)
BIOS compile time: 02/01/10
kickstart image file is: bootflash:///m9100-s3ek9-kickstart-mz.5.2.6b.bin
kickstart compile time: 12/25/2020 12:00:00 [12/19/2012 07:08:59]
system image file is: bootflash:///m9100-s3ek9-mz.5.2.6b.bin
system compile time: 10/3/2012 17:00:00 [12/19/2012 08:55:59]
Hardware
cisco MDS 9148 FC (1 Slot) Chassis (“1/2/4/8 Gbps FC/Supervisor-3”)
Motorola, e500v2 with 1036300 kB of memory.
Processor Board ID
Device name: <DeviceName>
bootflash: 1000944 kB
Kernel uptime is 42 day(s), 8 hour(s), 10 minute(s), 49 second(s)
Last reset at 198263 usecs after Sat May 11 07:51:54 2013
Reason: Reset due to upgrade
System version: 5.0(7)
Service:
——————————–
Switch hardware ID information
——————————–
Switch is booted up
Switch type is : MDS 9148 FC (1 Slot) Chassis
Model number is
H/W version is 1.1
Part Number is
Part Revision is A0
Manufacture Date is Year 16 Week 51
Serial number is
CLEI code is CMMFT00ARA
——————————–
Chassis has 1 Module slots
——————————–
Module1 ok
Module type is : 1/2/4/8 Gbps FC/Supervisor-3
0 submodules are present
Model number is
H/W version is 1.1
Part Number is 73-13049-06
Part Revision is A0
Manufacture Date is Year 16 Week 52
Serial number is
CLEI code is CMMFT00ARA
—————————————
Chassis has 2 PowerSupply Slots
—————————————
PS1 ok
Power supply type is: 300.00W 110v/220v AC
Model number is
H/W version is 160.0
Part Number is 341-0320-01
Part Revision is A0
Manufacture Date is Year 16 Week 47
Serial number is
CLEI code is
PS2 ok
Power supply type is: 300.00W 110v/220v AC
Model number is
H/W version is 160.0
Part Number is 341-0320-01
Part Revision is A0
Manufacture Date is Year 16 Week 47
Serial number is
CLEI code is
———————————-
Chassis has 4 Fan slots
———————————-
Fan1 ok
Fan2 ok
Fan3 ok
Fan4 ok
FCNS Database
VSAN 101:
————————————————————————–
FCID TYPE PWWN (VENDOR) FC4-TYPE:FEATURE
————————————————————————–
0x150000 N 20:11:00:05:1e:f8:fc:87
Total number of entries = 50
FLOGI Database
——————————————————————————–
INTERFACE VSAN FCID PORT NAME NODE NAME
——————————————————————————–
0x150000 N 20:11:00:05:1e:f8:fc:87
Total number of flogi = 50.
#####################################################################################
END of Report
#####################################################################################
#####################################################################################
Status report of Cisco Switch with IP:<IP>
#####################################################################################
Switch Time:
15:02:53.452 UTC Sat Jun 22 2013
Cisco Nexus Operating System (NX-OS) Software
TAC support: http://www.cisco.com/tac
Documents: http://www.cisco.com/en/US/products/ps9372/tsd_products_support_series_home.html
Copyright (c) 2002-2012, Cisco Systems, Inc. All rights reserved.
The copyrights to certain works contained herein are owned by
other third parties and are used and distributed under license.
Some parts of this software are covered under the GNU Public
License. A copy of the license is available at
http://www.gnu.org/licenses/gpl.html.
Software
BIOS: version 1.0.19
loader: version N/A
kickstart: version 5.2(6b)
system: version 5.2(6b)
BIOS compile time: 02/01/10
kickstart image file is: bootflash:///m9100-s3ek9-kickstart-mz.5.2.6b.bin
kickstart compile time: 12/25/2020 12:00:00 [12/19/2012 07:08:59]
system image file is: bootflash:///m9100-s3ek9-mz.5.2.6b.bin
system compile time: 10/3/2012 17:00:00 [12/19/2012 08:55:59]
Hardware
cisco MDS 9148 FC (1 Slot) Chassis (“1/2/4/8 Gbps FC/Supervisor-3”)
Motorola, e500v2 with 1036300 kB of memory.
Processor Board ID
Device name:
bootflash: 1000944 kB
Kernel uptime is 42 day(s), 1 hour(s), 9 minute(s), 54 second(s)
Last reset at 778607 usecs after Sat May 11 13:52:57 2013
Reason: Reset due to upgrade
System version: 5.0(7)
Service:
——————————–
Switch hardware ID information
——————————–
Switch is booted up
Switch type is : MDS 9148 FC (1 Slot) Chassis
Model number is
H/W version is 1.1
Part Number is 73-13049-06
Part Revision is A0
Manufacture Date is Year 16 Week 51
Serial number is
CLEI code is CMMFT00ARA
——————————–
Chassis has 1 Module slots
——————————–
Module1 ok
Module type is : 1/2/4/8 Gbps FC/Supervisor-3
0 submodules are present
Model number is
H/W version is 1.1
Part Number is 73-13049-06
Part Revision is A0
Manufacture Date is Year 16 Week 52
Serial number is
CLEI code is CMMFT00ARA
—————————————
Chassis has 2 PowerSupply Slots
—————————————
PS1 ok
Power supply type is: 300.00W 110v/220v AC
Model number is DS-C48-300AC
H/W version is 160.0
Part Number is 341-0320-01
Part Revision is A0
Manufacture Date is Year 16 Week 47
Serial number is PAC16474UX4
CLEI code is
PS2 ok
Power supply type is: 300.00W 110v/220v AC
Model number is
H/W version is 160.0
Part Number is 341-0320-01
Part Revision is A0
Manufacture Date is Year 16 Week 47
Serial number is
CLEI code is
———————————-
Chassis has 4 Fan slots
———————————-
Fan1 ok
Fan2 ok
Fan3 ok
Fan4 ok
FCNS Database
VSAN 100:
————————————————————————–
FCID TYPE PWWN (VENDOR) FC4-TYPE:FEATURE
————————————————————————–
0x140000 N 20:11:00:05:1e:ff:ff:ff
Total number of entries = 53
FLOGI Database
——————————————————————————–
INTERFACE VSAN FCID PORT NAME NODE NAME
——————————————————————————–
0x140000 N 20:11:00:05:1e:ff:fe:fe
Total number of flogi = 53.
#####################################################################################
END of Report
#####################################################################################
Will this script with MDS 9148 switches?
Yes it would work
how to send the output to email id?
not able to run it pls help me out getting error
“C:\Users\127903>perl C:\Users\127903\Desktop\healthcheck.pl
“my” variable $channel masks earlier declaration in same scope at
C:\Users\127903\Desktop\healthcheck.pl line 46 (#1)
(W misc) A “my”, “our” or “state” variable has been redeclared in the
current scope or statement, effectively eliminating all access to the
previous instance. This is almost always a typographical error. Note
that the earlier variable will still exist until the end of the scope
or until all closure references to it are destroyed.
“
Are you using Strawberry Perl
i am able to run it but when i mention multiple IP’s in text file it is showing up as connection failed
Check SSH connectivity and credentials as well
The error which I got .. Someone please help me..
C:\scripts>perl cisco_hc.pl
Unrecognized character \x93; marked by <– HERE after = sprintf(<– HERE near
column 26 at cisco_hc.pl line 7 (#1)
(F) The Perl parser has no idea what to do with the specified character
in your Perl script (or eval) near the specified column. Perhaps you
tried to run a compressed script, a binary program, or a directory as
a Perl program.
Uncaught exception from user code:
Unrecognized character \x93; marked by <– HERE after = sprintf(<– HERE
near column 26 at cisco_hc.pl line 7.
Also to mention .. I have no knowledge on scripting .. I want to use this to enable Cisco MDS automation in my environment ..
1) I copied the script and just replaced my switch username and password.
2) Didnt know how to install perl modules. Came to know that SSH2 module is installed by default.
Hence, I just executed this !!
If I am wrong, please tell me how to use PERL modules too!!