<ProbeActionModuleType ID="Microsoft.Windows.DHCPServer.Library.Probe.ACKsAndNAKs" Accessibility="Internal" RunAs="Microsoft.Windows.DHCPServer.Library.ActionAccount" Batching="false" PassThrough="false">
<Configuration>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="TargetComputer" type="xsd:string"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="ThresholdPercentage" type="xsd:integer"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="DebugFlag" type="xsd:boolean"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="TimeoutSeconds" type="xsd:integer"/>
</Configuration>
<ModuleImplementation Isolation="Any">
<Composite>
<MemberModules>
<ProbeAction ID="PassThrough" TypeID="System!System.PassThroughProbe"/>
<ProbeAction ID="Script" TypeID="Windows!Microsoft.Windows.ScriptPropertyBagProbe">
<ScriptName>DHCPPerformanceHealth.vbs</ScriptName>
<Arguments>"$Config/TargetComputer$" "$Config/ThresholdPercentage$" $Config/DebugFlag$</Arguments>
<ScriptBody><Script>'-------------------------------------------------------------------
' Microsoft Corporation
' Copyright (c) Microsoft Corporation. All rights reserved.
' Microsoft Windows DHCP Server Library Performance Health Script
'
' Compares Requests to (Offers + Nacks).
' Alerts if amount exceeds the threshold parameter.
'
' Assumptions - Script is run by a performance rule. It does not need to
' be a threshold rule.
'
' Parameters - TargetComputer The FQDN of the computer targeted by the script.
' ThresholdPercentage Percentage above which this script should report failure
' DebugFlag True / False
'
'-------------------------------------------------------------------
Function WMIExecQuery(ByVal sNamespace, ByVal sQuery)
'
' WMIExecQuery :: Executes the WMI query and returns the result set.
'
'
Dim oWMI, oQuery, nInstanceCount
Dim e
trace "WMI query = " & sQuery & vbCrLf & "WMI Namespace = " & sNamespace
Set e = New Error
On Error Resume Next
Set oWMI = GetObject(sNamespace)
e.Save
On Error Goto 0
If IsEmpty(oWMI) Then
ThrowScriptError "Unable to open WMI namespace '" & sNamespace & "'. Check to see if the WMI service is enabled and running, and ensure this WMI namespace exists.", e
End If
On Error Resume Next
Set oQuery = oWMI.ExecQuery(sQuery)
e.Save
On Error Goto 0
If IsEmpty(oQuery) Or e.Number <> 0 Then
ThrowScriptError "WMI query '" & sQuery & "' returned an invalid result set.", e
End If
'Determine if we queried a valid WMI class - Count will return 0 or empty
On Error Resume Next
nInstanceCount = oQuery.Count
e.Save
On Error Goto 0
If e.Number <> 0 Then
ThrowScriptError "The query '" & sQuery & "' did not return any valid instances.", e
End If
if (oDebugFlag = true) Then
Call oAPI.LogScriptEvent(DHCP_SCRIPTNAME, DHCP_TRACEEVENTNUMBER, SCOM_INFORMATIONAL, Message)
End if
End Sub
Dim bFailed, oDebugFlag
bFailed = False
Dim ImagePath, oWMI, rc, oArgs, oAPI, oDiscoveryData, oInst, SourceID, ManagedEntityId, TargetComputer, dThresholdPrecentage
Dim oPropertyBag, sInvalidParams
Set oArgs = WScript.Arguments
On Error Resume Next
Set oAPI = CreateObject("MOM.ScriptAPI")
If Err.Number <> 0 Then
wscript.Quit
End if
' If the script is called without the required arguments,
' create an information event and then quit.
If oArgs.Count < 2 Then
ThrowErrorAndExit "Usage: " & ScriptName & "<target computer FQDN> <threshold percentage (1-100)> [debug <true | false>]"
End If
TargetComputer = oArgs(0) ' The FQDN of the computer targeted by the script.
dThresholdPrecentage = Cdbl(oArgs(1))
If (oArgs.Count = 3) Then
oDebugFlag = cbool(oArgs(2))
Else
oDebugFlag = cbool(false)
End if
trace "TargetComputer: " & TargetComputer & " Threshold Percentage: " & dThresholdPrecentage
If (dThresholdPrecentage < 0) Or (dThresholdPrecentage > 100) Then
sInvalidParams = "RequestsVsOffersAndNacksThresholdPercent must be greater then 0 and less then 100." & vbCrLf & _
"The current value of the threshold is " & dThresholdPrecentage & vbCrLf & _
"The threshold will be set to 2 until the problem has been corrected."
dThresholdPrecentage = 2
ThrowError strInvalidParms, SCOM_WARNING
End If
Dim oPerfData, oPerfDataCollection
Const WMI_QUERY = "select RequestsPersec, NacksPersec, OffersPersec from Win32_PerfFormattedData_DHCPServer_DHCPServer"
Set oPerfDataCollection = WMIExecQuery("winmgmts:\\" & TargetComputer & "\ROOT\CIMV2", WMI_QUERY)
For Each oPerfData In oPerfDataCollection
Exit For
Next
If Not IsValidObject(oPerfData) Then
ThrowErrorAndExit "Could not execute WMI query '" & WMI_QUERY & "'. code =" & Err.Number
End If
trace "Requests: " & dRequests & "Offers: " & dOffers & " NACKs: " & dNacks
Set oPropertyBag = oAPI.CreateTypedPropertyBag(SCOM_PB_STATEDATA)
If Err.Number <> 0 Then ThrowErrorAndExit "CreateStateDataTypedPropertyBag failed. code = " & Err.Number
If dRequests <> 0 Then
Dim difference
difference = abs(dRequests - (dNacks + dOffers)) 'get the difference of the requests less the responses
If (difference / dRequests) > dThresholdPrecentage then 'raise threshold error
oPropertyBag.AddValue "state", "ERROR"
Else
oPropertyBag.AddValue "state", "OK"
End If
oAPi.AddItem(oPropertyBag)
If Err.Number <> 0 Then ThrowErrorAndExit "Error adding state data to property bag. code = " & Err.Number
Else
oPropertyBag.AddValue "state", "OK"
oAPi.AddItem(oPropertyBag)
If Err.Number <> 0 Then ThrowErrorAndExit "Error adding state data to property bag. code = " & Err.Number
End If
oAPi.ReturnItems
If Err.Number <> 0 Then ThrowErrorAndExit "Error returning property bag data. code = " & Err.Number
Set oAPI = Nothing
Set oPropertyBag = Nothing
Set oPropertyCollection = Nothing
Set oPerfData = Nothing