Dell FM Server Discovery Datasource

Dell.ManagedServer.FMServerUnhosted.Discovery.DataSource (DataSourceModuleType)

Discovery Datasource for FM Server

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$Interval SecondsDell FM Server discovery interval seconds
TimeoutSecondsint$Config/TimeoutSeconds$Timeout SecondsDell FM Server Unhosted discovery Timeout seconds
LogLevelint$Config/LogLevel$Log LevelDell FM Server Unhosted discovery logging level

Source Code:

<DataSourceModuleType ID="Dell.ManagedServer.FMServerUnhosted.Discovery.DataSource" Accessibility="Internal" Batching="false">
<Configuration>
<IncludeSchemaTypes>
<SchemaType>Windows!Microsoft.Windows.PowerShellSchema</SchemaType>
</IncludeSchemaTypes>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" minOccurs="1" name="IntervalSeconds" type="xsd:int"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" minOccurs="1" name="TimeoutSeconds" type="xsd:int"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" minOccurs="1" name="LogLevel" type="xsd:int"/>
</Configuration>
<OverrideableParameters>
<OverrideableParameter ID="IntervalSeconds" Selector="$Config/IntervalSeconds$" ParameterType="int"/>
<OverrideableParameter ID="TimeoutSeconds" Selector="$Config/TimeoutSeconds$" ParameterType="int"/>
<OverrideableParameter ID="LogLevel" Selector="$Config/LogLevel$" ParameterType="int"/>
</OverrideableParameters>
<ModuleImplementation Isolation="Any">
<Composite>
<MemberModules>
<DataSource ID="DS" TypeID="Windows!Microsoft.Windows.TimedPowerShell.DiscoveryProvider">
<IntervalSeconds>$Config/IntervalSeconds$</IntervalSeconds>
<SyncTime/>
<ScriptName>StompUnhostedPSScpt.ps1</ScriptName>
<ScriptBody><Script>
param($sourceID, $managedEntityID,$logLevel, $logDirectory)
$MSComputerName = (hostname)
$methodtype = 'Discovery'
$DebugScript = $false
$logDirectory = "DellFMServer_Logs"

Function Write-Info
{
param ([string] $msg)
Write-Host $msg
}
Function Write-WarningInfo
{
param ([string] $msg)
#Write-Host $msg
}
Function Write-ErrorInfo
{
param ([string] $msg)
#Write-Host $msg
}

$LogLocation = $env:SystemRoot + "\Temp" + "\" + $logDirectory + "\"
$aquaXMLPath=$LogLocation +"aquaSled.xml"

# Logging Header
If ($logLevel -ne 0)
{
#$LogLocation =[environment]::GetEnvironMentVariable("temp","machine") + "\" + $logDirectory + "\"
If(!(Test-Path -path($LogLocation)))
{
# create the directory if not present
New-Item $LogLocation -type directory
}
$Global:LogFileLocation = $LogLocation + "Dell_ManaagedFMServer_" + $MSComputerName + ".log"
If(!(Test-Path -path($LogFileLocation)))
{
# create the file if it does not exist
New-Item $LogFileLocation -type file
}
Else
{
$logFileSize = Get-ChildItem $LogFileLocation | ForEach-Object {($_.Length/1KB)}
If ($logFileSize -gt 512)
{
# existingLogFile is greater than 512 KB
$archiveTime = Get-Date -f "yyyy-MM-dd_HH.mm"
Rename-Item $LogFileLocation ("ArchivedLog_IPAddress_" + $chassisIP + "_" + $archiveTime + ".log")
New-Item $LogFileLocation -type file
}
}
}

Function psDebugLog
{
param($level, $message)
if (($level -gt 0))
{
$currentTime = Get-Date -f "yyyy-MM-dd_HH.mm.ss"
Out-File -FilePath $LogFileLocation -InputObject ($currentTime + " :: " + $message) -Append
#Write-Host $message
}
}

$scom2012intf = new-module {

[object]$connection = $null
[string] $state = ''
[string] $loglocation = '.\test.log'
[int] $loglevel = 1
[string] $product = "SCOM 2012"

Function Write-Info
{
param ([string] $msg)
#Write-Host $msg
}

Function psDebugLog
{
param($level, $message)
if (($level -gt 0) -and ($level -le $logLevel))
{
$currentTime = Get-Date -f "yyyy-MM-dd_HH.mm.ss"
Out-File -FilePath $this.loglocation -InputObject ($currentTime + " :: " + $message) -Append
}
}

Function GetConnection()
{
psDebugLog -level 1 -message $this.state

$managementServerName = ""
$persistConnection = $false
$interactive = $false
$MachineRegErrorMsg = "Can not find Operations Manager Management Server name for the local machine.";
$UserRegKeyPath = "HKCU:\software\Microsoft\Microsoft Operations Manager\3.0\User Settings";
$MachineRegKeyPath = "HKLM:\software\Microsoft\Microsoft Operations Manager\3.0\Machine Settings";
$UserRegValueName = "SDKServiceMachine";
$MachineRegValueName = "DefaultSDKServiceMachine";
$ConnectingMsg = "Connecting to Operations Manager Management Server '{0}'.";
$ConnectErrorMsg = "Can not connect to Operations Manager Management Server '{0}'.";
$AccessDeniedErrorMsg = "Access is denied to Operations Manager Management Server '{0}'.";
$ConnectPromptMsg = "Enter the name of the Operations Manager Management Server to connect to.";
$ConnectPrompt = "Management Server";
$serviceNotRunningErrorMsg = "The Data Access service is either not running or not yet initialized. Check the event log for more information.";
$HostNotFoundErrorMsg = "No such host is known";

$regKey = $null;
$regValue = $null;

# Set the initial server value to the MS argument.
# If the argument is empty the normal registry lookup sequence will kickin.
# If the argument is not empty the user will be connected to the specified connection.
$server = $managementServerName;
$drive = $null;

# Get the User Operations Manager Product Registry Key
if ($server -eq $null -or $server.Length -eq 0)
{
$regValue = Get-ItemProperty -path:$UserRegKeyPath -name:$UserRegValueName -ErrorAction:SilentlyContinue;

if ($regValue -ne $null)
{
$server = $regValue.SDKServiceMachine;
}
}

if ($server -eq $null -or $server.Length -eq 0)
{
# Get the Machine Operations Manager Product Registry Key if the user setting could not be found.
$regValue = Get-ItemProperty -path:$MachineRegKeyPath -name:$MachineRegValueName -ErrorAction:SilentlyContinue;

if ($regValue -ne $null)
{
$server = $regValue.DefaultSDKServiceMachine;
}
}

# If the default Operations Manager Management Server name can not be found in the registry then default to 'localhost'.
if ($server -eq $null -or $server.Length -eq 0)
{
psDebugLog -level 1 -message $MachineRegErrorMsg
$server = "localhost";
}

# Create a connection and make it the current location.
$this.connection = $null;

if ($server -ne $null -and $server.Length -gt 0)
{
# Format the connecting message.
$msg = $ConnectingMsg -f $server;
psDebugLog -level 1 -message $msg

# Create the new connection.
$this.connection = New-SCOMManagementGroupConnection -ComputerName: $server -PassThru -ErrorAction:Stop
}
$this.state = 'connected'
return $this.connection
}

Function PrintDebug()
{
Write-Info -msg ("Product: " + $this.Product)
Write-Info -msg ("State: " + $this.State)
}

Function LoadSnapins()
{
Import-Module OperationsManager
$this.state = 'snapins loaded'
}

Function GetManagementPacks()
{
psDebugLog -level 1 -message $this.state
return (Get-SCManagementPack)
}

Function InstallManagementPack($ImportPath)
{
Import-SCManagementPack $ImportPath -ErrorAction:SilentlyContinue -ErrorVariable v
return $v
}

Function UninstallManagementPack($ManagementPack)
{
Remove-SCManagementPack -ManagementPack $ManagementPack -ErrorAction:SilentlyContinue -ErrorVariable v
return $v
}

Function GetClassDetails($className)
{
return (Get-SCOMClass | where { $_.Name -eq $className })
}
Function GetManagementServer()
{
return (Get-SCOMManagementServer| sort-object DisplayName -Descending)
}
Function GetMonitoringProperty($refObject, $attribute)
{
$retValue = $null
$temp = $null
$property = $refObject.GetProperties() | where { $_.Name -eq $attribute }
if($property -ne $null)
{
if($refObject.TryGetProperty($property, [ref] $temp))
{
$retValue = $temp
}
}
$retValue
}

Function GetAllMonitoringObjectsOfAClass($class)
{
Get-SCOMClassInstance -class $class
}

Function GetRelatedObjects($cmcObject)
{
$slots = Get-SCRelationshipInstance -SourceInstance $cmcObject
return $slots
}

Function GetMonitoringObjectWithCriteria()
{

}

Function IsAChildObject($object, $chassisSlotSummaryClass)
{
return ( ($object.TargetObject -ne $null) -and
($object.TargetObject.ManagementPackClassIds -ne $null) -and
($object.TargetObject.ManagementPackClassIds.Contains($chassisSlotSummaryClass.Id)) );
}

Function GetTargetObjectInRelationship($object)
{
return ($object.TargetObject)
}

Function GetSourceObjectInRelationship($object)
{
return ($object.SourceObject)
}

Export-ModuleMember -Function * -variable *
} -asCustomObject


