You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

51 lines
1.9 KiB
PowerShell

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

$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
}
}