Fujitsu PRIMERGY Discovery Data Source for Fujitsu PRIMERGY Discovery Rule

Fujitsu.Servers.PRIMERGY.ESXi.Seed.Server.Discovery.DataSource (DataSourceModuleType)

Flat file based Discovery Data Source for Fujitsu PRIMERGY Discovery Rule

Element properties:

TypeDataSourceModuleType
IsolationAny
AccessibilityPublic
RunAsDefault
OutputTypeSystem.Discovery.Data

Member Modules:

ID Module Type TypeId RunAs 
Scheduler DataSource System.Discovery.Scheduler Default
Script ProbeAction Microsoft.Windows.PowerShellDiscoveryProbe Default

Overrideable Parameters:

IDParameterTypeSelectorDisplay NameDescription
IntervalSecondsint$Config/IntervalSeconds$Interval SecondsThis parameter determines seconds interval for Data Source

Source Code:

<DataSourceModuleType ID="Fujitsu.Servers.PRIMERGY.ESXi.Seed.Server.Discovery.DataSource" Accessibility="Public" Batching="false">
<Configuration>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="IntervalSeconds" type="xsd:integer"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="HostServer" type="xsd:string"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="IPList" type="xsd:string"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="ServerName" type="xsd:string"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="OpSystem" type="xsd:string"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="NoCertCheck" type="xsd:string"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="CIMPort" type="xsd:string"/>
</Configuration>
<OverrideableParameters>
<OverrideableParameter ID="IntervalSeconds" Selector="$Config/IntervalSeconds$" ParameterType="int"/>
</OverrideableParameters>
<ModuleImplementation Isolation="Any">
<Composite>
<MemberModules>
<DataSource ID="Scheduler" TypeID="System!System.Discovery.Scheduler">
<Scheduler>
<SimpleReccuringSchedule>
<Interval>$Config/IntervalSeconds$</Interval>
<SyncTime/>
</SimpleReccuringSchedule>
<ExcludeDates/>
</Scheduler>
</DataSource>
<ProbeAction ID="Script" TypeID="Windows!Microsoft.Windows.PowerShellDiscoveryProbe">
<ScriptName>SeedDiscovery.ps1</ScriptName>
<ScriptBody><Script>
#-------------------------------------------------------------------
# Fujitsu
# Copyright 2015-2019 FUJITSU LIMITED
#
# SeedDiscovery.ps1
#
# Summary:
# Seed Discovery for Fujitsu PRIMERGY ESXi Servers.
#
#-------------------------------------------------------------------

Param (
[string] $SourceId,
[string] $ManagedEntityId,
[string] $PrincipalName,
[string] $HostServer,
[string] $IPList,
[string] $ServerName,
[string] $OpSystem,
[string] $NoCertCheck,
[string] $CIMPort,
[switch] $OutsideManagementPack
)

Import-Module ("$FileResource[Name='Fujitsu.Servers.PRIMERGY.PS.CommonModule']/Path$", "$PSScriptRoot\Modules\CommonModule.psm1")[[bool]$OutsideManagementPack]

$ValidHostnameRegex = "^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9])$"

function Main {
Initialize-Log

try {
$oAPI = New-SCOMApiObject -OutsideManagementPack:$OutsideManagementPack
$oDiscoveryData = $oAPI.CreateDiscoveryData(0, $SourceId, $ManagedEntityId)

# check if it is proper Host Server we are running on
if ($PrincipalName -ieq $HostServer)
{
$aIPList = $IPList.split(';')
$aServerName = $ServerName.Split(';')
$aOpSystem = $OpSystem.Split(';')
$aNoCertCheck = $NoCertCheck.Split(';')
$aCIMPort = $CIMPort.Split(';')

# add ESXi servers from list
for ($i = 0; $i -le $IPList.Length; $i++) {
$hostname = $aServerName[$i]
$ipaddress = $aIPList[$i]
if ($hostname -match $ValidHostnameRegex) {
# try to determine network name for ESXi server
$NetworkName = $ipaddress
$nslookup = (Resolve-NSLookup $ipaddress)
if ($nslookup -ne $null -and !$nslookup.Name.Equals("")) {
$NetworkName = $nslookup.Name
} elseif (($hostname -ine "localhost" -and $hostname -ne "127.0.0.1") -and (Test-Connection -ComputerName $hostname -Count 2 -Quiet)) {
$NetworkName = $hostname
}
# add ESXi server to SCOM
$oInst = $oDiscoveryData.CreateClassInstance("$MPElement[Name='FTSESXSEED!Fujitsu.Servers.PRIMERGY.ESXiSeed.Server']$")
$oInst.AddProperty("$MPElement[Name='Windows!Microsoft.Windows.Computer']/PrincipalName$", "$PrincipalName")
$oInst.AddProperty("$MPElement[Name='FTSESXSEED!Fujitsu.Servers.PRIMERGY.ESXiSeed.HostServer']/PrincipalName$", "$PrincipalName")
$oInst.AddProperty("$MPElement[Name='System!System.Entity']/DisplayName$", "$($aIPList[$i])")
$oInst.AddProperty("$MPElement[Name='FTSESXSEED!Fujitsu.Servers.PRIMERGY.ESXiSeed.Server']/PrincipalName$", "$hostname")
$oInst.AddProperty("$MPElement[Name='FTSESXSEED!Fujitsu.Servers.PRIMERGY.ESXiSeed.Server']/HostServer$", "$PrincipalName")
$oInst.AddProperty("$MPElement[Name='FTSESXSEED!Fujitsu.Servers.PRIMERGY.ESXiSeed.Server']/OperatingSystem$", "$($aOpSystem[$i])")
$oInst.AddProperty("$MPElement[Name='FTSESXSEED!Fujitsu.Servers.PRIMERGY.ESXiSeed.Server']/IPAddress$", "$ipaddress")
$oInst.AddProperty("$MPElement[Name='FTSESXSEED!Fujitsu.Servers.PRIMERGY.ESXiSeed.Server']/NetworkName$", "$NetworkName")
$oInst.AddProperty("$MPElement[Name='FTSESXSEED!Fujitsu.Servers.PRIMERGY.ESXiSeed.Server']/NoCertCheck$", "$($aNoCertCheck[$i])")
$oInst.AddProperty("$MPElement[Name='FTSESXSEED!Fujitsu.Servers.PRIMERGY.ESXiSeed.Server']/CIMPort$", $aCIMPort[$i])
$oDiscoveryData.AddInstance($oInst)
}
}
}

$oDiscoveryData
} catch {
$ErrorMessage = $_.Exception.Message
Write-LogDebug "SourceId = $SourceId"
Write-LogDebug "ManagedEntityId = $ManagedEntityId"
Write-LogDebug "PrincipalName = $PrincipalName"
Write-LogDebug "HostServer = $HostServer"
Write-LogDebug "IPList = $IPList"
Write-LogDebug "ServerName = $ServerName"
Write-LogDebug "OpSystem = $OpSystem"
Write-LogDebug "NoCertCheck = $NoCertCheck"
Write-LogDebug "CIMPort = $CIMPort"
Write-LogDebug "Error: $ErrorMessage"
Exit 1
}

# normal end of Script
Exit 0
}

#-------------------------------------------------------------------

function Initialize-Log {
$script:LogFilePrefix = "PRIMERGYSeedDiscoveryTrace"
$script:LogFilePath = "$($Env:TEMP)\SVISCOM\SVISCOM-ESXi"
$script:LogFileName = "$LogFilePath\$($LogFilePrefix).log"

# create the target directory, if it does not exist
if ( !(Test-Path -Path $LogFilePath)) {
New-Item -ItemType directory -Path $LogFilePath | Out-Null
}
# default overwrite logs
if (Test-Path -Path $LogFileName) {
Remove-Item -Path $LogFileName -Force | Out-Null
}
}

function Write-LogDebug {
Param (
[string] $Text
)

if (($LogFileName.Length -gt 0) -and (Test-Path -Path $LogFileName -IsValid)) {
$DateTime = Get-Date -format "yyyy-MM-dd HH:mm:ss"
if ($OutsideManagementPack) { Write-Output $Text }
Add-Content -Path $LogFileName -Value "$DateTime $Text"
}
}

#-------------------------------------------------------------------

Main
</Script></ScriptBody>
<Parameters>
<Parameter>
<Name>SourceId</Name>
<Value>$MPElement$</Value>
</Parameter>
<Parameter>
<Name>ManagedEntityId</Name>
<Value>$Target/Id$</Value>
</Parameter>
<Parameter>
<Name>PrincipalName</Name>
<Value>$Target/Property[Type="FTSESXSEED!Fujitsu.Servers.PRIMERGY.ESXiSeed.HostServer"]/PrincipalName$</Value>
</Parameter>
<Parameter>
<Name>HostServer</Name>
<Value>$Config/HostServer$</Value>
</Parameter>
<Parameter>
<Name>IPList</Name>
<Value>$Config/IPList$</Value>
</Parameter>
<Parameter>
<Name>ServerName</Name>
<Value>$Config/ServerName$</Value>
</Parameter>
<Parameter>
<Name>OpSystem</Name>
<Value>$Config/OpSystem$</Value>
</Parameter>
<Parameter>
<Name>NoCertCheck</Name>
<Value>$Config/NoCertCheck$</Value>
</Parameter>
<Parameter>
<Name>CIMPort</Name>
<Value>$Config/CIMPort$</Value>
</Parameter>
</Parameters>
<TimeoutSeconds>120</TimeoutSeconds>
</ProbeAction>
</MemberModules>
<Composition>
<Node ID="Script">
<Node ID="Scheduler"/>
</Node>
</Composition>
</Composite>
</ModuleImplementation>
<OutputType>System!System.Discovery.Data</OutputType>
</DataSourceModuleType>