Created
December 14, 2016 14:52
-
-
Save rwasef1830/35798cebcc922fd11ff7f887c229925f to your computer and use it in GitHub Desktop.
Windows nagios plugin check software raid: http://www.anchor.com.au/hosting/dedicated/monitoring_windows_software_raid
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
' Source: http://www.anchor.com.au/hosting/dedicated/monitoring_windows_software_raid | |
' Software RAID status check script | |
Option Explicit | |
Dim WshShell, oExec | |
Dim Line, RE0, RE1, RE2, RE3 | |
Dim Failed | |
Failed = -1 | |
' Simple variable to display status of all volumes: | |
' 0 = Healthy | |
' 1 = Rebuilding | |
' 2 = Failed | |
' 3 = Unknown | |
' Check version of WScript. Has to be >= 5.6 for WScript.Shell.Exec to work | |
If Wscript.Version < 5.6 Then | |
Failed = 3 | |
Wscript.StdOut.WriteLine("UNKNOWN: WScript version < 5.6") | |
WScript.Quit(Failed) | |
End If | |
Set WshShell = WScript.CreateObject("WScript.Shell") | |
' Execute the DISKPART program and grab the output | |
Set oExec = WshShell.Exec("%comspec% /C echo list volume | %WINDIR%\SYSTEM32\DISKPART.EXE") | |
' Set up some regular expression objects | |
Set RE0 = New RegExp | |
Set RE1 = New RegExp | |
Set RE2 = New RegExp | |
Set RE3 = New RegExp | |
RE0.Pattern = "Healthy" | |
RE1.Pattern = "Mirror|RAID-5" | |
RE2.Pattern = "Failed|(At Risk)" | |
' At Risk indicates errors have been reported for a disk | |
' and it may need to be reactivated. | |
RE3.Pattern = "Rebuild" | |
' Check for no output | |
If oExec.StdOut.AtEndOfStream Then | |
Failed = 3 | |
Else | |
While Not oExec.StdOut.AtEndOfStream | |
Line = oExec.StdOut.ReadLine | |
' Tests for Mirrored or RAID-5 volumes | |
If RE1.Test(Line) Then | |
' Tests for Healthy volumes | |
If RE0.Test(Line) Then | |
If Failed = -1 Then Failed = 0 | |
End If | |
' Tests for Failed RAID volumes | |
If RE2.Test(Line) Then | |
If Failed < 2 Then Failed = 2 | |
' Tests for Rebuilding volumes | |
ElseIf RE3.Test(Line) Then | |
If Failed = 0 Then Failed = 1 | |
End If | |
End If | |
WEnd | |
End If | |
' If Failed is still -1, something bad has happened, or there is no RAID | |
If Failed = -1 Then Failed = 3 | |
' Print out the appropriate test result | |
Select Case Failed | |
Case 0 | |
WScript.StdOut.WriteLine("RAID OK: All volumes Healthy") | |
Case 1 | |
WScript.StdOut.WriteLine("RAID WARNING: Volume(s) Rebuilding") | |
Case 2 | |
WScript.StdOut.WriteLine("RAID CRITICAL: Volume(s) have Failed") | |
Case 3 | |
WScript.StdOut.WriteLine("UNKNOWN: " + oExec.StdErr.ReadLine) | |
End Select | |
WScript.Quit(Failed) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment