Advertisement
mezantrop

hcs_hosts2ldevs-1.1.ps1

Dec 18th, 2016
311
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. #
  13. # v1.0  2016.11.30  Initial release
  14. # v1.1  2016.12.16  Storage serial and model/type added
  15.  
  16. # Usage:
  17. # 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
  18.  
  19.  
  20. # Defaul values ---------------------------------------------------------------
  21. param (
  22.     [string]$hcs_host = "hcs8.server.name",
  23.     [string]$hcs_user = "system",
  24.     [string]$hcs_pass = "manager",
  25.     [string]$hcs_cli = "C:\HCS_CLI\HiCommandCLI.bat",
  26.     [string]$out_csv = "HCS-Hosts2LDEVs.csv"
  27. )
  28.  
  29. # -----------------------------------------------------------------------------
  30. $hcs_url="http://" + $hcs_host + ":2001/service"
  31.  
  32. Write-Host "Querying HCS data. You have time for a cup of coffee"
  33.  
  34. $flist = & $hcs_cli $hcs_url GetHost "subtarget=LogicalUnit" -u $hcs_user -p $hcs_pass |
  35.     where {$_ -cmatch "name=|capacityInKB=|osType=|instance|WWN=|displayName=|emulation=|consumedCapacityInKB|commandDevice|arrayGroupName|raidType|externalVolume|dpType|dpPoolID|objectID"}
  36.  
  37. Write-Host "Processing HCS data. Keep calm and enjoy your drink"
  38. $i = 0
  39. Add-Content $out_csv "Hostname,Host capacity (MB),OS,WWN,LDEV,LDEV capacity (MB),Storage System SN,Storage System Type,LDEV Used (MB),Emulation,Array Group,RAID level,Command Device,External,DP Type,DP Pool ID"
  40. foreach ($ln in $flist) {
  41.  
  42.     # Show some progress indication
  43.     $i += 1
  44.     if ($i % 10000 -eq 0) {
  45.         Write-Host Row $i : $flist.Length processed
  46.     }      
  47.    
  48.     # Split every line to fetch 'variable' and 'value' parts
  49.     $hash=$ln.Trim().Split('=')
  50.  
  51.     # Fetch Host/WWN/LDEV data and combine everything together to prepare normal table format
  52.     switch ($hash[0]) {
  53.         "An instance of Host" {
  54.             if ($LUN -ne "") {
  55.                 $LUNs += $LUN + $SS + $ST + $LUsed + $Emul + $RG + $RGLvl + $CMDDev + $Ext + $DPType + $DPPool
  56.             }
  57.            
  58.             foreach ($wc in $WWNs) {
  59.                 foreach ($lc in $LUNs) {
  60.                     if ("$Hst$OS$wc$lc" -ne "") {
  61.                         Add-Content $out_csv $Hst$OS$wc$lc
  62.                     }
  63.                 }
  64.             }
  65.  
  66.             # Clean variables for the next host
  67.             $Hst = ""
  68.             $LUN = ""
  69.             $OS = ","
  70.             $Emul = ",";
  71.            
  72.             $WWNs = @()
  73.             $LUNs = @()
  74.            
  75.             # We are at Host Level: 0
  76.             $l = 0
  77.             break
  78.         }
  79.        
  80.         "name" {
  81.             $Hst += $hash[1]
  82.             break
  83.         }
  84.  
  85.         "capacityInKB" {
  86.             # Capacity can be found on Level 0 and Level 2
  87.             switch ($l) {
  88.                 0 {$Hst += "," + $hash[1].Replace(".", "")/1024; break}
  89.                 2 {$LUN += "," + $hash[1].Replace(".", "")/1024; break}
  90.             }              
  91.         }
  92.  
  93.         "osType" {
  94.             $OS = "," + $hash[1]
  95.             break
  96.         }
  97.        
  98.         "An instance of WWN" {
  99.             # Go down to WWN Level: 1
  100.             $l = 1
  101.             break
  102.         }
  103.  
  104.         "WWN" {
  105.             $WWNs += "," + $hash[1].Replace(".", ":").ToLower()
  106.             break
  107.         }
  108.        
  109.         "An instance of LogicalUnit" {
  110.             if ($LUN -ne "") {
  111.                 $LUNs += $LUN + $SS + $ST + $LUsed + $Emul + $RG + $RGLvl + $CMDDev + $Ext + $DPType + $DPPool
  112.                 $LUN = ""; $SS = ""; $ST = ""; $Emul = ","; $LUsed = ","; $CMDDev = ","; $RG = ","
  113.                 $RGLvl = ","; $Ext = ","; $DPType = ","; $DPPool = ","
  114.             }
  115.            
  116.             # We are finally at LDEV Level 2 deep
  117.             $l = 2
  118.             break
  119.         }
  120.        
  121.         "displayName" {
  122.             $LUN += "," + $hash[1]
  123.             break
  124.         }
  125.         "objectID" {
  126.             if ($l -eq 2) {
  127.             # Storage serial
  128.                 $SS = "," + $hash[1].Split('.')[2]
  129.             # Storage type/model
  130.                 $ST = "," + $hash[1].Split('.')[1]
  131.             }
  132.             break
  133.         }
  134.        
  135.         "emulation" {
  136.             $Emul = "," + $hash[1]
  137.             break
  138.         }
  139.        
  140.         "commandDevice" {
  141.             switch ($hash[1]) {
  142.                 "false" {$CMDDev = "," + "0"}
  143.                 "true" {$CMDDev = "," + "1"}
  144.             }
  145.             #$CMDDev = "," + $hash[1]
  146.             break
  147.         }
  148.        
  149.         "arrayGroupName" {
  150.             $RG = "," + $hash[1]
  151.             break
  152.         }
  153.        
  154.         "raidType" {
  155.             $RGLvl = "," + $hash[1]
  156.             break
  157.         }
  158.        
  159.         "consumedCapacityInKB" {
  160.             $LUsed = "," + $hash[1].Replace(".", "")/1024
  161.             break
  162.         }
  163.        
  164.         "externalVolume" {
  165.             $Ext = "," + $hash[1]
  166.             break;
  167.         }
  168.        
  169.         "dpType" {
  170.             $DPType = "," + $hash[1]
  171.             break
  172.         }
  173.        
  174.         "dpPoolID" {
  175.             $DPPool = "," + $hash[1]
  176.             break
  177.         }
  178.     }  
  179. }
  180.  
  181. # Must process final line as it was not created by the main loop
  182. if ($LUN -ne "") {
  183.     $LUNs += $LUN + $SS + $ST + $LUsed + $Emul + $RG + $RGLvl + $CMDDev + $Ext + $DPType + $DPPool
  184. }
  185.  
  186. foreach ($wc in $WWNs) {
  187.     foreach ($lc in $LUNs) {
  188.         Add-Content $out_csv $Hst$OS$wc$lc
  189.     }
  190. }
  191.  
  192. Write-Host "Done."
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement