Discover Cireson Portal ServiceManagement DB Hosting Server

Cireson.Portal.Discovery.Cireson.Portal.SMDBServer (Discovery)

Description for the new discovery.

Element properties:

TargetCireson.Portal.Computer.WebServer
EnabledTrue
Frequency14400
RemotableFalse

Object Discovery Details:

Discovered Classes and their attribuets:

Member Modules:

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

Source Code:

<Discovery ID="Cireson.Portal.Discovery.Cireson.Portal.SMDBServer" Target="Cireson.Portal.Computer.WebServer" Enabled="true" ConfirmDelivery="false" Remotable="true" Priority="Normal">
<Category>Discovery</Category>
<DiscoveryTypes>
<DiscoveryClass TypeID="Cireson.Portal.Computer.SMDBServer"/>
</DiscoveryTypes>
<DataSource ID="DS" TypeID="Windows!Microsoft.Windows.TimedPowerShell.DiscoveryProvider">
<IntervalSeconds>14400</IntervalSeconds>
<SyncTime>00:00</SyncTime>
<ScriptName>CiresonSMDBServerDiscovery.ps1</ScriptName>
<ScriptBody><Script>
param($sourceId,$managedEntityId,$computerName)

#Initialize SCOM API

$api = new-object -comObject 'MOM.ScriptAPI'
$discoveryData = $api.CreateDiscoveryData(0, $SourceId, $ManagedEntityId)

# Logging
$api.LogScriptEvent('CiresonSMDBServerDiscovery.ps1',4660,0,"Cireson SMDB Server Discovery Script is starting")

$website = (Get-Website | Where-Object 'Name' -NotLike 'Default Web Site')
$webconfigpath = Get-ChildItem -Path $website.Physicalpath -Recurse | Where-Object {$_.Name -match "Cireson.CacheBuilder.WindowsService.exe.config"} | Select -Expand FullName

[xml]$webconfig = get-content $webconfigpath
$cns = ($webconfig.configuration.connectionStrings.add | Where-Object {$_.Name -eq 'ServiceManagementDatabase'}).Connectionstring
$sql = (New-Object System.Data.SqlClient.SqlConnectionStringBuilder($cns))
$CiresonSMDBServer = ($SQL.Server).ToString()

$CiresonSMDBName = ($SQL.'Initial Catalog').ToString()

#Check For SQL Named Instances
$SQLInstanceName = 'MSSQLSERVER'
$string = [string]$CiresonSMDBServer

if ($string -match '\\([^\\]+)$')
{
$SQLInstanceName = $matches[1]
}

#Server Name Check
$ServerNameCheck = $CiresonSMDBServer.Split('\')[0]

$CiresonSMDBDNSNameServer = Resolve-DnsName -Name $ServerNameCheck -Type A | Select -First 1 'Name'

$Result = $CiresonSMDBName

#Read the $ServerName output value and create instance of 'Cireson.Portal.App.Component.SMDB' Class

$ServerName = $Result
$Config = $ServerName # Will be used as display name
$SQLInstanceName = $SQLInstanceName
#The hosting object is windows computer whose display name is equal to script $Servername output
#If there is no matching windows computer managed by SCOM, then the instance cannot be hosted. Hence the instance is not discovered.

$instance = $discoveryData.CreateClassInstance("$MPElement[Name='Cireson.Portal.Computer.SMDBServer']$")

#The hosting object is windows computer whose display name is equal to script $Servername output
$instance.AddProperty("$MPElement[Name='Windows!Microsoft.Windows.Computer']/PrincipalName$", $CiresonSMDBDNSNameServer.Name)
$instance.AddProperty("$MPElement[Name='System!System.Entity']/DisplayName$", $CiresonSMDBDNSNameServer.Name)
$discoveryData.AddInstance($instance)

$discoveryData

# Logging
$api.LogScriptEvent('CiresonSMDBServerDiscovery.ps1',4661,0,"Cireson SMDB Server Discovery Script is complete")
</Script></ScriptBody>
<Parameters>
<Parameter>
<Name>sourceId</Name>
<Value>$MPElement$</Value>
</Parameter>
<Parameter>
<Name>managedEntityId</Name>
<Value>$Target/Id$</Value>
</Parameter>
</Parameters>
<TimeoutSeconds>300</TimeoutSeconds>
</DataSource>
</Discovery>