$MachineRegKeyPath = "HKLM:\software\Microsoft\Microsoft Operations Manager\3.0\Setup";
$MachineRegValueName = "SKU";
$skuName = $null; $skuVersion = $null
$skuName = Get-ItemProperty -path:$MachineRegKeyPath -name:$MachineRegValueName -ErrorAction:SilentlyContinue;
$skuVersion = Get-ItemProperty -path:$MachineRegKeyPath -name:"CurrentVersion" -ErrorAction:SilentlyContinue;
$scomenv = $scom2012intf
$scomenv.loglocation = $LogFileLocation
$scomenv.loglevel = $logLevel
$scomenv.LoadSnapins()
$scomenv.PrintDebug()
$scomenv.GetConnection() | OUT-NULL

# Main logic
psDebugLog -level 1 -message ("Source ID: " + $sourceID)
psDebugLog -level 1 -message ("Managed Entity ID: " + $managedEntityID)
$oAPI = new-object -comObject "MOM.ScriptAPI"
$discoveryData = $oAPI.CreateDiscoveryData(0, $sourceID, $managedEntityID)

# get all ms (need to filter Manitainance Mode)
$managementServers =$scomenv.GetManagementServer() | where-object {$_.HealthState -ne "Uninitialized"}

# iSM
$className= $scomenv.GetClassDetails("Dell.ManagedServer.SledNode")
$notePropety='[Dell.ManagedServer].ServiceTag'
$scClassInstance = $scomenv.GetAllMonitoringObjectsOfAClass($className) | sort-Object $notePropety -Descending

psDebugLog -level 1 -message ("Class : " + $scClassInstance)

#Hash table to keep track of service tags and its node
$hashTable=@{}
#Maintain Array of server nodes
$arry=@()

if($scClassInstance -ne $null)
{
foreach($serverInst in $scClassInstance)
{
$serverTagObj=$serverInst.$notePropety
[string]$serverTag=$serverTagObj.Value
psDebugLog 1 ("Adding "+ $serverTag + " to Hash table")
if($hashTable.ContainsKey($serverTag))
{
$arry = @($serverInst)
$arry+= $hashTable[$serverTag]
$hashTable[$serverTag] = $arry
}
else
{
$arry = @($serverInst)
$hashTable.Add($serverTag,$arry)
}
}
}
psDebugLog 1 ("Hash table : "+$hashTable.Keys)

