Friday 21 August 2015

PowerCLI to check cross-connect active path correct for VPLEX

Usually hosts set their active path correctly from the disk nearest to the host, but sometimes they need help.  This script will email any paths on any hosts that are wrong.

Assumptions are that you have Site1 and Site2 in the hostnames.  PowerPath is the default path selection method, and it reports CL1 for cluster1 and CL2 for cluster2.   Hostname pattern is near script (I couldn't get it passed as a variable, let me know if you see how to fix that for us all).  
________________________________________________________________

Add-PSSnapin VMware.VimAutomation.Core
Connect-VIServer vSphere -User DOM\powercli -Password password -Force
#
#disConnect-VIServer vSphere -confirm:$false
#
#
#SiteA
#SiteA runs on AMP Element MgrA and checks for CL1
$bldghost = "SiteA*"

$correctcluster = "CL2"
$correctcluster = "CL1"

#SiteB
#SiteB runs on AMP Element MgrB and checks for CL2
###$bldghost = "SiteB*"
###$correctcluster = "CL2"

$allhosts = Get-VMHost "SiteA*"

foreach ($esx in Get-VMHost "SiteA*")


{

#write-host "$esx is esxhost"
### PowerPath command rpowermt , then grabbing asb:prox and CL1 or CL2
$wrongpath = rpowermt username=root password=password host=$esx display dev=all | out-string -stream | select-string "asb:prox" | out-string -stream | select-string $correctcluster

### if this variable exists, then it means we have a problem & need an email alert
if ($wrongpath) 

{

#write-host $wrongpath is wrongpath

#write-host vBlock cross connect path wrong for $esx as $bldghost asb:proxy needs to be set to
#$wrongpath

$wrongpathandesx = "
$esx host
=================================================================================
$wrongpath

"
$errormail += $wrongpathandesx

$errorcheck += $wrongpath

}

else 

{

write-host "cluster $correctcluster for active path is correct for asb:proxy cross-connect VPLEX luns on $esx"

}

}

### get Email info from vCenter
$vCenterSettings = Get-View -Id 'OptionManager-VpxSettings'
$MailSender1 = $env:computername+'.uk01.apmn.org'
$MailSender = "vBlock_AMP_ArrayMgr@$MailSender1"
$MailSmtpServer = ($vCenterSettings.Setting | Where-Object { $_.Key -eq "mail.smtp.server"}).Value
$MailSendingTo = "email@email.com"


#write-host $MailSender1 is MailSender1 and $MailSender is MailSender

if ($errorcheck) 

{

#$mailtext = $errormail | Format-List

$emailbody2 = "RDP to $MailSender1 as these active paths should be set to $correctcluster and need the rpowermt set path_latency_monitor and set autostandby=reinitialize commands ran from CLI after sVMotioning to the host to create traffic

$errormail"

$emailbody0 = '<pre>{0}</pre>' -f [System.Net.WebUtility]::HtmlEncode($emailbody2) 


Send-MailMessage -from $MailSender -to $MailSendingTo -subject "alert: VPLEX cross-connect active paths wrong" -body $emailbody0 -BodyAsHtml -smtpServer $MailSmtpServer


}

else

{


$emailbody2 = "cluster $correctcluster for active path is correct for asb:proxy cross-connect VPLEX luns for $bldghost hosts:

$allhosts"

write-host $emailbody2

Send-MailMessage -from $MailSender -to $MailSendingTo -subject "ok: VPLEX cross-connect active paths good" -body $emailbody2 -smtpServer $MailSmtpServer

}

disConnect-VIServer vSphere -confirm:$false

No comments:

Post a Comment