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:
|
|
The command to get all physical disks status on Controller 0 is:
|
|
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:
|
|
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.
|
|
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:
|
|
Physical Disk Status Monitoring:
|
|
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!)