Dostawca odnajdywania obserwatora bazy danych programu Operations Manager

Microsoft.SystemCenter.OpsMgrDBWatcherProvider (DataSourceModuleType)

Element properties:

TypeDataSourceModuleType
IsolationAny
AccessibilityInternal
RunAsDefault
OutputTypeSystem.Discovery.Data

Member Modules:

ID Module Type TypeId RunAs 
DS DataSource Microsoft.Windows.TimedPowerShell.DiscoveryProvider Default

Overrideable Parameters:

IDParameterTypeSelectorDisplay NameDescription
IntervalSecondsint$Config/IntervalSeconds$Interwał czasowy w sekundach
TimeoutSecondsint$Config/TimeoutSeconds$Limit czasu w sekundach

Source Code:

<DataSourceModuleType ID="Microsoft.SystemCenter.OpsMgrDBWatcherProvider" Accessibility="Internal" Batching="false">
<Configuration>
<xsd:element name="IntervalSeconds" type="xsd:integer"/>
<xsd:element name="TargetDisplayName" type="xsd:string"/>
<xsd:element name="TimeoutSeconds" type="xsd:int"/>
</Configuration>
<OverrideableParameters>
<OverrideableParameter ID="IntervalSeconds" Selector="$Config/IntervalSeconds$" ParameterType="int"/>
<OverrideableParameter ID="TimeoutSeconds" Selector="$Config/TimeoutSeconds$" ParameterType="int"/>
</OverrideableParameters>
<ModuleImplementation Isolation="Any">
<Composite>
<MemberModules>
<DataSource ID="DS" TypeID="Windows!Microsoft.Windows.TimedPowerShell.DiscoveryProvider">
<IntervalSeconds>$Config/IntervalSeconds$</IntervalSeconds>
<SyncTime/>
<ScriptName>GetOpsMgrDBWatcherDiscovery.ps1</ScriptName>
<ScriptBody><Script>
param($targetDisplayName)

Set-StrictMode -Version 2

$SCOMPowerShellKey = "HKLM:\SOFTWARE\Microsoft\System Center Operations Manager\12\Setup\Powershell\V2"
$SCOMModulePath = Join-Path (Get-ItemProperty $SCOMPowerShellKey).InstallDirectory &#x201C;OperationsManager&#x201D;
Import-module $SCOMModulePath

Set-Variable SCRIPTNAME -Option Constant -Value "GetOpsMgrDBWatcherDiscovery.ps1"
Set-Variable SCOM_EVENTNUMBER -Option Constant -Value 1199
Set-Variable SCOM_ERROR -Option Constant -Value 1

$Error.Clear()

$api = New-Object -ComObject "MOM.ScriptAPI"
$discoveryData = $api.CreateDiscoveryData(0, "$MPElement$", "$Target/Id$")

function ThrowErrorAndExit($message)
{
$Error.Clear()
$api.LogScriptEvent($SCRIPTNAME, $SCOM_EVENTNUMBER, $SCOM_ERROR, $message)
exit
}

function GetComputerName()
{
$type = Add-Type -MemberDefinition $signature -Name Win32Utils -Namespace GetComputerNameEx -Using System.Text -PassThru
$computerNameDnsFullyQualified = 3
$nameLength = 0
$type::GetComputerNameEx($computerNameDnsFullyQualified, $null, [ref]$nameLength)
$builder = New-Object System.Text.StringBuilder $nameLength
$type::GetComputerNameEx($computerNameDnsFullyQualified, $builder, [ref]$nameLength)
$builder.ToString()
}

function GetWatcherProperty($value)
{
$key = "HKLM:\SOFTWARE\Microsoft\Microsoft Operations Manager\3.0\Setup\"
(Get-ItemProperty $key $value).$value
}

# use WinApi to get computer name

$signature = @'
[DllImport("kernel32.dll")]
public static extern int GetComputerNameEx(
int nameType,
StringBuilder nameBuffer,
ref uint nameBufferSize);
'@

$type = Add-Type -MemberDefinition $signature -Name Win32Utils -Namespace GetComputerNameEx -Using System.Text -PassThru
$computerNameDnsFullyQualified = 3
$nameLength = 0
$type::GetComputerNameEx($computerNameDnsFullyQualified, $null, [ref]$nameLength)
$sbLength = [int]$nameLength #Type casting to int, string builder class accepts only numeric datatypes.
$builder = New-Object System.Text.StringBuilder $sbLength
$type::GetComputerNameEx($computerNameDnsFullyQualified, $builder, [ref]$nameLength)

$computerName = $builder.ToString()

$dbServerName = GetWatcherProperty("DatabaseServerName")
if ($Error.Count -gt 0)
{
ThrowErrorAndExit("Error returning Database Server Name.")
}

$databaseName = GetWatcherProperty("DatabaseName")
if ($Error.Count -gt 0)
{
ThrowErrorAndExit("Error returning Database Name.")
}

$dbWatcherName = $targetDisplayName + " DB Watcher"

$instance = $discoveryData.CreateClassInstance("$MPElement[Name='SCLibrary!Microsoft.SystemCenter.OpsMgrDBWatcher']$")
if ($Error.Count -gt 0)
{
ThrowErrorAndExit("Unable to Create Instance.")
}

$instance.AddProperty("$MPElement[Name='Windows!Microsoft.Windows.Computer']/PrincipalName$", $computerName)
$instance.AddProperty("$MPElement[Name='SCLibrary!Microsoft.SystemCenter.OpsMgrDBWatcher']/DatabaseServerName$", $dbServerName)
$instance.AddProperty("$MPElement[Name='SCLibrary!Microsoft.SystemCenter.OpsMgrDBWatcher']/DatabaseName$", $databaseName)
$instance.AddProperty("$MPElement[Name='System!System.Entity']/DisplayName$", $dbWatcherName)
$discoveryData.AddInstance($instance)

$discoveryData
</Script></ScriptBody>
<Parameters>
<Parameter>
<Name>targetDisplayName</Name>
<Value>$Config/TargetDisplayName$</Value>
</Parameter>
</Parameters>
<TimeoutSeconds>$Config/TimeoutSeconds$</TimeoutSeconds>
</DataSource>
</MemberModules>
<Composition>
<Node ID="DS"/>
</Composition>
</Composite>
</ModuleImplementation>
<OutputType>System!System.Discovery.Data</OutputType>
</DataSourceModuleType>