Scopespace tillgänglig avsökning

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

Den här avsökningen returnerar antalet adresser som är lediga, väntande och i bruk för angivet scope i en egenskapsuppsättning. Den här avsökningen används för att kontrollera adresströsklar för tillgänglighetsövervakning och även för att konvertera dessa mått till prestandaräknare som kan tas fram som ramverk eller lagras i informationslager.

Element properties:

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

Member Modules:

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

Source Code:

<ProbeActionModuleType ID="Microsoft.Windows.DHCPServer.Library.Probe.ScopeMonitor" Accessibility="Internal" RunAs="Microsoft.Windows.DHCPServer.Library.ActionAccount" Batching="false" PassThrough="false">
<Configuration>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="TimeoutSeconds" type="xsd:integer"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="TargetComputer" type="xsd:string"/>
</Configuration>
<ModuleImplementation Isolation="Any">
<Composite>
<MemberModules>
<ProbeAction ID="Script" TypeID="Windows!Microsoft.Windows.ScriptPropertyBagProbe">
<ScriptName>DHCPScopeMonitoring.vbs</ScriptName>
<Arguments>"$Config/TargetComputer$"</Arguments>
<ScriptBody><Script>' Copyright (c) Microsoft Corporation. All rights reserved.
' Microsoft Windows DHCP Server Library Scope Monitoring
'
' Returns a property bag containing the number of free, inuse, and pending IP addresses in the specified scope / superscope.
'
' Parameters - TargetComputer The FQDN of the computer targeted by the script.

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 ForReading = 1, ForWriting = 2, ForAppending = 8
Const TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0

Const DHCP_SCRIPTNAME = "DHCPScopeMonitoring.vbs"
Const HKEY_LOCAL_MACHINE = &amp;H80000002
Const DHCP_START_EVENTNUMBER = 1130
Const DHCP_EVENTNUMBER = 1131
Const DHCP_TRACEEVENTNUMBER = 1132
Const DHCP_ERROREVENTNUMBER = 1135
Const DHCP_WARNINGEVENTNUMBER = 1136

Dim oAPI, oShell

Call Main()

Sub Main()
Dim objLogFile, fso, oArgs, objLog, objDataColl, oRegex
Dim strLogStream, strScopeName, sPattern, TargetComputer
Dim strFreeCount, strInUseCount, strPendCount, strIsDisabled
Dim i

Set oAPI = CreateObject("MOM.ScriptAPI")
Set oShell = CreateObject("WScript.Shell")
Set fso = CreateObject("Scripting.FileSystemObject")
Set oArgs = WScript.Arguments

If oArgs.Count &lt;&gt; 1 Then
ThrowErrorAndExit "Usage: " &amp; DHCP_SCRIPTNAME &amp; "&lt;target computer FQDN&gt;"
End If

TargetComputer = oArgs(0)
sPattern = "((.*)\t(.*)\t(.*)\t(.*)\t(.*))"

' Read all data to the registry. GetScriptStateKeyPath returns a 'safe' registry path to write data to/read data from.
' Registry key is ACL'ed with 'Creator Owner' meaning if you create it you alone (plus Admins) can read it.

Dim sRegPath
sRegPath = "HKLM\" &amp; oAPI.GetScriptStateKeyPath("DHCP") &amp; "\ScopePerfData"

On Error Resume Next
strLogStream = oShell.RegRead(sRegPath)
If Err.number &lt;&gt; 0 Then
Call oAPI.LogScriptEvent(DHCP_SCRIPTNAME, DHCP_WARNINGEVENTNUMBER, SCOM_WARNING, _
"RegRead failed with Error = " &amp; Err.number &amp; ". Description = " &amp; Err.Description &amp; vbCrLf &amp; _
"Normally it means that corresponding workflow has not yet populated data for the first time.")
End If
On Error Goto 0

' Parse all needed lines using Regex.
Set oRegex = New RegExp
oRegex.Global = True
oRegex.Multiline = True
oRegex.IgnoreCase = True
oRegex.Pattern = sPattern
Set objDataColl = oRegex.Execute(strLogStream)

Dim oPropertyBag
Set oPropertyBag = oAPI.CreateTypedPropertyBag(SCOM_PB_PERFDATA)

'Call oAPI.LogScriptEvent(DHCP_SCRIPTNAME, DHCP_TRACEEVENTNUMBER, SCOM_INFORMATIONAL, "Registry data at """ &amp; sRegPath &amp; """ has " &amp; objDataColl.count &amp; " lines.")

For i = 0 to objDataColl.count - 1
strScopeName = CStr(objDataColl(i).SubMatches(1))
strFreeCount = CStr(objDataColl(i).SubMatches(2))
strInUseCount = CStr(objDataColl(i).SubMatches(3))
strPendCount = CStr(objDataColl(i).SubMatches(4))
strIsDisabled = CStr(objDataColl(i).SubMatches(5))
strIsDisabled = Left(strIsDisabled,Len(strIsDisabled)-1)

Call oPropertyBag.AddValue(strScopeName &amp; "/" &amp; "Free", strFreeCount)
' IncludeDisabled property
If strIsDisabled = "1" Then
Call oPropertyBag.AddValue(strScopeName &amp; "/" &amp; "Disabled", "1")
Else
Call oPropertyBag.AddValue(strScopeName &amp; "/" &amp; "Disabled", "0")
End If
Call oPropertyBag.AddValue(strScopeName &amp; "/" &amp; "InUse", strInUseCount)
Call oPropertyBag.AddValue(strScopeName &amp; "/" &amp; "Pending", strPendCount)
Next

oAPI.AddItem(oPropertyBag)
oAPI.ReturnItems
End Sub

Sub ThrowErrorAndExit(Message)
Call oAPI.LogScriptEvent(DHCP_SCRIPTNAME, DHCP_ERROREVENTNUMBER, SCOM_ERROR, Message)
WScript.Quit
End Sub
</Script></ScriptBody>
<TimeoutSeconds>$Config/TimeoutSeconds$</TimeoutSeconds>
</ProbeAction>
</MemberModules>
<Composition>
<Node ID="Script"/>
</Composition>
</Composite>
</ModuleImplementation>
<OutputType>System!System.PropertyBagData</OutputType>
<InputType>System!System.BaseData</InputType>
</ProbeActionModuleType>