Sunday, 24 March 2013

AIX: Finding your HMC the easy way


If you have a large IBM System p environment with several HMC's it can be challenging to find which HMC manages any given LPAR.

It is usually possible to find out the HMC that manages the LPAR from the actual LPAR using the lsrsrc IBM.ManagementServer command (or lsrsrc IBM.MCP on AIX 7), however this has a couple of drawbacks.    The biggest drawback is if you are getting paged in the middle of the night because an LPAR just went down, you are obviously not going to be able to login to the LPAR to run this command to find the HMC.    Even if the LPAR is up and running the lsrsrc IBM.ManagementServer (or lsrsrc IBM.MCP on AIX 7) might not work if the RMC connection to the LPAR isn't working correctly. 


Below is script that will connect to your HMC's and build a HTML website that lists all your managed systems and all of the LPAR's on each managed system.   You could set this script up to run every day through cron and redirect the HTML output to a file served up by a webserver.   You would then be able to go to this page at any time to get up to date information on which LPAR's are on which managed systems/HMC's.   The output also includes a link to the HMC web interface.    Using your web browser you can easily search the page to find any LPAR you are looking for.

You need to create a text file that contains a list of all your HMC servers, one per line.   The server you are running the script from must have SSH keys setup to each HMC server.   In this example the file name is hmcservers.txt



$ cat hmcservers.txt 
testhmc01
testhmc02



You then run the script with the HMC list text file as an argument.   Since the output of the script is HTML, you should redirect the output to a .html file



 ./hmcreport.pl hmcservers.txt > hmcreport.html


If you open the hmcreport.html in a web browser, you will see a list of all managed systems on each HMC and a list of LPAR's on each managed system (example screenshot below).   From the web browser you can easily search for a specific LPAR or managed system.


image






































Here is the script to produce the HTML report:


#!/usr/bin/perl
use strict;

my ($inputfile, $hmcserver, @systems, $systemline, $system, @lpars, $lpar, $lparline);

if ($#ARGV == 0){
  $inputfile = $ARGV[0];
}else{
  print "You must specify a text input file that contais a list of HMC's as an argument.\n\n";
  exit 2;
}

open INPUT, "< $inputfile" or die "Unable to open file $inputfile\n";

print "<HTML>\n<BODY>\n";

while (<INPUT>){
  $hmcserver = $_;
  chomp($hmcserver);

  print "<TABLE bgcolor=\"F0FFF0\" border=\"3\">\n";
  print "<tr><th width=\"400\"><h3><a href=\"https://$hmcserver\">$hmcserver</a></h3>\n";

  @systems = `ssh -o "BatchMode yes" -q $hmcserver lssyscfg -r sys -F "name,state" | sort`;
  foreach $systemline (@systems){
    chomp ($systemline);
    if ($systemline =~ /(\S+),Operating/){
      $system = $1; 
      print '<center><table cellpadding="2" border="2" bordercolor="#000000" cellspacing="0">'; 
      print "\n<tr><th bgcolor=\"00BFFF\" width=\"350\">\n";
      print "$system\n";
      print "</tr></th>\n";
      @lpars = `ssh -o "BatchMode yes" -q $hmcserver lssyscfg -m $system -r lpar -F "name,state" | sort`;
      foreach $lparline (@lpars){
        chomp($lparline);
        if ($lparline =~ /(\S+),Running/){
          $lpar = $1;
          print "<tr><td bgcolor=\"FFFAFA\">$lpar</td></tr>";
        }
      }
      print "</center></table>\n";
      print "<br/><br/>";
    }
  }
  print "</table>\n<br/><br/>";
}

print "</BODY>\n</HTML>\n";




Courtesy :https://www.ibm.com/developerworks/mydeveloperworks/blogs/brian/entry/aix_finding_your_hmc_the_easy_way11?lang=en

No comments:

Post a Comment