Share via


Powershell–How to monitor HP Smartarray disk status?

really a quick one and straight forward but sometimes very useful. here is a quick example how you can monitor your smartarray controller disk status and in case of “Failed” drive detected sent a mail out to you with the summary.

Of course, SCOM has also automated capabilities to monitor HP hardware components in a much more efficient way but that’s a another story

Prerequisites are:

- depends on your SA version - you need the “HP ProLiant Array Configuration Utility (CLI) for Windows” and can be found here, the user guide here

- if required, modify program path to hp array utility command line tool "C:\Program Files\HP\hpssacli\bin\hpssacli.exe"

- modify smtp settings $smtpServer, $smtpFrom, $SMTPPort, $Username, $Password and $smtpTo

- modify $localhost

- check if your controller is 0 “controller slot=0”

###Code Snippet###

$localhost="PUTYOURSERVERNAMEHERE"
Get-item ".\log.txt" -ea 0 | Remove-Item -ea 0
$logfile=".\log.txt"

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
}

CheckSmartArray | out-file -filepath $logfile -append

function SentDiskDrivefailedviaMail {
$Logs=Get-Content $logfile
$smtpServer = "yoursmtp.server.com"
$smtpFrom = "sender@yourdomain.com"
$SMTPPort = "25"
$Username = "user@yourdomain.com"
$Password = "passwordhere"
$smtpTo = "recipient@yourdomain.com"
$messageSubject = "Disk Drive failed at $localhost"

[string]$messagebody = ""

foreach ($log in $logs )
{
$messagebody = $messagebody + $log + "`r`n"
}
Write-Host "failed disk detected - 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 " "
}

#Check logfile if a "Failed" status can be found, if true send a mail with "SentDiskDrivefailedviaMail" function
[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
}
}

###Code Snippet###

Sample Output from smart array CLI utility “controller slot=0 physicaldrive all show”

image

Disclaimer: Please read and test script before you run in your production!

Comments

  • Anonymous
    August 05, 2017
    The comment has been removed
    • Anonymous
      February 24, 2018
      nothing fancy, this is just to remove any previous logfiles if there is a logfile exists (get-Item) then remove it (remove-item)