Created
March 29, 2018 23:40
-
-
Save tostka/5b3e39fea6138e5e4f19bd3e731b6798 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<# TRIMMED GIST see full post at github for details #> | |
#*------v Function CheckSmartArray v------ | |
function CheckSmartArray { | |
Write-Host -foregroundcolor green "`nChecking SmartArray on system $($env:COMPUTERNAME), controller slot $($targControllerSlot)..." ; | |
C:\Windows\System32\cmd.exe /c "C:\Program Files (x86)\Compaq\Hpacucli\Bin\hpacucli.exe" controller slot=$($targControllerSlot) physicaldrive all show | |
} ; #*------^ END Function CheckSmartArray ^------ | |
<# TRIMMED #> | |
CheckSmartArray | out-file -filepath $logfile -append ; | |
write-verbose -verbose:$true "$((get-date).ToString('HH:mm:ss')):DETAILED OUTPUT FOR CTRL IN SLOT $($targControllerSlot):`n(blank if none)" ; | |
[array]$logcontent=gc $logfile ; | |
$logcontent | out-string ; | |
write-host "`n$((get-date).ToString('HH:mm:ss')):CHECKING FOR 'FAILED'S IN OUTPUT:`n(blank if none)" ; | |
$FailedDriveCount = 0 ; | |
foreach ($line in $logcontent) { | |
if ($line -match "Failed") { | |
$FailedDriveCount ++ ; | |
$SmtpSubject = "FAILED DISK FOUND ON $($env:COMPUTERNAME) ($((get-date -format 'yyyyMMdd-HHmmtt')))" ; | |
write-verbose -verbose:$true "$((get-date).ToString('HH:mm:ss')):FAILED DISK ON $($env:COMPUTERNAME)" ; | |
$SmtpBody += "`n`rFAILURE:`n$($line)`n`rdetailed logs can be found $($logfile.replace("C:\","\\$($env:COMPUTERNAME)\c$\"))" ; | |
write-verbose -verbose:$true "$((get-date).ToString('HH:mm:ss')):$($SmtpBody)" ; | |
$FailedDbs=Get-DatabaseAvailabilityGroup $tDAG | select -expand servers | | |
% {Get-MailboxDatabaseCopyStatus -Server $_ | where {$_.Status -match '^(Failed|FailedAndSuspended)'}} | |
$faileddbs|%{ | |
$fdbName= $_.identity.tostring().split("\")[0] ; | |
$sMsg = "===STATUS OF DBS IN $($tDAG) WITH FAILED REPLICAS:" ; | |
write-verbose -verbose:$true "$((get-date).ToString('HH:mm:ss')):$($sMsg)" ; | |
$SmtpBody += "`n`r" + $sMsg ; | |
$CopyStat= Get-MailboxDatabaseCopyStatus -identity $fdbName | select name,status,LatestFullBackupTime,LatestIncrementalBackupTime ; | |
$SmtpBody += "`n`r$(($CopyStat| out-string).trim())" ; | |
$(($CopyStat| out-string).trim()) ; | |
$sMsg = "===EdbFilePath of affected dbs" ; | |
write-verbose -verbose:$true "$((get-date).ToString('HH:mm:ss')):$($sMsg)" ; | |
$SmtpBody += "`n`r" + $sMsg ; | |
$EdbFilePath = Get-MailboxDatabase -identity $fdbName | select name,EdbFilePath ; | |
$SmtpBody += "`n`r$(($EdbFilePath| out-string).trim())" ; | |
$(($EdbFilePath| out-string).trim()) ; | |
} ; | |
}; # if-E fail | |
} # loop-E ; | |
$attachments+=$logfile ; | |
if($FailedDriveCount -eq 0 -AND $bAlert ){ | |
# reset semaphore if present but no longer in Fail state | |
$SmtpSubject = "DISK RECOVERY ON $($env:COMPUTERNAME) ($((get-date -format 'yyyyMMdd-HHmmtt')))" ; | |
$SmtpBody = "Returning to NOMINAL status`n`r$($line)`n`rdetailed logs can be found $($logfile.replace("C:\","\\$($env:COMPUTERNAME)\c$\"))" ; | |
$SendMsg=$true ; | |
$bAlert = $false ; | |
} elseif($FailedDriveCount -ge 0 -AND -not $bAlert){ | |
# new alert | |
$SendMsg=$true ; | |
$bAlert = $true ; | |
} elseif($FailedDriveCount -AND $bAlert ) { | |
# existing alert, only send on after $EmailEveryXCycles | |
if($CyclesSinceLastNotif -ge $EmailEveryXCycles){ | |
$SendMsg=$true ; | |
write-verbose -verbose:$true "$((get-date).ToString('HH:mm:ss')):TRIGGERING ALERT NOTIFICATION" ; | |
} else { | |
$SendMsg=$false ; | |
write-verbose -verbose:$true "$((get-date).ToString('HH:mm:ss')):ALERT STATUS, SENT $($SentNotifications++) NOTIFICATIONS, `n`r$($CyclesSinceLastNotif) CYCLES SINCE LAST NOTIFICATION`r`nWAITING UNTIL $($EmailEveryXCycles) CYCLES TO SEND A NEW NOTIFICATION" ; | |
} | |
} else { | |
} ; | |
} else { write-error "$((get-date).ToString('HH:mm:ss')):NO EMS FOUND, FAILED LOAD, OR SCRIPT NOT RUNNING ON AN EXCHANGE ROLE SERVER! ABORTING!"; } ; | |
<# TRIMMED #> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
core bits of my broader check-DriveStatusHP.ps1 script (at Github repo)