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 / apc-switched-pdu-hybrid-outlet-status.pl < prev    next >
Perl Script  |  2008-04-24  |  3KB  |  125 lines

  1. #!/usr/bin/perl 
  2.  
  3. # requires APC MIB file, which is available for download from APC's web site
  4.  
  5. # this script will first attempt to use SNMP to send power control commands,
  6. # and then fail back to using SSH
  7.  
  8. use strict;
  9. use Getopt::Long;
  10. use File::Find;
  11. use File::Path;
  12. use POSIX qw(setsid);
  13. use Socket;
  14.  
  15. my $host;
  16. my $ssh_user;
  17. my $ssh_pass; 
  18. my $snmp_user;
  19. my $snmp_pass;
  20. my $outlet;
  21.  
  22. my $snmp_command;
  23.  
  24. &process_args;
  25.  
  26. $snmp_command = "snmpget -v3 -a MD5 -l authNoPriv -u $snmp_user -A $snmp_pass -m \"/var/lib/filesystems/powernet387.mib\" $host PowerNet-MIB::rPDUOutletControlOutletCommand.$outlet";
  27.  
  28. my $snmp_output = `$snmp_command 2>&1`;
  29. if ( $? == 0 )
  30. {
  31.    if($snmp_output =~ /immediateOn/)
  32.    {
  33.       print "On\n";
  34.    }
  35.    elsif($snmp_output =~ /immediateOff/)
  36.    {
  37.       print "Off\n";
  38.    }
  39.    else
  40.    {
  41.       print "Unknown\n";
  42.    }
  43.  
  44.    exit 0;
  45. }
  46.  
  47. # no fall back to ssh implemented in this script
  48.  
  49. print "Error: failed to contact APC unit.\n";
  50. print "SNMP output: $snmp_output";
  51. print "SSH unsupported in this utility.\n";
  52.  
  53. exit 1;
  54.  
  55. sub process_args
  56. {
  57.    # Parse the command line options
  58.    # For a description of the command line options see &print_help
  59.    use vars qw( $opt_help $opt_host $opt_ssh_user $opt_ssh_pass $opt_snmp_user $opt_snmp_pass $opt_outlet);
  60.  
  61.    Getopt::Long::Configure( "no_ignore_case", "bundling");
  62.    GetOptions( "help",
  63.                "host=s",
  64.                "ssh-user=s",
  65.                "ssh-pass=s",
  66.                "snmp-user=s",
  67.                "snmp-pass=s",
  68.                "outlet=i");
  69.  
  70.    if ($opt_help)
  71.    {
  72.       &print_help;
  73.       exit(0);
  74.    }
  75.  
  76.    if(!$opt_host || !$opt_ssh_user || !$opt_ssh_pass || 
  77.       !$opt_snmp_user || !$opt_snmp_pass || !$opt_outlet)
  78.    {
  79.       &print_help;
  80.       die "Error: missing arguments.\n";
  81.    }
  82.  
  83.    $host = $opt_host;
  84.    $ssh_user = $opt_ssh_user;
  85.    $ssh_pass = $opt_ssh_pass; 
  86.    $snmp_user = $opt_snmp_user;
  87.    $snmp_pass = $opt_snmp_pass;
  88.    $outlet = $opt_outlet;
  89. }
  90.  
  91.  
  92. # --------------- print help information ------------------------------
  93. sub print_help {
  94.  
  95.    print <<EOF;
  96.  
  97. This script will check the status of a single outlet on an APC power strip.  
  98. It will only attempt communication via SNMP at this time (although it accepts
  99. arguments for ssh authentication for future use).
  100.  
  101. usage: apc-switched-pdu-hybrid-outlet-status.pl <options>
  102.  
  103. options:
  104.    --help                   print this help and exit
  105.    --host        <STRING>   hostname of APC unit
  106.    --ssh-user    <STRING>   ssh username for APC unit
  107.    --ssh-pass    <STRING>   ssh password for APC unit
  108.    --snmp-user   <STRING>   SNMP username for APC unit
  109.    --snmp-pass   <STRING>   SNMP authentication pass phrase (MD5) for APC unit
  110.    --outlet      <INTEGER>  APC outlet to control
  111.  
  112. EOF
  113. }
  114.  
  115. # Local variables:
  116. #  c-basic-offset: 3
  117. #  perl-indent-level: 3
  118. #  tab-width: 3
  119. #  indent-tabs-mode: nil
  120. #  shiftwidth: 3
  121. # End:
  122. #
  123. # vim: ts=3 expandtab
  124.  
  125.