SeeDk
asked on
Nagios - Monitor DFSR - VBscript out of range
DISCLAIMER: I DID NOT WRITE THIS SCRIPT.
It is available here: https://exchange.nagios.org/directory/Addons/Monitoring-Agents/DFS-Replication-and-BackLog/details
I am trying to set this up in my environment so I can track dfsr without having to manually check it.
However, when I try running it on Nagios I get the error:
DFS-Backlog.vbs(7, 1) Microsoft VBScript runtime error: Subscript out of range
I searched around and the best hint to the solution I could find is other VBscripts that monitor DFS have this error when the Replicated Groups and/or Folders have spaces in the name.
Both have spaces in my DFSR setup.
I think if a change is made to accommodate spaces in Replicated Groups/Folders names - then this script will work. Would someone be able to point out what line needs to be changed and what it should be changed to?
It is available here: https://exchange.nagios.org/directory/Addons/Monitoring-Agents/DFS-Replication-and-BackLog/details
I am trying to set this up in my environment so I can track dfsr without having to manually check it.
However, when I try running it on Nagios I get the error:
DFS-Backlog.vbs(7, 1) Microsoft VBScript runtime error: Subscript out of range
I searched around and the best hint to the solution I could find is other VBscripts that monitor DFS have this error when the Replicated Groups and/or Folders have spaces in the name.
Both have spaces in my DFSR setup.
I think if a change is made to accommodate spaces in Replicated Groups/Folders names - then this script will work. Would someone be able to point out what line needs to be changed and what it should be changed to?
strComputer = "."
const intOK = 0
const intWarning = 1
const intCritical = 2
const intUnknown = 3
GroupName = Replace(WScript.Arguments.Item(0),"_"," ")
Warn = CInt(WScript.Arguments.Item(1))
Crit = CInt(WScript.Arguments.Item(2))
sTarget = "localhost"
set oPing = _
GetObject("winmgmts:{impersonationLevel=impersonate}"). _
ExecQuery ("select * from Win32_PingStatus where address = '" _
& sTarget & "'")
For Each o In oPing
sResp = o.StatusCode : exit for
Next
if sResp = 0 Then
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\MicrosoftDfs")
Set colItems = objWMIService.ExecQuery( _
"SELECT * FROM DfsrReplicatedFolderInfo WHERE ReplicatedFolderName = '" & GroupName & "'",,48)
For Each objItem in colItems
BackLog objItem.ReplicationGroupGuid
Next
else
wscript.echo "CRITICAL - WMI Error"
wscript.quit(intCritical)
End If
Sub BackLog(GRPID)
BLCount = 0
Set oWMIService = GetObject("winmgmts:\\" & strComputer & "\root\MicrosoftDFS")
Set colRGFolders = oWMIService.ExecQuery("SELECT * FROM DfsrReplicatedFolderConfig WHERE ReplicationGroupGUID='" & GRPID & "'")
For Each oFolder in colRGFolders
FolderName = oFolder.ReplicatedFolderName
Set colRGConnections = oWMIService.ExecQuery("SELECT * FROM DfsrConnectionConfig WHERE ReplicationGroupGUID='" & GRPID & "'")
For Each oConnection in colRGConnections
numBackLog = getBackLogCount(oConnection.ConnectionGUID)
BLCount = BLCount + numBackLog
Output = Output & numBackLog & " -BackLog Count for " & FolderName & " "
Next
Next
BackLogChk BLCount,Output
End Sub
Function getBackLogCount(ConnectionGUID)
Set oWMIService = GetObject("winmgmts:\\" & strComputer & "\root\MicrosoftDFS")
Set oDfsIUI = oWMIService.ExecQuery("SELECT * FROM DfsrIdUpdateInfo WHERE ConnectionGuid = '" & ConnectionGUID & "'")
numBacklog=0
If Err.Number <> 0 Then
getBackLogCount = 999
else
for each eDfsIUI in oDfsIUI
numBackLog=numBackLog+1
next
getBackLogCount = numBackLog
end if
End Function
Sub BackLogChk(BackLogCount,Output)
GroupName = Replace(WScript.Arguments.Item(0),"_"," ")
if BackLogCount >= Warn then
if BackLogCount >= Crit then
wscript.echo "CRITICAL - " & Output
wscript.quit(intCritical)
else
wscript.echo "Warning - " & Output
wscript.quit(intWarning)
end if
elseif BackLogCount < Warn and BackLogCount >= 0 then
wscript.echo "OK - " & Output
wscript.quit(intOK)
else
wscript.echo "CRITICAL - WMI error Backlog not set to an integer (probably null)"
wscript.quit(intCritical)
end if
End Sub
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER