Featured image of post Blog Series: Monitoring using PowerShell: Part one – Using PowerShell to monitor MegaRaid

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:

1
StorCli64.exe "/c0 /vall show j"

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

1
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:

1
2
3
$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.

1
2
3
4
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:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
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:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
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!)

All blogs are posted under AGPL3.0 unless stated otherwise
comments powered by Disqus
Built with Hugo
Theme Stack designed by Jimmy