<UnitMonitorType ID="Microsoft.Windows.Server.2008.AD.DomainController.LostObjectCount.Monitortype" Accessibility="Internal">
<MonitorTypeStates>
<MonitorTypeState ID="OK" NoDetection="false"/>
<MonitorTypeState ID="Warn" NoDetection="false"/>
<MonitorTypeState ID="Error" NoDetection="false"/>
</MonitorTypeStates>
<Configuration>
<xsd:element name="IntervalSeconds" type="xsd:int"/>
<xsd:element name="LostObjectCountWarningThreshold" type="xsd:int"/>
<xsd:element name="LostObjectCountErrorThreshold" type="xsd:int"/>
</Configuration>
<OverrideableParameters>
<OverrideableParameter ID="IntervalSeconds" Selector="$Config/IntervalSeconds$" ParameterType="int"/>
<OverrideableParameter ID="LostObjectCountWarningThreshold" Selector="$Config/LostObjectCountWarningThreshold$" ParameterType="int"/>
<OverrideableParameter ID="LostObjectCountErrorThreshold" Selector="$Config/LostObjectCountErrorThreshold$" ParameterType="int"/>
</OverrideableParameters>
<MonitorImplementation>
<MemberModules>
<DataSource ID="ScriptDS" TypeID="System!System.CommandExecuterPropertyBagSource">
<IntervalSeconds>$Config/IntervalSeconds$</IntervalSeconds>
<ApplicationName>%windir%\system32\cscript.exe</ApplicationName>
<WorkingDirectory/>
<CommandLine>//nologo $file/AD_Lost_And_Found_Object_Count.vbs$ $Target/Host/Property[Type="Windows!Microsoft.Windows.Computer"]/NetworkName$ false</CommandLine>
<TimeoutSeconds>300</TimeoutSeconds>
<RequireOutput>true</RequireOutput>
<Files>
<File>
<Name>AD_Lost_And_Found_Object_Count.vbs</Name>
<Contents><Script>
'*************************************************************************
' Script Name - AD Lost And Found Object Count
'
' Purpose - Monitors the number of objects in lost and found contianer
'
' Assumptions - Script is run by a timed event
'
' Parameters - LogSuccessEvent - True/False value to indicates to log an
' an event for script success
' (useful for demos and debugging)
'
' (c) Copyright 2001, Microsoft Corporation, All Rights Reserved
' Proprietary and confidential to Microsoft Corporation
'*************************************************************************
' Other Variables
Dim oParams, TargetFQDNComputer, bLogSuccessEvent, IsTargetAgentless, oAPI, oBag
Set oParams = WScript.Arguments
if oParams.Count < 2 then
Wscript.Quit -1
End if
Dim objAD
Dim dtStart, bBindSuccess
Dim lngObjectCount
Dim strMessage, strComputer
If Not(IsTargetAgentless) Then
Dim errorString
dtStart = Now
strComputer = TargetFQDNComputer
On Error Resume Next
Set objAD = CreateObject("McActiveDir.ActiveDirectory")
If (0 <> Err.Number) Or (Not(IsObject(objAD))) Then
errorString = "The script '" & SCRIPT_NAME & "' failed to create object " & _
"'McActiveDir.ActiveDirectory'. This is an unexpected error." & vbCrLf & vbCrLf & _
GetErrorString(Err.Number, Err.Description) & vbCrLf & vbCrLf & _
"The Active Directory Management Pack Objects (OOMADs) components are not installed on the Domain Controller. These components are required for the monitoring scripts to run successfully. See Alert Knowledge for additional details."
bBindSuccess = objAD.BindLostFoundContainer
If bBindSuccess Then
lngObjectCount = objAD.LostAndFoundCount
End If
If bBindSuccess Then
Set oBag= oAPI.CreateTypedPropertyBag(PerformanceDataType)
Call oBag.AddValue("StatusInstance","")
Call oBag.AddValue("StatusValue","" & lngObjectCount)
Call oAPI.addItem(oBag)
oAPI.ReturnItems
If bLogSuccessEvent Then
strMessage = "There are " & lngObjectCount & " objects in the lost and found container." & vbCrLf & _
"The script '" & SCRIPT_NAME & "' completed in " & DateDiff("s", dtStart, Now) & " seconds."
CreateEvent EVENTID_SUCCESS, EVENT_TYPE_INFORMATION, strMessage
End If
Else
strMessage = "Script '" & SCRIPT_NAME & "' was unable to bind to the lost and found container."
CreateEvent EVENTID_SCRIPT_ERROR, EVENT_TYPE_WARNING, strMessage
End If
Set objAD = Nothing
Else
CreateEvent EVENT_ID_AGENTLESS, EVENT_TYPE_ERROR, "The AD Management Pack does not support the agentless management mode." & vbCrLf & _
"The script '" & SCRIPT_NAME & "' will not execute." & vbCrLf & _
"To prevent this alert being generated again, either change the monitoring " & _
"mode of the computer '" & TargetFQDNComputer & "' to agent-managed " & _
"or disable the rule that generated this alert."
End If
'Else
' strMessage = "The script '" & SCRIPT_NAME & "' can only be executed by an event rule."
' CreateEvent EVENTID_EVENT_RULE_ONLY, EVENT_TYPE_WARNING, strMessage
' End If
End Sub
'******************************************************************************
' Name: CreateEvent
'
' Purpose: Creates a MOM event
'
' Parameters: lngEventID, the ID for the event
' lngEventType, the severity for the event. See constants at head of file
' strMessage, the message for the event
'
' Return: nothing
'
Sub CreateEvent(lngEventID, lngEventType, strMessage)
oAPI.LogScriptEvent "AD Lost And Found Object Count",lngEventID, lngEventType, strMessage
End Sub
'******************************************************************************
' Name: GetErrorString
'
' Purpose: Attempts to find the description for an error if no description
' is passed in.
'
' Parameters: lErrNumber, the error number
' strErrDescription, the error description (if known)
'
' Return: String, the description for the error. (Includes the error code.)
'
Function GetErrorString(lErrNumber, strErrDescription)
On Error Resume Next
If 0 >= Len(strErrDescription) Then
' If we don't have an error description, then check to see if the error
' is a 0x8007xxxx error. If it is, then look it up.
Const ErrorMask = &HFFFF0000
Const HiWord8007 = &H80070000
Const LoWordMask = 65535 ' This is equivalent to 0x0000FFFF
If (lErrNumber And ErrorMask) = HiWord8007 Then
Dim oShell
Set oShell = CreateObject("WScript.Shell")
If IsObject(oShell) Then
Dim oExec
Set oExec = oShell.Exec("net helpmsg " & (lErrNumber And LoWordMask))
Dim strMessage, i
Do
strMessage = oExec.stdout.ReadLine()
i = i + 1
Loop While (Len(strMessage) = 0) And (i < 5)
strErrDescription = strMessage
End If
End If
End If
GetErrorString = "The error returned was '" & strErrDescription & "' (0x" & Hex(lErrNumber) & ")"
End Function