# Form Aqua SLED object
Function FormAquaSled
{
PARAM([string]$ServiceTag,[string]$hostMgmtServer,$ARYServer)
$arryServer=@($ARYServer)

# Create health service instance for the proxy computer. This will be used as the source in the relationship to ensure that agent on proxy agent manages the discovered instances.
$healthServiceInstance = $discoveryData.CreateClassInstance("$MPElement[Name='SC!Microsoft.SystemCenter.HealthService']$" )
$healthServiceInstance.AddProperty("$MPElement[Name='Windows!Microsoft.Windows.Computer']/PrincipalName$",$hostMgmtServer)
$discoveryData.AddInstance($healthServiceInstance)
$instance = $discoveryData.CreateClassInstance("$MPElement[Name='DellModelServer!Dell.Server.FMServer']$")
psDebugLog -level 1 -message ("Aqua Sled Object ID: " + "$MPElement[Name='DellModelServer!Dell.Server.FMServer']$")
psDebugLog -level 1 -message ("HostMgmtServer Object : " + $hostMgmtServer)
$instance.AddProperty("$MPElement[Name='DellModelServer!Dell.Server.FMServer']/ServiceTag$",$ServiceTag)
$instance.AddProperty("$MPElement[Name='DellModelServer!Dell.Server.FMServer']/HostManagementServer$",$hostMgmtServer)
$sledName="Dell FM Server: "+$ServiceTag
psDebugLog -level 1 -message ("Dell FM Server name : " + $sledName)
$instance.AddProperty("$MPElement[Name='System!System.Entity']/DisplayName$",$sledName)
$discoveryData.AddInstance($instance)

# Create an instance of the HealthServiceShouldManageEntity class. This ensures that the target instance (the discovered network device) is managed on the agent of the source (the proxy computer).
$healthServiceRelationship = $discoveryData.CreateRelationshipInstance("$MPElement[Name='SC!Microsoft.SystemCenter.HealthServiceShouldManageEntity']$")
$healthServiceRelationship.Source = $healthServiceInstance
$healthServiceRelationship.Target = $instance
$discoveryData.AddInstance($healthServiceRelationship)

ForEach ($serverNode in $arryServer)
{
psDebugLog -level 1 -message ("Server Nodes " + $serverNode)
$serverUID= $serverNode.'[Dell.ManagedServer].UID'
psDebugLog -level 1 -message ("Server UID " + $serverUID.Value)
$Instance3 = $discoveryData.CreateClassInstance("$MPElement[Name='DellManagedServer!Dell.ManagedServer.SledNode']$")
$Instance3.AddProperty("$MPElement[Name='DellManagedServer!Dell.ManagedServer']/UID$", $serverUID.Value)
#psDebugLog -level 1 -message ("Dell Server Object Element" + "$MPElement[Name='DellManagedServer!Dell.ManagedServer']$")
$oRelationship1 = $discoveryData.CreateRelationshipInstance("$MPElement[Name='DellManagedServer!Dell.FMServer.Contains.Dell.Managed.SledNode']$")
$oRelationship1.Source = $instance
$oRelationship1.Target = $Instance3
$discoveryData.AddInstance($oRelationship1)
}
}

$msIndex=0
$msList = New-Object System.Collections.ArrayList
if (!($managementServers.GetType().IsArray))
{
$msList.Add($managementServers)
}
else{
$msList = $managementServers
}

foreach($svTagKeys in $hashTable.Keys)
{
if ($msIndex -eq $msList.Count)
{
$msIndex = 0;
}
$hostMgmtServer=$msList[$msIndex].DisplayName
psDebugLog 1 ("Host management server "+$hostMgmtServer)
psDebugLog 1 ("Hash table SERVICE TAG "+$svTagKeys)
$monObjArray=@($hashTable[$svTagKeys])
FormAquaSled -ServiceTag $svTagKeys -hostMgmtServer $hostMgmtServer -ARYServer $monObjArray
$msIndex = $msIndex + 1
}

psDebugLog 1 " End of Discovery script "
psDebugLog 1 "----------------------------------------------"
$discoveryData
$oAPI.Return($discoveryData)

</Script></ScriptBody>
<Parameters>
<Parameter>
<Name>sourceID</Name>
<Value>$MPElement$</Value>
</Parameter>
<Parameter>
<Name>managedEntityID</Name>
<Value>$Target/Id$</Value>
</Parameter>
<Parameter>
<Name>logLevel</Name>
<Value>$Config/LogLevel$</Value>
</Parameter>
</Parameters>
<TimeoutSeconds>$Config/TimeoutSeconds$</TimeoutSeconds>
</DataSource>
</MemberModules>
<Composition>
<Node ID="DS"/>
</Composition>
</Composite>
</ModuleImplementation>
<OutputType>System!System.Discovery.Data</OutputType>
</DataSourceModuleType>