DPM data source discovery (D-D)
Microsoft.SystemCenter.DataProtectionManager.2011.Discovery.DToDDatasourceDiscovery (Discovery)
DPM data source discovery (Disk-to-Disk).
Element properties: Object Discovery Details: Member Modules:
Source Code: <Discovery ID="Microsoft.SystemCenter.DataProtectionManager.2011.Discovery.DToDDatasourceDiscovery" Enabled="true" Target="SCDPM!Microsoft.SystemCenter.DataProtectionManager.2011.Library.ReplicaVolume" ConfirmDelivery="true" Remotable="true" Priority="Normal">
<Category>Discovery</Category>
<DiscoveryTypes>
<DiscoveryClass TypeID="SCDPM!Microsoft.SystemCenter.DataProtectionManager.2011.Library.ApplicationDatasource"/>
<DiscoveryClass TypeID="SCDPM!Microsoft.SystemCenter.DataProtectionManager.2011.Library.FileSystemDatasource"/>
<DiscoveryClass TypeID="SCDPM!Microsoft.SystemCenter.DataProtectionManager.2011.Library.ClientDatasource"/>
<DiscoveryClass TypeID="SCDPM!Microsoft.SystemCenter.DataProtectionManager.2011.Library.ExchangeDatasource"/>
<DiscoveryClass TypeID="SCDPM!Microsoft.SystemCenter.DataProtectionManager.2011.Library.HyperVDatasource"/>
<DiscoveryClass TypeID="SCDPM!Microsoft.SystemCenter.DataProtectionManager.2011.Library.SharePointDatasource"/>
<DiscoveryClass TypeID="SCDPM!Microsoft.SystemCenter.DataProtectionManager.2011.Library.SQLDatasource"/>
<DiscoveryClass TypeID="SCDPM!Microsoft.SystemCenter.DataProtectionManager.2011.Library.SystemStateDatasource"/>
<DiscoveryClass TypeID="SCDPM!Microsoft.SystemCenter.DataProtectionManager.2011.Library.VirtualServerDatasource"/>
<DiscoveryRelationship TypeID="SCDPM!Microsoft.SystemCenter.DataProtectionManager.2011.Library.PGHostsDatasource"/>
<DiscoveryRelationship TypeID="SCDPM!Microsoft.SystemCenter.DataProtectionManager.2011.Library.PSContainsDatasource"/>
<DiscoveryRelationship TypeID="SCDPM!Microsoft.SystemCenter.DataProtectionManager.2011.Library.ReplicaVolumeContainsDatasource"/>
<DiscoveryRelationship TypeID="SCDPM!Microsoft.SystemCenter.DataProtectionManager.2011.Library.DPMLibraryContainsDatasource"/>
</DiscoveryTypes>
<DataSource ID="DatasourceDiscovery" TypeID="Windows!Microsoft.Windows.TimedPowerShell.DiscoveryProvider">
<IntervalSeconds>43200</IntervalSeconds>
<SyncTime>06:00</SyncTime>
<ScriptName>DatasourceDiscovery.ps1</ScriptName>
<ScriptBody><Script> #Read input parameters
param($sourceType,$sourceId,$managedEntityId,$dpmServerName,$volumeId)
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);
}
$desc = "D-D datasource discovery start event for ReplicaID =" + $volumeId.ToString()
DisplayError $desc 0 119 $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)
$guid_volumeId = [GUID]$volumeId
$dpmServer = $null
try
{
#Connect to DPM server
$err = $($dpmServer = Connect-DPMServer -DPMServerName $dpmServerName) 2>&1
if (!$dpmServer)
{
$desc = "D-D datasource discovery - Unable to connect to DPM Server=" + $dpmServerName
if($err)
{
DisplayError $desc 1 120 $err.Exception.ToString() $err.Exception.Error.Resolution.ToString()
}
else
{
DisplayError $desc 1 120 $null $null
}
exit 1
}
#sleepTime is in mili-sec
$sleepTime = 8*1000;
$regKeyExists = Test-Path "hklm:\SOFTWARE\Microsoft\Microsoft Data Protection Manager\Configuration";
if($regKeyExists)
{
$prop = get-itemProperty "hklm:\SOFTWARE\Microsoft\Microsoft Data Protection Manager\Configuration";
if($prop -ne $null)
{
if($prop.DToDDiscoveryScriptSleepTimeInSec -ne $null)
{
if($prop.DToDDiscoveryScriptSleepTimeInSec.GetType() -eq [Int32])
{
$sleepTimeInRegKey = $prop.DToDDiscoveryScriptSleepTimeInSec;
if($sleepTimeInRegKey -le 100 -and $sleepTimeInRegKey -ge 0)
{
$sleepTime = ($sleepTimeInRegKey/5)*1000;
}
Remove-Variable sleepTimeInRegKey -Confirm:$false
}
}
Remove-Variable prop -Confirm:$false
}
}
#Get ds list for the replica volume
$err = $($dsList = Get-Datasource -DPMServerName $dpmServerName | ?{$_.Protected -and $_.ProtectionGroup.IsDiskShortTerm}) 2>&1
if($err)
{
$desc = "Unable to retrieve datasource list in D-D discovery"
DisplayError $desc 1 120 $err.Exception.ToString() $err.Exception.Error.Resolution.ToString()
}
# Sleep is added to make sure script does not take lot of CPU when lot of instances of the scripts are run by SCOM
sleep -m $sleepTime
if($dsList)
{
$dsList = $dsList | ?{$_.AssociatedReplica.PhysicalReplicaId -eq $guid_volumeId};
$dsList = @($dsList | Sort-Object $_.Name);
}
# Sleep is added to make sure script does not take lot of CPU when lot of instances of the scripts are run by SCOM
sleep -m $sleepTime
$libInstance = $null;
if($dsList -ne $null)
{
if($dsList[0].ProtectionGroup.IsTapeLongTerm)
{
#Create the corresponding Library class instance
$libInstance = $discoveryData.CreateClassInstance("$MPElement[Name="SCDPM!Microsoft.SystemCenter.DataProtectionManager.2011.Library.DPMLibrary"]$")
$libInstance.AddProperty("$MPElement[Name='Windows!Microsoft.Windows.Computer']/PrincipalName$", $dpmServerName)
$libInstance.AddProperty("$MPElement[Name='SCDPM!Microsoft.SystemCenter.DataProtectionManager.2011.Library.DPMSeed']/DPMServerName$", $dpmServerName)
$libInstance.AddProperty("$MPElement[Name='SCDPM!Microsoft.SystemCenter.DataProtectionManager.2011.Library.DPMServer']/DPMServerName$", $dpmServerName)
$libInstance.AddProperty("$MPElement[Name='SCDPM!Microsoft.SystemCenter.DataProtectionManager.2011.Library.DPMLibrary']/DPMObjectID$", $dsList[0].ProtectionGroup.ArchiveIntent.LibraryId.ToString())
}
}
#Create the corresponding ReplicaVolume class instance
$volInstance = $discoveryData.CreateClassInstance("$MPElement[Name="SCDPM!Microsoft.SystemCenter.DataProtectionManager.2011.Library.ReplicaVolume"]$")
$volInstance.AddProperty("$MPElement[Name='Windows!Microsoft.Windows.Computer']/PrincipalName$", $dpmServerName)
$volInstance.AddProperty("$MPElement[Name='SCDPM!Microsoft.SystemCenter.DataProtectionManager.2011.Library.DPMSeed']/DPMServerName$", $dpmServerName)
$volInstance.AddProperty("$MPElement[Name='SCDPM!Microsoft.SystemCenter.DataProtectionManager.2011.Library.DPMServer']/DPMServerName$", $dpmServerName)
$volInstance.AddProperty("$MPElement[Name='SCDPM!Microsoft.SystemCenter.DataProtectionManager.2011.Library.ReplicaVolume']/DPMObjectID$", $volumeId.ToString())
# Sleep is added to make sure script does not take lot of CPU when lot of instances of the scripts are run by SCOM
sleep -m $sleepTime
foreach ($ds in $dsList)
{
if($ds -and ($ds.ReferentialDatasourceId -eq [System.Guid]::Empty))
{
$dsInstance = $null
$isSharepointDatasource = $false
$genericDatasource = $false
#Create a Datasource instance
Switch($ds.Type.Id)
{
#File system datasource
{$_ -eq [Microsoft.Internal.EnterpriseStorage.Dls.EngineUICommon.VssWriterId]::FileSystem}
{
$dsInstance = $discoveryData.CreateClassInstance("$MPElement[Name="SCDPM!Microsoft.SystemCenter.DataProtectionManager.2011.Library.FileSystemDatasource"]$")
}
#Client datasource
{$_ -eq [Microsoft.Internal.EnterpriseStorage.Dls.EngineUICommon.VssWriterId]::DisconnectedClient}
{
$dsInstance = $discoveryData.CreateClassInstance("$MPElement[Name="SCDPM!Microsoft.SystemCenter.DataProtectionManager.2011.Library.ClientDatasource"]$")
}
#SQL datasource
{($_ -eq [Microsoft.Internal.EnterpriseStorage.Dls.EngineUICommon.VssWriterId]::MSDE) -or
($_ -eq [Microsoft.Internal.EnterpriseStorage.Dls.EngineUICommon.VssWriterId]::Yukon)}
{
$dsInstance = $discoveryData.CreateClassInstance("$MPElement[Name="SCDPM!Microsoft.SystemCenter.DataProtectionManager.2011.Library.SQLDatasource"]$")
$sqlDs = $ds -as [Microsoft.Internal.EnterpriseStorage.Dls.UI.ObjectModel.SQL.SQLDataSource]
$dsInstance.AddProperty('$MPElement[Name="SCDPM!Microsoft.SystemCenter.DataProtectionManager.2011.Library.SQLDatasource"]/SQLInstance$', $sqlDs.Instance)
}
#HyperV datasource
{$_ -eq [Microsoft.Internal.EnterpriseStorage.Dls.EngineUICommon.VssWriterId]::HyperVServer}
{
$dsInstance = $discoveryData.CreateClassInstance("$MPElement[Name="SCDPM!Microsoft.SystemCenter.DataProtectionManager.2011.Library.HyperVDatasource"]$")
}
#Virtual server datasource
{$_ -eq [Microsoft.Internal.EnterpriseStorage.Dls.EngineUICommon.VssWriterId]::VirtualServer}
{
$dsInstance = $discoveryData.CreateClassInstance("$MPElement[Name="SCDPM!Microsoft.SystemCenter.DataProtectionManager.2011.Library.VirtualServerDatasource"]$")
}
#System state datasource
{$_ -eq [Microsoft.Internal.EnterpriseStorage.Dls.EngineUICommon.VssWriterId]::SystemState}
{
$dsInstance = $discoveryData.CreateClassInstance("$MPElement[Name="SCDPM!Microsoft.SystemCenter.DataProtectionManager.2011.Library.SystemStateDatasource"]$")
}
#Sharepoint datasource
{($_ -eq [Microsoft.Internal.EnterpriseStorage.Dls.EngineUICommon.VssWriterId]::Sharepoint) -or
($_ -eq [Microsoft.Internal.EnterpriseStorage.Dls.EngineUICommon.VssWriterId]::Sharepoint4) -or
($_ -eq [Microsoft.Internal.EnterpriseStorage.Dls.EngineUICommon.VssWriterId]::SpSearch) -or
($_ -eq [Microsoft.Internal.EnterpriseStorage.Dls.EngineUICommon.VssWriterId]::OfficeSearch) -or
($_ -eq [Microsoft.Internal.EnterpriseStorage.Dls.EngineUICommon.VssWriterId]::VirtualSPSearch) -or
($_ -eq [Microsoft.Internal.EnterpriseStorage.Dls.EngineUICommon.VssWriterId]::VirtualSSP)}
{
$isSharepointDatasource = $true
$dsInstance = $discoveryData.CreateClassInstance("$MPElement[Name="SCDPM!Microsoft.SystemCenter.DataProtectionManager.2011.Library.SharePointDatasource"]$")
}
#Exchange datasource
{($_ -eq [Microsoft.Internal.EnterpriseStorage.Dls.EngineUICommon.VssWriterId]::E14) -or
($_ -eq [Microsoft.Internal.EnterpriseStorage.Dls.EngineUICommon.VssWriterId]::Exchange)}
{
$dsInstance = $discoveryData.CreateClassInstance("$MPElement[Name="SCDPM!Microsoft.SystemCenter.DataProtectionManager.2011.Library.ExchangeDatasource"]$")
}
default
{
$dsInstance = $discoveryData.CreateClassInstance("$MPElement[Name="SCDPM!Microsoft.SystemCenter.DataProtectionManager.2011.Library.ApplicationDatasource"]$")
$genericDatasource = $true
}
}
$dsInstance.AddProperty("$MPElement[Name='Windows!Microsoft.Windows.Computer']/PrincipalName$", $dpmServerName)
$dsInstance.AddProperty("$MPElement[Name='SCDPM!Microsoft.SystemCenter.DataProtectionManager.2011.Library.DPMSeed']/DPMServerName$", $dpmServerName)
$dsInstance.AddProperty("$MPElement[Name='SCDPM!Microsoft.SystemCenter.DataProtectionManager.2011.Library.DPMServer']/DPMServerName$", $dpmServerName)
$dsInstance.AddProperty("$MPElement[Name='SCDPM!Microsoft.SystemCenter.DataProtectionManager.2011.Library.ProtectionGroup']/DPMObjectID$", $ds.ProtectionGroupId.ToString())
$dsName = $null
if($ds.Type.Id -eq [Microsoft.Internal.EnterpriseStorage.Dls.EngineUICommon.VssWriterId]::FileSystem -or
$ds.Type.Id -eq [Microsoft.Internal.EnterpriseStorage.Dls.EngineUICommon.VssWriterId]::SystemState -or
$ds.Type.Id -eq [Microsoft.Internal.EnterpriseStorage.Dls.EngineUICommon.VssWriterId]::HyperVServer -or
$genericDatasource -eq $true)
{
$dsName = $ds.DisplayPath + "(" + $ds.ProductionServerName + ")"
}
else
{
$dsName = $ds.DisplayPath
}
$dsInstance.AddProperty("$MPElement[Name='System!System.Entity']/DisplayName$", $dsName)
$dsInstance.AddProperty("$MPElement[Name='SCDPM!Microsoft.SystemCenter.DataProtectionManager.2011.Library.DataSource']/DPMServerName$", $dpmServerName)
$dsInstance.AddProperty("$MPElement[Name='SCDPM!Microsoft.SystemCenter.DataProtectionManager.2011.Library.DataSource']/PGName$", $ds.ProtectionGroupName)
$dsInstance.AddProperty("$MPElement[Name='SCDPM!Microsoft.SystemCenter.DataProtectionManager.2011.Library.DataSource']/PSName$", $ds.ProductionServerName)
$dsInstance.AddProperty("$MPElement[Name='SCDPM!Microsoft.SystemCenter.DataProtectionManager.2011.Library.DataSource']/DPMObjectID$", $ds.DatasourceId.ToString())
$dsInstance.AddProperty("$MPElement[Name='SCDPM!Microsoft.SystemCenter.DataProtectionManager.2011.Library.DataSource']/IsSecondaryProtected$", $ds.IsDPMDatasource)
$dsInstance.AddProperty("$MPElement[Name='SCDPM!Microsoft.SystemCenter.DataProtectionManager.2011.Library.DataSource']/DatasourceType$", $ds.Type.Name)
$dsInstance.AddProperty("$MPElement[Name='SCDPM!Microsoft.SystemCenter.DataProtectionManager.2011.Library.DataSource']/SourceDPM$", $ds.SourceDPMServer)
$discoveryData.AddInstance($dsInstance)
#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 the corresponding PS class instance
$psInstance = $discoveryData.CreateClassInstance("$MPElement[Name="SCDPM!Microsoft.SystemCenter.DataProtectionManager.2011.Library.ProductionServer"]$")
$psInstance.AddProperty("$MPElement[Name='Windows!Microsoft.Windows.Computer']/PrincipalName$", $dpmServerName)
$psInstance.AddProperty("$MPElement[Name='SCDPM!Microsoft.SystemCenter.DataProtectionManager.2011.Library.DPMSeed']/DPMServerName$", $dpmServerName)
$psInstance.AddProperty("$MPElement[Name='SCDPM!Microsoft.SystemCenter.DataProtectionManager.2011.Library.DPMServer']/DPMServerName$", $dpmServerName)
$psInstance.AddProperty("$MPElement[Name='SCDPM!Microsoft.SystemCenter.DataProtectionManager.2011.Library.ProductionServer']/ComputerName$", $ds.PSInfo.Name)
$psInstance.AddProperty("$MPElement[Name='SCDPM!Microsoft.SystemCenter.DataProtectionManager.2011.Library.ProductionServer']/DPMServerName$", $dpmServerName)
if($libInstance -ne $null)
{
#Create Library to Datasource relationship instance
$libRelationInstance = $discoveryData.CreateRelationshipInstance("$MPElement[Name="SCDPM!Microsoft.SystemCenter.DataProtectionManager.2011.Library.DPMLibraryContainsDatasource"]$")
$libRelationInstance.Source = $libInstance
$libRelationInstance.Target = $dsRelInstance
$discoveryData.AddInstance($libRelationInstance)
Remove-Variable libRelationInstance -Confirm:$false
}
if($ds.Type.Id -ne [Microsoft.Internal.EnterpriseStorage.Dls.EngineUICommon.VssWriterId]::DisconnectedClient)
{
#Create PS to Datasource relationship instance
$psRelationInstance = $discoveryData.CreateRelationshipInstance("$MPElement[Name="SCDPM!Microsoft.SystemCenter.DataProtectionManager.2011.Library.PSContainsDatasource"]$")
$psRelationInstance.Source = $psInstance
$psRelationInstance.Target = $dsRelInstance
$discoveryData.AddInstance($psRelationInstance)
Remove-Variable psRelationInstance -Confirm:$false
}
#Create ReplicaVolume to Datasource relationship instance
$volRelationInstance = $discoveryData.CreateRelationshipInstance("$MPElement[Name="SCDPM!Microsoft.SystemCenter.DataProtectionManager.2011.Library.ReplicaVolumeContainsDatasource"]$")
$volRelationInstance.Source = $volInstance
$volRelationInstance.Target = $dsRelInstance
$discoveryData.AddInstance($volRelationInstance)
Remove-Variable volRelationInstance -Confirm:$false
Remove-Variable dsRelInstance -Confirm:$false
Remove-Variable psInstance -Confirm:$false
Remove-Variable dsInstance -Confirm:$false
}
}
# Sleep is added to make sure script does not take lot of CPU when lot of instances of the scripts are run by SCOM
sleep -m $sleepTime
}
catch
{
$desc = "Exception in D-D datasource discovery"
DisplayError $desc 1 120 $_.ToString() $null
throw $_
}
#Make OM call to publish alerts.
try
{
if($dpmServer -ne $null)
{
$dpmServer.PublishAlertsDelayed();
}
}
catch
{
$desc = "Exception in D-D datasource discovery while publishing alerts"
DisplayError $desc 1 120 $_.ToString() $null
}
$desc = "D-D datasource discovery completed event for ReplicaID =" + $volumeId.ToString()
DisplayError $desc 0 121 $null $null
$discoveryData
#Cleanup Variables
Remove-Variable regKeyExists -Confirm:$false
Remove-Variable sleepTime -Confirm:$false
Remove-Variable sourceType -Confirm:$false
Remove-Variable sourceId -Confirm:$false
Remove-Variable managedEntityId -Confirm:$false
Remove-Variable discoveryData -Confirm:$false
Remove-Variable volInstance -Confirm:$false
Remove-Variable libInstance -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.ReplicaVolume"]/DPMServerName$</Value>
</Parameter>
<Parameter>
<Name>VolumeId</Name>
<Value>$Target/Property[Type="SCDPM!Microsoft.SystemCenter.DataProtectionManager.2011.Library.ReplicaVolume"]/DPMObjectID$</Value>
</Parameter>
</Parameters>
<TimeoutSeconds>7200</TimeoutSeconds>
</DataSource>
</Discovery>