hp-server-monitoring/_windows_disk_monitoring/disk_monitoring.ps1
2019-11-12 08:58:12 +01:00

51 lines
1.9 KiB
PowerShell
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

$localhost="HOST-BLACKNET"
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\Smart Storage Administrator\ssacli\bin\ssacli.exe" controller slot=2 physicaldrive all show
C:\Windows\System32\cmd.exe /c "C:\Program Files\Smart Storage Administrator\ssacli\bin\ssacli.exe" controller slot=0 physicaldrive all show
}
CheckSmartArray | out-file -filepath $logfile -append
function SentDiskDrivefailedviaMail {
$Logs=Get-Content $logfile
$smtpServer = "smtp.gmail.com"
$smtpFrom = "MY_SERVER_MAIL@gmail.com"
$SMTPPort = "587"
$Username = "MY_SERVER_MAIL@gmail.com"
$Password = "MY_SERVER_MAIL_PASSWORD"
$smtpTo = "MY_DESTINATION_MAIL"
$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
$SMTPClient = New-Object Net.Mail.SmtpClient( $smtpServer, $SMTPPort )
$SMTPClient.EnableSsl = $true
$SMTPClient.Credentials = New-Object System.Net.NetworkCredential($Username, $Password);
$SMTPClient.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
}
}