Sondeo de estado de rendimiento

Microsoft.Windows.DHCPServer.Library.Probe.ACKsAndNAKs (ProbeActionModuleType)

Element properties:

TypeProbeActionModuleType
IsolationAny
AccessibilityInternal
RunAsMicrosoft.Windows.DHCPServer.Library.ActionAccount
OutputTypeSystem.PropertyBagData

Member Modules:

ID Module Type TypeId RunAs 
PassThrough ProbeAction System.PassThroughProbe Default
Script ProbeAction Microsoft.Windows.ScriptPropertyBagProbe Default

Source Code:

<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
'
'-------------------------------------------------------------------

Option Explicit

SetLocale("en-us")

Const SCOM_ERROR = 1
Const SCOM_WARNING = 2
Const SCOM_INFORMATIONAL = 4

' SCOM Property Bag Types
Const SCOM_PB_ALERT = 0
Const SCOM_PB_EVENT = 1
Const SCOM_PB_PERFDATA = 2
Const SCOM_PB_STATEDATA = 3

Const DHCP_SCRIPTNAME = "DHCPPerformanceHealth.vbs"

Const DHCP_START_EVENTNUMBER = 1120
Const DHCP_EVENTNUMBER = 1121
Const DHCP_TRACEEVENTNUMBER = 1122

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 = " &amp; sQuery &amp; vbCrLf &amp; "WMI Namespace = " &amp; 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 '" &amp; sNamespace &amp; "'. 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 &lt;&gt; 0 Then
ThrowScriptError "WMI query '" &amp; sQuery &amp; "' 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 &lt;&gt; 0 Then
ThrowScriptError "The query '" &amp; sQuery &amp; "' did not return any valid instances.", e
End If

Set WMIExecQuery = oQuery

End Function

Class Error

Private m_lNumber
Private m_sSource
Private m_sDescription
Private m_sHelpContext
Private m_sHelpFile

Public Sub Save()

m_lNumber = Err.number
m_sSource = Err.Source
m_sDescription = Err.Description
m_sHelpContext = Err.HelpContext
m_sHelpFile = Err.helpfile

End Sub

Public Sub Raise()

Err.Raise m_lNumber, m_sSource, m_sDescription, m_sHelpFile, m_sHelpContext

End Sub

Public Sub Clear()

m_lNumber = 0
m_sSource = ""
m_sDescription = ""
m_sHelpContext = ""
m_sHelpFile = ""

End Sub

Public Default Property Get Number()

Number = m_lNumber

End Property

Public Property Get Source()

Source = m_sSource

End Property

Public Property Get Description()

Description = m_sDescription

End Property

Public Property Get HelpContext()

HelpContext = m_sHelpContext

End Property

Public Property Get HelpFile()

HelpFile = m_sHelpFile

End Property

End Class

Function IsValidObject(ByVal oObject)
IsValidObject = False

If IsObject(oObject) Then
If Not oObject Is Nothing Then
IsValidObject = True
End If
End If
End Function

Sub ThrowError(Message, Severity)

Call oAPI.LogScriptEvent(DHCP_SCRIPTNAME, SCOM_EVENTNUMBER, Severity, Message)
WScript.Quit

End Sub
Sub ThrowErrorAndExit(Message)

Call oAPI.LogScriptEvent(DHCP_SCRIPTNAME, SCOM_EVENTNUMBER, SCOM_ERROR, Message)
WScript.Quit

End Sub

Sub Trace(Message)

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 &lt;&gt; 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 &lt; 2 Then
ThrowErrorAndExit "Usage: " &amp; ScriptName &amp; "&lt;target computer FQDN&gt; &lt;threshold percentage (1-100)&gt; [debug &lt;true | false&gt;]"
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: " &amp; TargetComputer &amp; " Threshold Percentage: " &amp; dThresholdPrecentage
If (dThresholdPrecentage &lt; 0) Or (dThresholdPrecentage &gt; 100) Then
sInvalidParams = "RequestsVsOffersAndNacksThresholdPercent must be greater then 0 and less then 100." &amp; vbCrLf &amp; _
"The current value of the threshold is " &amp; dThresholdPrecentage &amp; vbCrLf &amp; _
"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:\\" &amp; TargetComputer &amp; "\ROOT\CIMV2", WMI_QUERY)

For Each oPerfData In oPerfDataCollection
Exit For
Next

If Not IsValidObject(oPerfData) Then
ThrowErrorAndExit "Could not execute WMI query '" &amp; WMI_QUERY &amp; "'. code =" &amp; Err.Number
End If

Dim dRequests, dNacks, dOffers

dRequests = CDbl(oPerfData.RequestsPersec)
dNacks = CDbl(oPerfData.NacksPersec)
dOffers = CDbl(oPerfData.OffersPersec)

trace "Requests: " &amp; dRequests &amp; "Offers: " &amp; dOffers &amp; " NACKs: " &amp; dNacks

Set oPropertyBag = oAPI.CreateTypedPropertyBag(SCOM_PB_STATEDATA)
If Err.Number &lt;&gt; 0 Then ThrowErrorAndExit "CreateStateDataTypedPropertyBag failed. code = " &amp; Err.Number

If dRequests &lt;&gt; 0 Then
Dim difference

difference = abs(dRequests - (dNacks + dOffers)) 'get the difference of the requests less the responses

If (difference / dRequests) &gt; dThresholdPrecentage then 'raise threshold error
oPropertyBag.AddValue "state", "ERROR"
Else
oPropertyBag.AddValue "state", "OK"
End If

oAPi.AddItem(oPropertyBag)
If Err.Number &lt;&gt; 0 Then ThrowErrorAndExit "Error adding state data to property bag. code = " &amp; Err.Number
Else
oPropertyBag.AddValue "state", "OK"

oAPi.AddItem(oPropertyBag)
If Err.Number &lt;&gt; 0 Then ThrowErrorAndExit "Error adding state data to property bag. code = " &amp; Err.Number
End If

oAPi.ReturnItems
If Err.Number &lt;&gt; 0 Then ThrowErrorAndExit "Error returning property bag data. code = " &amp; Err.Number

Set oAPI = Nothing
Set oPropertyBag = Nothing
Set oPropertyCollection = Nothing
Set oPerfData = Nothing

trace "Exiting normally"
</Script></ScriptBody>
<TimeoutSeconds>$Config/TimeoutSeconds$</TimeoutSeconds>
</ProbeAction>
</MemberModules>
<Composition>
<Node ID="Script">
<Node ID="PassThrough"/>
</Node>
</Composition>
</Composite>
</ModuleImplementation>
<OutputType>System!System.PropertyBagData</OutputType>
<TriggerOnly>true</TriggerOnly>
</ProbeActionModuleType>