Advertisement
mezantrop

hcs_hosts2ldevs.ps1

Nov 30th, 2016
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # -----------------------------------------------------------------------------
  2. # "THE BEER-WARE LICENSE" (Revision 42):
  3. # zmey20000@yahoo.com wrote this file. As long as you retain this notice you
  4. # can do whatever you want with this stuff. If we meet some day, and you think
  5. # this stuff is worth it, you can buy me a beer in return Mikhail Zakharov
  6. # -----------------------------------------------------------------------------
  7.  
  8. #
  9. # Dump and correlate Hitachi Command Suite Hosts and LDEVs information
  10. #
  11.  
  12. # Usage:
  13. # hcs_hosts2ldevs -hcs_host hcs8.server.name -hcs_user user -hcs_pass password -hcs_cli X:\HCS\CLI\HiCommandCLI.bat -out_csv X:\path\to\your.csv
  14.  
  15. # Defaul values ---------------------------------------------------------------
  16. param (
  17.     [string]$hcs_host = "hcs8.server.name",
  18.     [string]$hcs_user = "system",
  19.     [string]$hcs_pass = "manager",
  20.     [string]$hcs_cli = "C:\HCS_CLI\HiCommandCLI.bat",
  21.     [string]$out_csv = "HCS-Hosts2LDEVs.csv"
  22. )
  23.  
  24. # -----------------------------------------------------------------------------
  25. $hcs_url="http://" + $hcs_host + ":2001/service"
  26.  
  27. Write-Host "Querying HCS data. You have time for a cup of coffee"
  28.  
  29. $flist = & $hcs_cli $hcs_url GetHost "subtarget=LogicalUnit" -u $hcs_user -p $hcs_pass |
  30.     where {$_ -cmatch "name=|capacityInKB=|osType=|instance|WWN=|displayName=|emulation=|consumedCapacityInKB|commandDevice|arrayGroupName|raidType|externalVolume|dpType|dpPoolID"}
  31.  
  32. Write-Host "Processing HCS data. Keep calm and enjoy your drink"
  33. $i = 0
  34. Add-Content $out_csv "Hostname,Host capacity (MB),OS,WWN,LDEV,LDEV capacity (MB),LDEV Used (MB),Emulation,Array Group,RAID level,Command Device,External,DP Type,DP Pool ID"            
  35. foreach ($ln in $flist) {
  36.  
  37.     # Show some progress indication
  38.     $i += 1
  39.     if ($i % 10000 -eq 0) {
  40.         Write-Host Row $i : $flist.Length processed
  41.     }      
  42.    
  43.     # Split every line to fetch 'variable' and 'value' parts
  44.     $hash=$ln.Trim().Split('=')
  45.  
  46.     # Fetch Host/WWN/LDEV data and combine everything together to prepare normal table format
  47.     switch ($hash[0]) {
  48.         "An instance of Host" {
  49.             if ($LUN -ne "") {
  50.                 $LUNs += $LUN + $LUsed + $Emul + $RG + $RGLvl + $CMDDev + $Ext + $DPType + $DPPool
  51.             }
  52.            
  53.             foreach ($wc in $WWNs) {
  54.                 foreach ($lc in $LUNs) {
  55.                     if ("$Hst$OS$wc$lc" -ne "") {
  56.                         Add-Content $out_csv $Hst$OS$wc$lc
  57.                     }
  58.                 }
  59.             }
  60.  
  61.             # Clean variables for the next host
  62.             $Hst = ""
  63.             $LUN = ""
  64.             $OS = ","
  65.             $Emul = ",";
  66.            
  67.             $WWNs = @()
  68.             $LUNs = @()
  69.            
  70.             # We are at Host Level: 0
  71.             $l = 0
  72.             break
  73.         }
  74.        
  75.         "name" {
  76.             $Hst += $hash[1]
  77.             break
  78.         }
  79.  
  80.         "capacityInKB" {
  81.             # Capacity can be found on Level 0 and Level 2
  82.             switch ($l) {
  83.                 0 {$Hst += "," + $hash[1].Replace(".", "")/1024; break}
  84.                 2 {$LUN += "," + $hash[1].Replace(".", "")/1024; break}
  85.             }              
  86.         }
  87.  
  88.         "osType" {
  89.             $OS = "," + $hash[1]
  90.             break
  91.         }
  92.        
  93.         "An instance of WWN" {
  94.             # Go down to WWN Level: 1
  95.             $l = 1
  96.             break
  97.         }
  98.  
  99.         "WWN" {
  100.             $WWNs += "," + $hash[1].Replace(".", ":").ToLower()
  101.             break
  102.         }
  103.        
  104.         "An instance of LogicalUnit" {
  105.             if ($LUN -ne "") {
  106.                 $LUNs += $LUN + $LUsed + $Emul + $RG + $RGLvl + $CMDDev + $Ext + $DPType + $DPPool
  107.                 $LUN = ""; $Emul = ","; $LUsed = ","; $CMDDev = ","; $RG = ","
  108.                 $RGLvl = ","; $Ext = ","; $DPType = ","; $DPPool = ","
  109.             }
  110.            
  111.             # We are finally at LDEV Level 2 deep
  112.             $l = 2
  113.             break
  114.         }
  115.        
  116.         "displayName" {
  117.             $LUN += "," + $hash[1]
  118.             break
  119.         }
  120.        
  121.         "emulation" {
  122.             $Emul = "," + $hash[1]
  123.             break
  124.         }
  125.        
  126.         "commandDevice" {
  127.             switch ($hash[1]) {
  128.                 "false" {$CMDDev = "," + "0"}
  129.                 "true" {$CMDDev = "," + "1"}
  130.             }
  131.             #$CMDDev = "," + $hash[1]
  132.             break
  133.         }
  134.        
  135.         "arrayGroupName" {
  136.             $RG = "," + $hash[1]
  137.             break
  138.         }
  139.        
  140.         "raidType" {
  141.             $RGLvl = "," + $hash[1]
  142.             break
  143.         }
  144.        
  145.         "consumedCapacityInKB" {
  146.             $LUsed = "," + $hash[1].Replace(".", "")/1024
  147.             break
  148.         }
  149.        
  150.         "externalVolume" {
  151.             $Ext = "," + $hash[1]
  152.             break;
  153.         }
  154.        
  155.         "dpType" {
  156.             $DPType = "," + $hash[1]
  157.             break
  158.         }
  159.        
  160.         "dpPoolID" {
  161.             $DPPool = "," + $hash[1]
  162.             break
  163.         }
  164.     }  
  165. }
  166.  
  167. # Must process final line as it was not created by the main loop
  168. if ($LUN -ne "") {
  169.     $LUNs += $LUN + $LUsed + $Emul + $RG + $RGLvl + $CMDDev + $Ext + $DPType + $DPPool
  170. }
  171.  
  172. foreach ($wc in $WWNs) {
  173.     foreach ($lc in $LUNs) {
  174.         Add-Content $out_csv $Hst$OS$wc$lc
  175.     }
  176. }
  177.  
  178. Write-Host "Done."
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement