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!)

Recent Articles

The return of CyberDrain CTF

CyberDrain CTF returns! (and so do I!)

It’s been since september that I actually picked up a digital pen equivalent and wrote anything down. This was due to me being busy with life but also my side projects like CIPP. I’m trying to get back into the game of scripting and blogging about these scripts. There’s still so much to automate and so little time, right? ;)

Monitoring with PowerShell: Monitoring Acronis Backups

Intro

This is a monitoring script requested via Reddit, One of the reddit r/msp users wondered how they can monitor Acronis a little bit easier. I jumped on this because it happened pretty much at the same time that I was asked to speak at the Acronis CyberSummit so it kinda made sense to script this so I have something to demonstrate at my session there.

Monitoring with PowerShell: Monitoring VSS Snapshots

Intro

Wow! It’s been a while since I’ve blogged. I’ve just been so swamped with CIPP that I’ve just let the blogging go entirely. It’s a shame because I think out of all my hobbies it’s one I enjoy the most. It’s always nice helping others achieve their scripting target. I even got a couple of LinkedIn questions asking if I was done with blogging but I’m not. Writing always gives me some more piece of mind so I’ll try to catch up again. I know I’ve said that before but this time I’ll follow through. I’m sitting down right now and scheduling the release of 5 blogs in one go. No more whining and no more waiting.