Ta sonda zwraca liczbę wolnych, oczekujących oraz używanych adresów dla określonego zakresu w zbiorze właściwości. Ta sonda jest używana do sprawdzania progów adresów na potrzeby monitorowania dostępności, jak również do konwertowania tych metryk na liczniki wydajności, które mogą być przedstawiane na wykresach lub zapisywane w magazynie danych.
<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.
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 <> 1 Then
ThrowErrorAndExit "Usage: " & DHCP_SCRIPTNAME & "<target computer FQDN>"
End If
' 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\" & oAPI.GetScriptStateKeyPath("DHCP") & "\ScopePerfData"
On Error Resume Next
strLogStream = oShell.RegRead(sRegPath)
If Err.number <> 0 Then
Call oAPI.LogScriptEvent(DHCP_SCRIPTNAME, DHCP_WARNINGEVENTNUMBER, SCOM_WARNING, _
"RegRead failed with Error = " & Err.number & ". Description = " & Err.Description & vbCrLf & _
"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 """ & sRegPath & """ has " & objDataColl.count & " 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 & "/" & "Free", strFreeCount)
' IncludeDisabled property
If strIsDisabled = "1" Then
Call oPropertyBag.AddValue(strScopeName & "/" & "Disabled", "1")
Else
Call oPropertyBag.AddValue(strScopeName & "/" & "Disabled", "0")
End If
Call oPropertyBag.AddValue(strScopeName & "/" & "InUse", strInUseCount)
Call oPropertyBag.AddValue(strScopeName & "/" & "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>