Détection de la relation entre la bibliothèque et la source de données (D-B)
Microsoft.SystemCenter.DataProtectionManager.2011.Discovery.DToTLibraryRelationDiscovery (Discovery)
Détection de la relation entre la bibliothèque et la source de données (disque à bande).
Element properties: Object Discovery Details: Member Modules:
Source Code: <Discovery ID="Microsoft.SystemCenter.DataProtectionManager.2011.Discovery.DToTLibraryRelationDiscovery" Enabled="true" Target="SCDPM!Microsoft.SystemCenter.DataProtectionManager.2011.Library.ProtectionGroup" ConfirmDelivery="true" Remotable="true" Priority="Normal">
<Category>Discovery</Category>
<DiscoveryTypes>
<DiscoveryClass TypeID="SCDPM!Microsoft.SystemCenter.DataProtectionManager.2011.Library.DataSource"/>
<DiscoveryRelationship TypeID="SCDPM!Microsoft.SystemCenter.DataProtectionManager.2011.Library.DPMLibraryContainsDatasource"/>
</DiscoveryTypes>
<DataSource ID="DtoTLibraryRelationDiscovery" TypeID="Windows!Microsoft.Windows.TimedPowerShell.DiscoveryProvider">
<IntervalSeconds>43200</IntervalSeconds>
<SyncTime>06:00</SyncTime>
<ScriptName>DatasourceDtoTLibraryRelationDiscovery.ps1</ScriptName>
<ScriptBody><Script> #Read input parameters
param($sourceType, $sourceId, $managedEntityId, [string] $dpmServerName, $pgId)
function DisplayError()
{
param($description, $severity, $errorCode, $exceptionString, $resolutionString)
$evt = new-object System.Diagnostics.EventLog("DPM Alerts");
$evt.Source = "DPM-EM";
$eventSeverity = [System.Diagnostics.EventLogEntryType]::Information;
#severity = 0 is info and severity = 1 is warning
if($severity -eq 1)
{
$eventSeverity = [System.Diagnostics.EventLogEntryType]::Warning;
}
$errString = new-object system.text.stringBuilder
$errString.AppendLine($description)
if($exceptionString -ne $null)
{
$errString.AppendLine()
$errString.AppendLine("Problem: " + $exceptionString)
}
if($resolutionString -ne $null)
{
$errString.AppendLine()
$errString.AppendLine("Resolution: " + $resolutionString)
}
$evt.WriteEntry($errString.ToString(), $eventSeverity, $errorCode);
}
#######################################################################################
## This script discovers the relation between Library and D-T DS
#######################################################################################
$desc = "D-T DS - Library relation discovery started event. PgId = " + $pgId
DisplayError $desc 0 114 $null $null
# Load DPM snapin
$dpmBinPath = (Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\Microsoft Data Protection Manager\Setup" "UIInstallPath").UIInstallPath
. "$dpmBinPath\GlobalFunctions.ps1"
LoadDPMSnapin
#Create and Instantinate SCOM discovery objects
$api = New-Object -ComObject 'MOM.ScriptAPI'
$discoveryData = $api.CreateDiscoveryData($sourceType, $sourceId, $managedEntityId)
try
{
$guid_pgId = [GUID]$pgId
#Connect to DPM server
$err = $($dpmServer = Connect-DPMServer -DPMServerName $dpmServerName) 2>&1
if (!$dpmServer)
{
$desc = "D-T DS - Library relation discovery exited event as could not connect to dpm server = " + $dpmServerName
if($err)
{
DisplayError $desc 1 115 $err.Exception.ToString() $err.Exception.Error.Resolution.ToString()
}
else
{
DisplayError $desc 1 115 $null $null
}
exit 1
}
#Get D-T PG object for which we want to discover DSes
$err = $($pg = Get-ProtectionGroup -DPMServerName $dpmServerName | Where{($_.PGProtectionType -ieq "DiskToTape" -or $_.PGProtectionType -ieq "DiskToTapeToTape") -and $_.ProtectionGroupId -eq $guid_pgId}) 2>&1
if($err)
{
$desc = "Unable to retrieve PG list in D-T datasource Library relation discovery"
DisplayError $desc 1 115 $err.Exception.ToString() $err.Exception.Error.Resolution.ToString()
}
if($pg)
{
#Get library for PG
$libraryInstance = $discoveryData.CreateClassInstance('$MPElement[Name="SCDPM!Microsoft.SystemCenter.DataProtectionManager.2011.Library.DPMLibrary"]$');
$libraryInstance.AddProperty('$MPElement[Name="Windows!Microsoft.Windows.Computer"]/PrincipalName$', $dpmServerName);
$libraryInstance.AddProperty('$MPElement[Name="SCDPM!Microsoft.SystemCenter.DataProtectionManager.2011.Library.DPMSeed"]/DPMServerName$', $dpmServerName)
$libraryInstance.AddProperty('$MPElement[Name="SCDPM!Microsoft.SystemCenter.DataProtectionManager.2011.Library.DPMServer"]/DPMServerName$', $dpmServerName)
$libraryInstance.AddProperty('$MPElement[Name="SCDPM!Microsoft.SystemCenter.DataProtectionManager.2011.Library.DPMLibrary"]/DPMObjectID$', $pg.ArchiveIntent.LibraryId.ToString());
#Get all DSes for the PG
$err = $($dsList = @(Get-Datasource -ProtectionGroup $pg)) 2>&1
if($err)
{
$desc = "Unable to retrieve datasource list in D-T datasource Library relation discovery"
DisplayError $desc 1 115 $err.Exception.ToString() $err.Exception.Error.Resolution.ToString()
}
if($dsList)
{
$dsList = $dsList | Sort-Object $_.Name
}
if($dsList)
{
foreach($ds in $dsList)
{
#Create a separate instance for the datasource class, This is required becasue SCOM will not discover containment relationships
#if it has derived class properties in the instance.
$dsRelInstance = $discoveryData.CreateClassInstance('$MPElement[Name="SCDPM!Microsoft.SystemCenter.DataProtectionManager.2011.Library.DataSource"]$');
$dsRelInstance.AddProperty("$MPElement[Name='Windows!Microsoft.Windows.Computer']/PrincipalName$", $dpmServerName)
$dsRelInstance.AddProperty("$MPElement[Name='SCDPM!Microsoft.SystemCenter.DataProtectionManager.2011.Library.DPMSeed']/DPMServerName$", $dpmServerName)
$dsRelInstance.AddProperty("$MPElement[Name='SCDPM!Microsoft.SystemCenter.DataProtectionManager.2011.Library.DPMServer']/DPMServerName$", $dpmServerName)
$dsRelInstance.AddProperty("$MPElement[Name='SCDPM!Microsoft.SystemCenter.DataProtectionManager.2011.Library.ProtectionGroup']/DPMObjectID$", $ds.ProtectionGroupId.ToString())
$dsRelInstance.AddProperty("$MPElement[Name='SCDPM!Microsoft.SystemCenter.DataProtectionManager.2011.Library.DataSource']/DPMObjectID$", $ds.DatasourceId.ToString())
#Create Library to DS relationship instance
$libraryToDsRelationInstance = $discoveryData.CreateRelationshipInstance('$MPElement[Name="SCDPM!Microsoft.SystemCenter.DataProtectionManager.2011.Library.DPMLibraryContainsDatasource"]$');
$libraryToDsRelationInstance.Source = $libraryInstance;
$libraryToDsRelationInstance.Target = $dsRelInstance;
$discoveryData.AddInstance($libraryToDsRelationInstance);
Remove-Variable dsRelInstance -Confirm:$false
Remove-Variable libraryToDsRelationInstance -Confirm:$false
}
}
Remove-Variable libraryInstance -Confirm:$false
}
}
catch
{
$desc = "Exception in D-T datasource Library relation discovery"
DisplayError $desc 1 115 $_.ToString() $null
throw $_
}
$desc = "D-T DS Library relation discovery completed event. PgId = " + $pgId
DisplayError $desc 0 115 $null $null
#return discovery data
$discoveryData
#Cleanup Variables
Remove-Variable sourceType -Confirm:$false
Remove-Variable sourceId -Confirm:$false
Remove-Variable managedEntityId -Confirm:$false
Remove-Variable discoveryData -Confirm:$false
Remove-Variable api -Confirm:$false
</Script> </ScriptBody>
<Parameters>
<Parameter>
<Name>SourceType</Name>
<Value>0</Value>
</Parameter>
<Parameter>
<Name>SourceId</Name>
<Value>$MPElement$</Value>
</Parameter>
<Parameter>
<Name>ManagedEntityId</Name>
<Value>$Target/Id$</Value>
</Parameter>
<Parameter>
<Name>DPMServerName</Name>
<Value>$Target/Property[Type="SCDPM!Microsoft.SystemCenter.DataProtectionManager.2011.Library.ProtectionGroup"]/DPMServerName$</Value>
</Parameter>
<Parameter>
<Name>PgId</Name>
<Value>$Target/Property[Type="SCDPM!Microsoft.SystemCenter.DataProtectionManager.2011.Library.ProtectionGroup"]/DPMObjectID$</Value>
</Parameter>
</Parameters>
<TimeoutSeconds>7200</TimeoutSeconds>
</DataSource>
</Discovery>