As promised in my previous post i made a (Powershell) script which can be automated to run as a scheduled task. The script is build to run once a day. It sends an email if there is an error in the controller or one of the (logical) drive’s. On friday it always sends an email so you will know the script is still working 😉
It’s my first Powershell script so feel free to leave a comment with possible improvements 😉
<#
Script Name : Adaptac Array Health checker
Version : 20130419
Author : Luke Voorn
Description : Checks the health status of an array trough arcconf provider on ESXi
TODO :
#>
# -------------------------------------------------------------- #
# Variables
# -------------------------------------------------------------- #
$ESXI_SERVER = "192.168.1.10"
$ESXI_PORT = "5989"
$ESXI_USER = "raidstatus"
$ESXI_PASSWORD = "raidstatuspassword"
$ADAPTEC_CARD = "1"
$ARCCONF_PATH = "C:\Program Files (x86)\Adaptec\RemoteArcconf\arcconf.exe"
[string[]]$MAILTO = "email1@domain.nl", "email2@domain.nl"
$MAILFROM = "email3@domain.nl"
$SMTPSERVER = "192.168.1.20"
# -------------------------------------------------------------- #
# End Variables
# -------------------------------------------------------------- #
$global:SomethingInError="False"
function GetStatusData {
$ARCCONF_ARG = " SETVMCREDENTIAL $ESXI_SERVER $ESXI_PORT $ESXI_USER $ESXI_PASSWORD"
Start-Process $ARCCONF_PATH -ArgumentList " $ARCCONF_ARG" -Wait
$result = &$ARCCONF_PATH getconfig $ADAPTEC_CARD
return $result
}
function ParseTheData {
param([string[]]$FunctionInput)
$Count = 0
$Output = @() #create empty error
ForEach($s in $FunctionInput) {
If ($s.Contains("Controller Status") -and $s.Contains("Optimal")){
$Output + $s
}
ElseIf ($s.Contains("Controller Status") -and !$s.Contains("Optimal")){
$Output + $s
$global:SomethingInError = "True"
}
if ($s.Contains("Status of logical device") -and $s.Contains("Optimal")){
$Output += $s
}
elseif ($s.Contains("Status of logical device") -and !$s.Contains("Optimal")){
$Output += $s
$global:SomethingInError = "True"
}
if ($s.Contains("Device is a Hard drive") -and $FunctionInput.GetValue($Count +1).Contains("Online")){
$Output += ($FunctionInput.GetValue($Count -1)) + ($FunctionInput.GetValue($Count +1))
}
elseif ($s.Contains("Device is a Hard drive") -and !$FunctionInput.GetValue($Count +1).Contains("Online")){
$Output += ($FunctionInput.GetValue($Count -1)) + ($FunctionInput.GetValue($Count +1))
$global:SomethingInError = "True"
}
$Count++
}
return $Output
}
function MailResults {
param([string[]]$ResultArray)
$MAILSUBJECT = ""
$MAILBODY = ""
ForEach ($s in $ResultArray){
$MAILBODY = $MAILBODY + $s
$MAILBODY = $MAILBODY + [Environment]::NewLine
}
if ($global:SomethingInError -eq "True"){
$MAILSUBJECT = "Adapter in ERROR"
}
elseif ((Get-Date).DayOfWeek.value__ -eq 5 -and $global:SomethingInError -eq "False"){
$MAILSUBJECT = "Adapter OK: weekly status"
}
ForEach($e in $MAILTO){
Send-MailMessage -to "$e" -Subject "$MAILSUBJECT" -from "$MAILFROM" -body "$MAILBODY" -SmtpServer "$SMTPSERVER"
}
}
$Raw = GetStatusData
$result = ParseTheData -FunctionInput $Raw
MailResults -ResultArray $result

