Link to home
Start Free TrialLog in
Avatar of mmoya
mmoyaFlag for United States of America

asked on

DFS Monitoring VB Script

I need to run this but include a line wherein if the DFS link/s fail/s I need to send an email to certain people. Can someone please provide assistance? thank you...

'Designate the DFS server you want to query
strComputer = "yourfileserver"
'Number of times you want to loop, 0 is indefinite
numLoop = 0
'Wait time between queries - for large DFS trees make this longer
'Time is in minutes
numWait = 5


'**** Do not edit beyond this point!  ****
Dim objExplorer, binFirstWindow, strFiles

If numLoop = 0 Then
	numSubtract = 0
Else
	numSubtract = 1
	numLoop = numLoop - 1
End If

'Convert minutes to miliseconds
numWait = (numWait * 60) * 1000

showTable("Running...")
Do Until numLoop < 0
	Call Main()
	numLoop = numLoop - numSubtract
	Wscript.Sleep numWait
Loop

wscript.echo "Done!"

Sub Main
	strHTML = "<table border=" & chr(34) & "1" & chr(34) & ">" & vbCRLF
	strHTML = strHTML & "<th>Replication Group</th><th>Sending Partner</th><th>Receiving Partner</th><th>Backlog</th><th>Files</th>" & vbCRLF
	Set oWMIService = GetObject("winmgmts:\\" & strComputer & "\root\MicrosoftDFS")
	Set colRGroups = oWMIService.ExecQuery("SELECT * FROM DfsrReplicationGroupConfig")
	For Each oGroup in colRGroups
		Set colRGFolders = oWMIService.ExecQuery("SELECT * FROM DfsrReplicatedFolderConfig WHERE ReplicationGroupGUID='" & oGroup.ReplicationGroupGUID & "'")
		For Each oFolder in colRGFolders
			Set colRGConnections = oWMIService.ExecQuery("SELECT * FROM DfsrConnectionConfig WHERE ReplicationGroupGUID='" & oGroup.ReplicationGroupGUID & "'")
			For Each oConnection in colRGConnections
			
				binInbound = oConnection.Inbound
				strPartner = oConnection.PartnerName
				strRGName = oGroup.ReplicationGroupName
				strRFName = oFolder.ReplicatedFolderName
				If binInbound = True Then
					strSendingComputer = strPartner
					strReceivingComputer = strComputer
				Else
					strSendingComputer = strComputer
					strReceivingComputer = strPartner
				End If
				If oConnection.Enabled = True Then
					strHTML = strHTML & "<tr>" & vbCRLF
					strHTML = strHTML & "<td>" & strRGName & "</td>" & vbCRLF
					strHTML = strHTML & "<td>" & strSendingComputer & "</td>" & vbCRLF
					strHTML = strHTML & "<td>" & strReceivingComputer & "</td>" & vbCRLF
					numBackLog = getBackLog(strSendingComputer, strReceivingComputer, strRGName, strRFName)
					If numBackLog = 0 Then
						strHTML = strHTML & "<td>" & numBackLog & "</td>" & vbCRLF
					Else
						strHTML = strHTML & "<td style=" & chr(34) & "background-color:red" & chr(34) & ">" & numBackLog & "</td>" & vbCRLF
					End If
					strHTML = strHTML & "<td>" & strFiles & "</td>" & vbCRLF
					strHTML = strHTML & "</tr>" & vbCRLF
					'wscript.echo strHTML
				End If
			Next
		Next
	Next
	strHTML = strHTML & "</table>" & vbCRLF
	'wscript.echo strHTML
	showTable(strHTML)
End Sub


Function getBackLog(strSending, strReceiving, strReplicationGroup, strReplicatedFolder)
	Set WshShell = CreateObject ("Wscript.shell")
	'wscript.echo "dfsrdiag Backlog /RGName:" & strReplicationGroup & " /RFName:" & strReplicatedFolder & " /SendingMember:" & strSending & " /ReceivingMember:" & strReceiving
	Set objExec = WSHshell.Exec("dfsrdiag.exe Backlog /RGName:" & strReplicationGroup & " /RFName:" & strReplicatedFolder & " /SendingMember:" & strSending & " /ReceivingMember:" & strReceiving)
	strResult = ""
	Do While Not objExec.StdOut.AtEndOfStream
		strResult = strResult & objExec.StdOut.ReadLine() & "\\"
	Loop
	'wscript.echo strResult
	strTemp = "&nbsp;"
	If InStr(strResult, "No Backlog") > 0 Then
		getBackLog = 0
	Else
		arrLines = Split(strResult, "\\")
		arrResult = Split(arrLines(1), ":")
		getBackLog = arrResult(1)
		If UBound(arrLines) > 1 Then
			strTemp = ""
			For x = 2 to UBound(arrLines)
				If InStr(arrLines(x), "Succeeded") = 0 and arrLines(x) <> "" Then
					strTemp = strTemp & arrLines(x) & "<br>"
				End If
			Next
			'wscript.echo strTemp
		End If
	End If
	strFiles = strTemp
End Function


Sub showTable(strText)
	If binFirstWindow = False Then
		binFirstWindow = True
		Set objExplorer = WScript.CreateObject("InternetExplorer.Application")
		With objExplorer
			.Navigate "about:blank"   
			.ToolBar = 0
			.StatusBar = 0
			.Width = 750
			.Height = 600 
			.Left = 0
			.Top = 0
		End With
		
		Do While (objExplorer.Busy)
			Wscript.Sleep 200
		Loop
		objExplorer.Visible = 1 
	End If

	On Error Resume Next
	objExplorer.Document.Body.InnerHTML = strText
	If Err.Number <> 0 Then
		Wscript.Quit
	End If
	On Error Goto 0
End Sub

Open in new window

Avatar of RobSampson
RobSampson
Flag of Australia image

Hi, in the current script, what determines where it fails?  Or doesn't it have that yet?  Is the WMI connection error you are talking about?

Rob.
Avatar of mmoya

ASKER

Fails = when DFS link is unaccessible then send email to certain users for acknowledgement...
ASKER CERTIFIED SOLUTION
Avatar of RobSampson
RobSampson
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial