AD Lost Object Count Monitortype

Microsoft.Windows.Server.2003.AD.DomainController.LostObjectCount.Monitortype (UnitMonitorType)

Element properties:

RunAsDefault
AccessibilityInternal
Support Monitor RecalculateFalse

Member Modules:

ID Module Type TypeId RunAs 
ScriptDS DataSource System.CommandExecuterPropertyBagSource Default
FilterError ConditionDetection System.ExpressionFilter Default
FilterSuccess ConditionDetection System.ExpressionFilter Default
FilterWarn ConditionDetection System.ExpressionFilter Default
PerfMapper ConditionDetection System.Performance.DataGenericMapper Default

Overrideable Parameters:

IDParameterTypeSelectorDisplay NameDescription
IntervalSecondsint$Config/IntervalSeconds$Interval (sec)
LostObjectCountWarningThresholdint$Config/LostObjectCountWarningThreshold$
LostObjectCountErrorThresholdint$Config/LostObjectCountErrorThreshold$

Source Code:

<UnitMonitorType ID="Microsoft.Windows.Server.2003.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>120</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
'*************************************************************************

Option Explicit

'Event Constants
Const EVENT_TYPE_SUCCESS = 0
Const EVENT_TYPE_ERROR = 1
Const EVENT_TYPE_WARNING = 2
Const EVENT_TYPE_INFORMATION = 4

' Event ID Constants
Const EVENTID_EVENT_RULE_ONLY = 2
Const EVENTID_SUCCESS = 99
Const EVENTID_SCRIPT_ERROR = 1000
Const EVENT_ID_AGENTLESS = 98

'Other constants
Const SCRIPT_NAME = "AD Lost And Found Object Count"

' TypedPropertyBag
const PerformanceDataType = 2
const StateDataType = 3

' Other Variables
Dim oParams, TargetFQDNComputer, bLogSuccessEvent, IsTargetAgentless, oAPI, oBag
Set oParams = WScript.Arguments
if oParams.Count &lt; 2 then
Wscript.Quit -1
End if

TargetFQDNComputer = oParams(0)
bLogSuccessEvent = CBool( oParams(1))
IsTargetAgentless = False
Set oAPI = CreateObject("Mom.ScriptAPI")
Err.Clear

Sub Main()

Dim objAD
Dim dtStart, bBindSuccess
Dim lngObjectCount
Dim strMessage, strComputer

If Not(IsTargetAgentless) Then
dtStart = Now
strComputer = TargetFQDNComputer

On Error Resume Next
Set objAD = CreateObject("McActiveDir.ActiveDirectory")
If (0 &lt;&gt; Err.Number) Or (Not(IsObject(objAD))) Then
CreateEvent EVENTID_SCRIPT_ERROR, EVENT_TYPE_WARNING, "The script '" &amp; SCRIPT_NAME &amp; "' failed to create object " &amp; _
"'McActiveDir.ActiveDirectory'. This is an unexpected error." &amp; vbCrLf &amp; _
GetErrorString(Err.Number, Err.Description)
Exit Sub
End If

objAD.Server = strComputer

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","" &amp; lngObjectCount)
Call oAPI.addItem(oBag)
oAPI.ReturnItems

If bLogSuccessEvent Then
strMessage = "There are " &amp; lngObjectCount &amp; " objects in the lost and found container." &amp; vbCrLf &amp; _
"The script '" &amp; SCRIPT_NAME &amp; "' completed in " &amp; DateDiff("s", dtStart, Now) &amp; " seconds."
CreateEvent EVENTID_SUCCESS, EVENT_TYPE_INFORMATION, strMessage
End If
Else
strMessage = "Script '" &amp; SCRIPT_NAME &amp; "' 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." &amp; vbCrLf &amp; _
"The script '" &amp; SCRIPT_NAME &amp; "' will not execute." &amp; vbCrLf &amp; _
"To prevent this alert being generated again, either change the monitoring " &amp; _
"mode of the computer '" &amp; TargetFQDNComputer &amp; "' to agent-managed " &amp; _
"or disable the rule that generated this alert."

End If
'Else
' strMessage = "The script '" &amp; SCRIPT_NAME &amp; "' 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 &gt;= 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 = &amp;HFFFF0000
Const HiWord8007 = &amp;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 " &amp; (lErrNumber And LoWordMask))

Dim strMessage, i
Do
strMessage = oExec.stdout.ReadLine()
i = i + 1
Loop While (Len(strMessage) = 0) And (i &lt; 5)

strErrDescription = strMessage
End If
End If
End If

GetErrorString = "The error returned was '" &amp; strErrDescription &amp; "' (0x" &amp; Hex(lErrNumber) &amp; ")"
End Function

Call Main()

</Script></Contents>
<Unicode>1</Unicode>
</File>
</Files>
</DataSource>
<ConditionDetection ID="PerfMapper" TypeID="SystemPerf!System.Performance.DataGenericMapper">
<ObjectName>ActiveDirectoryMP</ObjectName>
<CounterName>Active Directory Lost Objects</CounterName>
<InstanceName>$data/Property[@Name='StatusInstance']$</InstanceName>
<Value>$data/Property[@Name='StatusValue']$</Value>
</ConditionDetection>
<ConditionDetection ID="FilterSuccess" TypeID="System!System.ExpressionFilter">
<Expression>
<SimpleExpression>
<ValueExpression>
<XPathQuery Type="Integer">Value</XPathQuery>
</ValueExpression>
<Operator>LessEqual</Operator>
<ValueExpression>
<Value Type="Integer">$Config/LostObjectCountWarningThreshold$</Value>
</ValueExpression>
</SimpleExpression>
</Expression>
</ConditionDetection>
<ConditionDetection ID="FilterWarn" TypeID="System!System.ExpressionFilter">
<Expression>
<And>
<Expression>
<SimpleExpression>
<ValueExpression>
<XPathQuery Type="Double">Value</XPathQuery>
</ValueExpression>
<Operator>Greater</Operator>
<ValueExpression>
<Value Type="Integer">$Config/LostObjectCountWarningThreshold$</Value>
</ValueExpression>
</SimpleExpression>
</Expression>
<Expression>
<SimpleExpression>
<ValueExpression>
<XPathQuery Type="Double">Value</XPathQuery>
</ValueExpression>
<Operator>LessEqual</Operator>
<ValueExpression>
<Value Type="Double">100</Value>
</ValueExpression>
</SimpleExpression>
</Expression>
</And>
</Expression>
</ConditionDetection>
<ConditionDetection ID="FilterError" TypeID="System!System.ExpressionFilter">
<Expression>
<SimpleExpression>
<ValueExpression>
<XPathQuery Type="Double">Value</XPathQuery>
</ValueExpression>
<Operator>Greater</Operator>
<ValueExpression>
<Value Type="Integer">$Config/LostObjectCountErrorThreshold$</Value>
</ValueExpression>
</SimpleExpression>
</Expression>
</ConditionDetection>
</MemberModules>
<RegularDetections>
<RegularDetection MonitorTypeStateID="OK">
<Node ID="FilterSuccess">
<Node ID="PerfMapper">
<Node ID="ScriptDS"/>
</Node>
</Node>
</RegularDetection>
<RegularDetection MonitorTypeStateID="Warn">
<Node ID="FilterWarn">
<Node ID="PerfMapper">
<Node ID="ScriptDS"/>
</Node>
</Node>
</RegularDetection>
<RegularDetection MonitorTypeStateID="Error">
<Node ID="FilterError">
<Node ID="PerfMapper">
<Node ID="ScriptDS"/>
</Node>
</Node>
</RegularDetection>
</RegularDetections>
</MonitorImplementation>
</UnitMonitorType>