App-V screenshot

Blog Series: Monitoring using PowerShell: Part one – Using PowerShell to monitor MegaRaid

Preface:

Hi All,

My next couple of blogs will be a series of blogs where I will be explaining on how to use PowerShell for the monitoring of critical infrastructure. I will be releasing a blog every day that will touch on how to monitor specific software components, but also network devices from Ubiquity, third-party API’s and Office365. I will also be showing how you can integrate this monitoring in current RMM packages such as Solarwinds N-Central, Solarwinds RMM MSP and even include the required files to import the  monitoring set directly into your system.


Requirements:

  • StorCLI.exe or Storecli64.exe extracted to any path you’d like. (Download can be found here)
  • PowerShell v2 or higher

Creating the monitoring sets:

The first monitoring script is a good start but still a fairly simple script. We’re going to use the StorCli executable to get the status of the RAID array, and the physical disk data. The StorCLI executable has multiple options for outputting its data. One of the options is outputting it as a JSON string. JSON is a way to present structured data as a string.

If you’re only hear for ready made packages you can scroll down to the downloads, where the packages for PRTG and N-Central can be found.

Getting information from StorCLI:

To get the information required from StorCLI we’ll have to execute it within PowerShell and tell it to output the data to the JSON format we’re going to use.

The command to get the RAID configuration for Controller 0(Most likely the only controller in your system) is:

StorCli64.exe "/c0 /vall show j"

The command to get all physical disks status on Controller 0 is:

StorCli64.exe "/c0 /eall /sall show"

To load the configuration into a usable array we will use PowerShell to run the executable, grab the string output and then convert it to an array:

$StoreCliLocation = “C:\Executables\StorCli64.exe”
$ExecuteStoreCLI = & $StoreCliLocation "/c0 /eall /sall show j" | out-string
$ArrayStorCLI= ConvertFrom-Json $ExecuteStoreCLI

Now we can run $ArrayStorCli and we will get the entire array back with the information about the RAID array. The next step is straightforward – We check each Virtual Drive(Which is a RAID array) that does not have the state “Optl” and set the current health variable based on that.

foreach($VirtualDrive in $ArrayStorCLI.Controllers.'response data'.'Virtual Drives'){
if($($VirtualDrive.state) -ne "Optl"){
$RAIDStatus += "Virtual Drive $($Controller.'DG/VD') With Size $($Controller.'Size') is $($Controller.State)"
}

If we now check $RAIDStatus it will be empty if our RAID array is healthy, and it will contain “Virtual drive X with Size X has state X” if it has failed in any way. Of course this script needs some more steps to ensure that there is sufficient error handeling in case the StorCli send us incorrect data.

For this, See the full script below. In the full script we’ve added the parameters so we can set the correct path for the StorCli executable and a bit or error handeling in case the executable is not found. For error handeling we’re using a try and catch block.

RAID Status Monitoring:

param(
[string]$StorCLILocation = 'C:\Executables\StorCli64.exe',
[string]$StorCliCommand = "/c0 /vall show j"
)
try {
$ExecuteStoreCLI = & $StorCliLocation $StorCliCommand | out-string
$ArrayStorCLI= ConvertFrom-Json $ExecuteStoreCLI
}catch{
$ScriptError = "StorCli Command has Failed: $($_.Exception.Message)"
exit
}
foreach($VirtualDrive in $ArrayStorCLI.Controllers.'response data'.'Virtual Drives'){
if($($VirtualDrive.state) -ne "Optl"){
$RAIDStatus += "Virtual Drive $($VirtualDrive .'DG/VD') With Size $($VirtualDrive .'Size') is $($VirtualDrive.State)"
}
}
#If the variables are not set, We’re setting them to a “Healthy” state as our final action.
if (!$RAIDStatus) { $RAIDStatus = “Healthy” }
if (!$ScriptError) { $ScriptError = “Healthy” }

Physical Disk Status Monitoring:

param(
[string]$StorCLILocation = 'C:\Executables\StorCli64.exe',
[string]$StorCliCommand = "/c0 /eall /sall show j"
)
try {
$ExecuteStoreCLI = & $StorCliLocation $StorCliCommand | out-string
$ArrayStorCLI= ConvertFrom-Json $ExecuteStoreCLI
}catch{
$ScriptError = "StorCli Command has Failed: $($_.Exception.Message)"
exit
}
foreach($Controller in $ArrayStorCLI. Controllers.'Response data'.'Drive Information'){
if($($Controller.state) -ne "Onln"){
$PhysicalStatus += “$($Controller.Model) With Disk ID $($Controller.DID) is $($Controller.State)"
}
}
#If the variables are not set, We’re setting them to a “Healthy” state as our final action.
if (!$PhysicalStatus) { $RAIDStatus = “Healthy” }
if (!$ScriptError) { $ScriptError = “Healthy” }

And that concludes todays simple MegaRAID/Lenovo RAID/LSI Raid monitoring script in PowerShell. If you want to implement this in your own monitoring system you can download the respective files below.

Any questions? Feel free to comment below! 🙂

Downloads for RMM packages:

N-Central 11.0+ – RAID Monitoring

N-Central 11.0+ – Physical Disk Monitoring

PRTG – RAID and Physical Disk monitoring (Coming soon!)

4 thoughts on “Blog Series: Monitoring using PowerShell: Part one – Using PowerShell to monitor MegaRaid

  1. Keith

    Love it!! Thanks for sharing, good to get a controlled set of alerts instead of the built in mega raid email alert settings. Cheers!

    Reply
  2. lance

    i’m trying to use your n-central scripts, but it only allows me to import one as it says the other is already there when i try to import it. is there a duplication problem it’s detecting?

    also, when I setup the custom service, it wants the thresholds string values for “script error state” and “raid health state” I tried parsing your amp files to see what they should be, but didn’t get very far.

    Reply
    1. Kelvin Tegelaar Post author

      Hi Lance,

      That must be because I’ve reused the same file a couple of times, I’ve uploaded a new set. Please try to download the zip or RAID files once more.

      The thresholds are “Healthy” for the RAID states & Script Error States, use “OK” for chassis states, See my screenshot for more information.
      RAID Status N-Able

      Regards,

      Reply

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.