IBM MQ Channel Discovery

IBM.MQ.Channel.Discovery (Discovery)

Element properties:

TargetIBM.MQ.QueueManager
EnabledTrue
Frequency86405
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="IBM.MQ.Channel.Discovery" Enabled="true" Target="IBM.MQ.QueueManager" ConfirmDelivery="false" Remotable="true" Priority="Normal">
<Category>Discovery</Category>
<DiscoveryTypes>
<DiscoveryClass TypeID="IBM.MQ.Channel">
<Property TypeID="IBM.MQ.Channel" PropertyID="ChannelName"/>
<Property TypeID="IBM.MQ.Channel" PropertyID="ChannelType"/>
<Property TypeID="IBM.MQ.Channel" PropertyID="QueueManagerName"/>
</DiscoveryClass>
</DiscoveryTypes>
<DataSource ID="DS" TypeID="Windows!Microsoft.Windows.TimedPowerShell.DiscoveryProvider">
<IntervalSeconds>86405</IntervalSeconds>
<SyncTime/>
<ScriptName>IBM.MQ.Channel.Discovery.ps1</ScriptName>
<ScriptBody><Script>
#=================================================================================
# Discover IBM MQ Channel Discovery
#
# Author: Kevin Holman
# v1.2
#=================================================================================
param($SourceId,$ManagedEntityId,[string]$ComputerName,[string]$QueueManagerName)


# Manual Testing section - put stuff here for manually testing script - typically parameters:
#=================================================================================
# $SourceId = '{00000000-0000-0000-0000-000000000000}'
# $ManagedEntityId = '{00000000-0000-0000-0000-000000000000}'
# $ComputerName = "computername.domain.com"
# $QueueManagerName = "QM2"
#=================================================================================


# Constants section - modify stuff here:
#=================================================================================
# Assign script name variable for use in event logging.
# ScriptName should be the same as the ID of the module that the script is contained in
$ScriptName = "IBM.MQ.Channel.Discovery.ps1"
$EventID = "7102"
#=================================================================================


# Starting Script section - All scripts get this
#=================================================================================
# Gather the start time of the script
$StartTime = Get-Date
#Set variable to be used in logging events
$whoami = whoami
# Load MOMScript API
$momapi = New-Object -comObject MOM.ScriptAPI
#Log script event that we are starting task
$momapi.LogScriptEvent($ScriptName,$EventID,0,"`n Script is starting. `n Running as ($whoami).")
#=================================================================================


# Discovery Script section - Discovery scripts get this
#=================================================================================
# Load SCOM Discovery module
$DiscoveryData = $momapi.CreateDiscoveryData(0, $SourceId, $ManagedEntityId)
#=================================================================================


# Begin MAIN script section
#=================================================================================
#Get the Channel from QueueManager
$Ccmd = "cmd /c 'echo Display channel(*) | runmqsc $QueueManagerName'"

$Cout = Invoke-Expression $Ccmd
FOREACH ($CLine in $Cout)
{
$Cmatch = $CLine | Select-String -Pattern 'CHANNEL\(' -CaseSensitive
IF ($Cmatch)
{
$CLineSplit = $CLine.Split("(,)")
[string]$ChannelName = $CLineSplit[1]
$ChannelName = $ChannelName.Trim()
[string]$ChannelType = $CLineSplit[3]
$ChannelType = $ChannelType.Trim()
#Write-Host "Found Channel Name: ($ChannelName) Type:($ChannelType)"

$momapi.LogScriptEvent($ScriptName,$EventID,0,"`nDiscovering Channel: ($ChannelName). `nChannel Type:($ChannelType). `nQueue Manager: ($QueueManagerName).")

$instance = $DiscoveryData.CreateClassInstance("$MPElement[Name='IBM.MQ.Channel']$")
$instance.AddProperty("$MPElement[Name='Windows!Microsoft.Windows.Computer']/PrincipalName$",$ComputerName)
$instance.AddProperty("$MPElement[Name='IBM.MQ.QueueManager']/QueueManagerName$",$QueueManagerName)
$instance.AddProperty("$MPElement[Name='IBM.MQ.Channel']/ChannelName$",$ChannelName)
$instance.AddProperty("$MPElement[Name='IBM.MQ.Channel']/ChannelType$",$ChannelType)
$instance.AddProperty("$MPElement[Name='IBM.MQ.Channel']/QueueManagerName$",$QueueManagerName)
$instance.AddProperty("$MPElement[Name='System!System.Entity']/DisplayName$", $ChannelName)
$DiscoveryData.AddInstance($instance)
}
}

# Return Discovery Items Normally
$DiscoveryData
# Return Discovery Bag to the command line for testing (does not work from ISE)
# $momapi.Return($DiscoveryData)
#=================================================================================
# End MAIN script section


# End of script section
#=================================================================================
#Log an event for script ending and total execution time.
$EndTime = Get-Date
$ScriptTime = ($EndTime - $StartTime).TotalSeconds
$momapi.LogScriptEvent($ScriptName,$EventID,0,"`n Script Completed. `n Script Runtime: ($ScriptTime) seconds.")
#=================================================================================
# End of script
</Script></ScriptBody>
<Parameters>
<Parameter>
<Name>SourceID</Name>
<Value>$MPElement$</Value>
</Parameter>
<Parameter>
<Name>ManagedEntityID</Name>
<Value>$Target/Id$</Value>
</Parameter>
<Parameter>
<Name>ComputerName</Name>
<Value>$Target/Host/Host/Property[Type="Windows!Microsoft.Windows.Computer"]/PrincipalName$</Value>
</Parameter>
<Parameter>
<Name>QueueManagerName</Name>
<Value>$Target/Property[Type="IBM.MQ.QueueManager"]/QueueManagerName$</Value>
</Parameter>
</Parameters>
<TimeoutSeconds>300</TimeoutSeconds>
</DataSource>
</Discovery>