Active Script: Windows RAID monitoring

If you have information, script, utility, or idea that can be useful for HostMonitor community, you welcome to share information in this forum.
Post Reply
SplanK
Posts: 38
Joined: Wed Nov 21, 2007 1:33 pm

Active Script: Windows RAID monitoring

Post by SplanK »

We have a couple of machines here which use MS software RAID. I tweaked a script found here:
http://www.eventsentry.com/kb/211
to interrogate the status of the software raid.

It will report ok when status is Healtyh
It will report bad when status is not healthy
It will report unknown if there are no MS software raids found.

Code: Select all

' Lists all logical drives on the local computer which are configured for 
' software RAID. 

Option Explicit

const statusAlive       = "Host is alive:"
const statusDead        = "No answer:"
const statusUnknown     = "Unknown:"
const statusNotResolved = "Unknown host:"
const statusOk          = "Ok:"
const statusBad         = "Bad:"
const statusBadContents = "Bad contents:"

FUNCTION PerformTest()

	Dim WshShell, oExec
	Dim RegexParse
	Dim oError, oReply, oCount, oSpacer
	oCount = 0
	oError = 0

	Set WshShell = CreateObject("WScript.Shell")
	Set RegexParse = New RegExp

	' Execute diskpart
	Set oExec = WshShell.Exec("%comspec% /c echo list volume | diskpart.exe")

	RegexParse.Pattern = "\s\s(Volume\s\d)\s+([A-Z])\s+(.*)\s\s(NTFS|FAT)\s+(Mirror|RAID-5)\s+(\d+)\s+(..)\s\s([A-Za-z]*\s?[A-Za-z]*)(\s\s)*.*"

	While Not oExec.StdOut.AtEndOfStream
		Dim regexMatches
		Dim Volume, Drive, Description, Redundancy, RaidStatus
		Dim CurrentLine : CurrentLine = oExec.StdOut.ReadLine
		
		Set regexMatches = RegexParse.Execute(CurrentLine)
		If (regexMatches.Count > 0) Then
			Dim match
			Set match = regexMatches(0)
			
			If match.SubMatches.Count >= 8 Then
				Volume      = match.SubMatches(0)
				Drive       = match.SubMatches(1)
				Description = Trim(match.SubMatches(2))
				Redundancy  = match.SubMatches(4)
				RaidStatus  = Trim(match.SubMatches(7))
			End If

			If RaidStatus <> "Healthy" Then
				oError = 1
			End If
			
			'WScript.StdOut.WriteLine "Status of " & Redundancy & " " & Drive & ": (" & Description & ") is """ & RaidStatus & """"
	
			If oCount > 1 Then
				oSpacer = " / "
			Else
				oSpacer = ""
			End If 
	
			oReply = oReply & oSpacer & Redundancy & " " & Drive & ": is " & RaidStatus
			oCount = oCount + 1
		End If
	Wend

	If oError = 1  Then
		PerformTest = statusBad+oReply
	Elseif oCount = 0 Then
		PerformTest = statusUnknown+"No Software RAID found " & oReply
	Else
		PerformTest = statusOk+oReply	
	End If
End Function

Post Reply