stichl.at tech at work

5Nov/125

Quick DFSR-Backlog-Count with VBScript

A Quick and dirty VB-Script to check the DFS Backlog (for Windows Server 2008 R2 - does NOT work on 2003 because of missing WMI-Tables...)

strComputer = "localhost"
bConnectForeign = False

    Set oWMIService = GetObject("winmgmts:\\" & strComputer & "\root\MicrosoftDFS")
    Set colRGroups = oWMIService.ExecQuery("SELECT * FROM DfsrReplicationGroupConfig")
    For Each oGroup in colRGroups
        wscript.echo "Replication Group: " & oGroup.ReplicationGroupName
        Set colRGFolders = oWMIService.ExecQuery("SELECT * FROM DfsrReplicatedFolderConfig WHERE ReplicationGroupGUID='" & oGroup.ReplicationGroupGUID & "'")
        For Each oFolder in colRGFolders
            wscript.echo "  Folder: " & oFolder.ReplicatedFolderName
            Set colRGConnections = oWMIService.ExecQuery("SELECT * FROM DfsrConnectionConfig WHERE ReplicationGroupGUID='" & oGroup.ReplicationGroupGUID & "'")
            For Each oConnection in colRGConnections
                If oConnection.Enabled = True Then
                    If oConnection.Inbound = True Then
                        if bConnectForeign then
                            numBackLog = getBackLogCount(oConnection.PartnerName, oConnection.ConnectionGUID)
                        else
                            numBackLog = getBackLogCount(strComputer, oConnection.ConnectionGUID)
                        end if
                        Wscript.echo "    " & strComputer & " <-- " & oConnection.PartnerName & " :: " & numBackLog                     Else                         numBackLog = getBackLogCount(strComputer, oConnection.ConnectionGUID)                         Wscript.echo "    " & strComputer & " --> " & oConnection.PartnerName & " :: " & numBackLog
                    End If
                End If
            Next
        Next
    Next

Function getBackLogCount(strComputer, ConnectionGUID)
    Set oWMIService = GetObject("winmgmts:\\" & strComputer & "\root\MicrosoftDFS")
    Set oDfsIUI = oWMIService.ExecQuery("SELECT * FROM DfsrIdUpdateInfo WHERE ConnectionGuid = '" & ConnectionGUID & "'")
    numBacklog=0
    for each eDfsIUI in oDfsIUI
        numBackLog=numBackLog+1
    next
    getBackLogCount = numBackLog
End Function

Result:

Group: Replication1
  Folder: Folder1
    SERVER1 --> SERVER2 :: 1
    SERVER1 --> SERVER3 :: 2
    SERVER1 --> SERVER4 :: 2

Version for OMD checks:

Set wshShell = WScript.CreateObject( "WScript.Shell" )
strComputer = wshShell.ExpandEnvironmentStrings( "%COMPUTERNAME%" )

bConnectForeign = False
Wscript.echo("<<<dfs_backlog:sep(59)>>>")

    Set oWMIService = GetObject("winmgmts:\\" & strComputer & "\root\MicrosoftDFS")
    Set colRGroups = oWMIService.ExecQuery("SELECT * FROM DfsrReplicationGroupConfig")
    For Each oGroup in colRGroups
        'wscript.echo "Replication Group: " & oGroup.ReplicationGroupName
        Set colRGFolders = oWMIService.ExecQuery("SELECT * FROM DfsrReplicatedFolderConfig WHERE ReplicationGroupGUID='" & oGroup.ReplicationGroupGUID & "'")
        For Each oFolder in colRGFolders
            'wscript.echo "  Folder: " & oFolder.ReplicatedFolderName
            Set colRGConnections = oWMIService.ExecQuery("SELECT * FROM DfsrConnectionConfig WHERE ReplicationGroupGUID='" & oGroup.ReplicationGroupGUID & "'")
            For Each oConnection in colRGConnections
                If oConnection.Enabled = True Then
                    If oConnection.Inbound = True Then
                        if bConnectForeign then
                            numBackLog = getBackLogCount(oConnection.PartnerName, oConnection.ConnectionGUID)
                        else
                            numBackLog = getBackLogCount(strComputer, oConnection.ConnectionGUID)
                        end if
                        Wscript.echo oFolder.ReplicatedFolderName & " ( from " & oConnection.PartnerName & ");" & numBackLog
                    Else
                        numBackLog = getBackLogCount(strComputer, oConnection.ConnectionGUID)
                        Wscript.echo oFolder.ReplicatedFolderName & " ( to " & oConnection.PartnerName & ");" & numBackLog
                    End If
                End If
            Next
        Next
    Next

Function getBackLogCount(strComputer, ConnectionGUID)
    Set oWMIService = GetObject("winmgmts:\\" & strComputer & "\root\MicrosoftDFS")
    Set oDfsIUI = oWMIService.ExecQuery("SELECT * FROM DfsrIdUpdateInfo WHERE ConnectionGuid = '" & ConnectionGUID & "'")
    numBacklog=0
    for each eDfsIUI in oDfsIUI
        numBackLog=numBackLog+1
    next
    getBackLogCount = numBackLog
End Function

OMD check_mk plugin:

dfs_backlog_default_values = (5,10)

# the inventory function
def inventory_dfs_backlog(info):
   inventory = []
   for line in info:
      inventory.append( (line[0], "dfs_backlog_default_values") )

   return inventory

# the check function
def check_dfs_backlog(item, params, info):
   warn, crit = params
   for line in info:
     if line[0] == item:
       backlog = int(line[1])
       perfdata = [ ( "count", backlog, warn, crit ) ]
       if backlog > crit:
         return(2,"CRIT - Backlog count: "+line[1],perfdata)
       elif backlog > warn:
         return(1,"WARN - Backlog count: "+line[1],perfdata)
       else:
         return (0,"OK - Backlog count: "+line[1],perfdata)
   return (3, "UNKNOWN - agent output error")

# declare the check to Check_MK
check_info['dfs_backlog'] = {
    "check_function"          : check_dfs_backlog,
    "inventory_function"      : inventory_dfs_backlog,
    "service_description"     : "DFS Backlog:",
    "has_perfdata"            : True,
}

Looks like:
backlog-check_mk

Filed under: Windows Leave comment
Comments (5) Trackbacks (0)
  1. nice script. just does what i shoud do.. anyhow… i would like to have it work together with nagios(OMD) to make it more human reports 😉

  2. Hi Mike great script.

    Do I create 2 different Scrips to the CheckMK local folder? How do I implement this?

    Thanks

    • I’m sorry, this may be a bit confusing…
      The “Version for OMD checks” has to be saved as .vbs script in the check_mk agent’s plugins directory on the Windows DFS server.
      The “OMD check_mk plugin” is the actual check plugin on your OMD nagios server. When using OMD it needs to be saved as /opt/omd/sites/[YOURSITENAME]/local/share/check_mk/checks/dfs_backlog
      Please substitute [YOURSITENAME] with your own OMD site name.

      You can also read the section about writing agent based checks for check_mk here: http://mathias-kettner.de/checkmk_devel_agentbased.html

  3. Hi Mike,

    thanks for the script. There is a small problem with it. If you have multiple folders in one group the backlog get mixed up and show on every single one of them. If put a fixed version on http://pastebin.com/w82iXje7

    Jonathan


Leave a comment

No trackbacks yet.