Adaptec Raidstatus script for ESXi

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

This entry was posted in Powershell, Vmware, Windows and tagged , , , . Bookmark the permalink.

4 Responses to Adaptec Raidstatus script for ESXi

  1. Laurent says:

    Bonjour,
    Je ne sais pas si vous comprenez le français mais j’essaye quand même !!!
    J’ai un petit problème avec votre script j’ai une erreur avec le Subject “$MAILSUBJECT” je n’arrive pas à comprendre d’où ça pourrait venir !!!
    Voila le message d’erreur :
    + Send-MailMessage -to “$e” -Subject <<<< "$MAILSUBJECT" -from "$MAILFROM" -body "$MAILBODY" -SmtpServer "$SMTPSERVER"}
    + CategoryInfo : InvalidData: (:) [Send-MailMessage], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.PowerShell.Commands.SendMailMessage

    Quand j'enlève le subject de l'envoi de mail ça marche !!!
    Auriez vous une idée d'où ça pourrait venir ?

    Cordialement
    Laurent

  2. laurent says:

    Hello,
    I do not know if you understand French but I still try!
    I have a little problem with your script I get an error with the Subject “$ MAILSUBJECT” I can not understand where it could come!
    Here is the error message:
    + Send-MailMessage-to “$ e”-Subject <<<< "$ MAILSUBJECT"-from "$ MAILFROM"-body "$ mailBody"-SmtpServer "$ SMTPSERVER"}
    + CategoryInfo: invalidData: (:) [Send-MailMessage] ParameterBindingValidationException
    + FullyQualifiedErrorId: ParameterArgumentValidationError, Microsoft.PowerShell.Commands.SendMailMessage

    When I remove the subject of the mail sending it works!
    Do you have an idea where it could come?

    cordially
    Laurent

  3. Stanislas Elie says:

    Hello Laurent.

    The error you see in the output console is normal if you are running the script any day other then Friday. Try changing the number 5 (friday) for the number of the day you are running the script to see if it works better for you.

    Luke : we noticed that the $ sign contained in a variable (a password for example) doesn’t get passed to the rest of the script. It needs an escape code before the $ sign, or just use the simple quote to enclose the string instead of double quotes, ‘password$’ instead of “password$”.

Leave a Reply

Your email address will not be published. Required fields are marked *