Powershell–How to query HP smart array for disk health check?
There is no direct Powershell module for HP servers available yet but the CLI tools can help us here. You can also use SCOM where a management is available for HP to monitor health of HP hardware. if you have not SCOM running we can work with Powershell and execute the HP CLI tools and check the reported states of disks
we need some global params a.e. to store in a logfile the results
$localhost="SERVERNAME" Get-item ".\log.txt" -ea 0 | Remove-Item -ea 0 $logfile=".\log.txt" $programpath='C:\Program Files\HP\hpssacli\bin'
we can build a function to be able to call that later in our script:
function CheckSmartArray { Write-Host " " Write-Host "Checking SmartArray on system"$localhost"" -foregroundcolor green C:\Windows\System32\cmd.exe /c "C:\Program Files\HP\hpssacli\bin\hpssacli.exe" controller slot=0 physicaldrive all show }
now do we want to check that daily manually? or would be an automated solution like sending a mail in case of a failure? Ok, lets build the SMTP parameters so we can grab the results from HP CLI
function SentDiskDrivefailedviaMail { $Logs=Get-Content $logfile $smtpServer = "smtp.contoso.com" $smtpFrom = "datacenterteam@contoso.com" $SMTPPort = "25" $Username = "datacenterteam@contoso.com" $Password = "ContosoPassword1" $smtpTo = "datacenterteam@contoso.com" $messageSubject = "Disk Drive failed at $localhost" [string]$messagebody = "" foreach ($log in $logs ) { $messagebody = $messagebody + $log + "`r`n" } Write-Host "Failed Disk found on Server $servername - starting to sent mail to $smtpTo via $smtpServer ...." -ForegroundColor red $smtp = New-Object Net.Mail.SmtpClient($smtpServer) $smtp.Credentials = New-Object System.Net.NetworkCredential($Username, $Password); $smtp.Send($smtpFrom,$smtpTo,$messagesubject,$messagebody) Write-Host "mail sent completed " -ForegroundColor green Write-Host " " }
Now we have 2 functions which can be called and executed, lets finalize the script. first we need to analyze the log for failed disk and if true, build mail object and transfer via SMTP
CheckSmartArray | out-file -filepath $logfile -append [array]$logcontent=gc $logfile foreach ($line in $logcontent) { if ($line -match "Failed") { Write-Host " " write-host "failed disk found at $localhost " -foregroundcolor red write-host "detailed logs can be found $logfile " -foregroundcolor red Write-Host " " SentDiskDrivefailedviaMail } }
here you can find the HP “Configuring Arrays on HP Smart Array Controllers Reference Guide“ for further details
https://h10032.www1.hp.com/ctg/Manual/c02289065.pdf
Hope this helps,
Ramazan