home *** CD-ROM | disk | FTP | other *** search
/ ftp.parl.clemson.edu / 2015-02-07.ftp.parl.clemson.edu.tar / ftp.parl.clemson.edu / pub / pvfs2 / orangefs-2.8.3-20110323.tar.gz / orangefs-2.8.3-20110323.tar / orangefs / examples / heartbeat / hardware-specific / qla-monitor.pl < prev   
Perl Script  |  2008-04-24  |  2KB  |  98 lines

  1. #!/usr/bin/perl 
  2.  
  3. use strict;
  4. use Getopt::Long;
  5. use File::Find;
  6. use File::Path;
  7. use POSIX qw(setsid);
  8. use Socket;
  9.  
  10. my $device = undef;
  11. my $mon_device = undef;
  12.  
  13. &process_args;
  14.  
  15. # strip path and partition off of device name 
  16. if($device =~ /\/+dev\/+([a-zA-Z]+)[1234567890]*/)
  17. {
  18.    $mon_device = $1;
  19. }
  20. else
  21. {
  22.    print "Error: poorly formated device name.\n";
  23.    exit 1;
  24. }
  25.  
  26. my $devcount = `powermt display dev=$mon_device 2>&1 |grep -c -E "(qla)|(lpfc)"`;
  27. if ($devcount < 1)
  28. {
  29.    print "Error: could not find device $mon_device.\n";
  30.    exit 1;
  31. }
  32. chomp($devcount);
  33.  
  34. my $deadcount = `powermt display dev=$mon_device 2>&1 |grep -E "(qla)|(lpfc)" | grep -c dead`;
  35. chomp($deadcount);
  36.  
  37. if($devcount == $deadcount)
  38. {
  39.    print "Error: all paths for device $device are dead.\n";
  40.    exit 1;
  41. }
  42.  
  43. exit 0;
  44.  
  45. sub process_args
  46. {
  47.    # Parse the command line options
  48.    # For a description of the command line options see &print_help
  49.    use vars qw( $opt_help $opt_device);
  50.  
  51.    Getopt::Long::Configure( "no_ignore_case", "bundling");
  52.    GetOptions( "help",
  53.                "device=s");
  54.  
  55.    if ($opt_help)
  56.    {
  57.       &print_help;
  58.       exit(0);
  59.    }
  60.  
  61.    if($opt_device)
  62.    {
  63.       $device = $opt_device;
  64.    }
  65.    else
  66.    {
  67.       &print_help;
  68.       die "Error: must specify device.\n";
  69.    }
  70. }
  71.  
  72. # --------------- print help information ------------------------------
  73. sub print_help {
  74.  
  75.    print <<EOF;
  76.  
  77. This script will check a QLogic or Emulex SAN device to see if it is operating correctly.
  78.  
  79. usage: qla-monitor.pl --device <SAN device>
  80.  
  81. options:
  82.    --help                        Print this help and exit.
  83.    --device           <STRING>   SAN device (such as /dev/emcpowera1).
  84.  
  85. EOF
  86. }
  87.  
  88. # Local variables:
  89. #  c-basic-offset: 3
  90. #  perl-indent-level: 3
  91. #  tab-width: 3
  92. #  indent-tabs-mode: nil
  93. #  shiftwidth: 3
  94. # End:
  95. #
  96. # vim: ts=3 expandtab
  97.  
  98.