IBM MQ Queue Discovery

IBM.MQ.Queue.Discovery (Discovery)

Element properties:

TargetIBM.MQ.QueueManager
EnabledTrue
Frequency86401
RemotableFalse

Object Discovery Details:

Discovered Classes and their attribuets:
  • IBM.MQ.Queue
    • QueueName
    • QueueManagerName
    • TYPE
    • DESCR
    • MAXDEPTH
    • MAXMSGL

Member Modules:

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

Source Code:

<Discovery ID="IBM.MQ.Queue.Discovery" Enabled="true" Target="IBM.MQ.QueueManager" ConfirmDelivery="false" Remotable="true" Priority="Normal">
<Category>Discovery</Category>
<DiscoveryTypes>
<DiscoveryClass TypeID="IBM.MQ.Queue">
<Property TypeID="IBM.MQ.Queue" PropertyID="QueueName"/>
<Property TypeID="IBM.MQ.Queue" PropertyID="QueueManagerName"/>
<Property TypeID="IBM.MQ.Queue" PropertyID="TYPE"/>
<Property TypeID="IBM.MQ.Queue" PropertyID="DESCR"/>
<Property TypeID="IBM.MQ.Queue" PropertyID="MAXDEPTH"/>
<Property TypeID="IBM.MQ.Queue" PropertyID="MAXMSGL"/>
</DiscoveryClass>
</DiscoveryTypes>
<DataSource ID="DS" TypeID="Windows!Microsoft.Windows.TimedPowerShell.DiscoveryProvider">
<IntervalSeconds>86401</IntervalSeconds>
<SyncTime/>
<ScriptName>IBM.MQ.Queue.Discovery.ps1</ScriptName>
<ScriptBody><Script>
#=================================================================================
# IBM MQ Queue Discovery Script
#
# Author: Kevin Holman
# v1.3
#=================================================================================
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"
# $QueueName = "SYSTEM.INTERNAL.REPLY.QUEUE"
#=================================================================================


# 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.Queue.Discovery.ps1"
$EventID = "7104"
[bool]$DiscoverSystemQueues = $true
#=================================================================================


# 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,"`nScript is starting. `nRunning 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 queues from QueueManager
$Qcmd = "cmd /c 'echo Display QL(*) | runmqsc $QueueManagerName'"
# Write-Host "Getting Queues from ($QueueManagerName) using $Qcmd"
$Qout = Invoke-Expression $Qcmd

FOREACH ($QLine in $Qout)
{
$Qmatch = $QLine | Select-String -Pattern 'QUEUE\('
IF ($Qmatch)
{
$QLineSplit = $QLine.Split("(,)")
[string]$QueueName = $QLineSplit[1]
#Write-Host "Found Queue: ($QueueName)"

IF ($QueueName -match "SYSTEM.DEFAULT")
{
#This is a system default queue. Only continue if System Default Queues should be discovered
IF ($DiscoverSystemQueues)
{$ContinueDiscovery = $true}
ELSE
{$ContinueDiscovery = $false}
}
ELSE
{
#This is not a system queue. Continue discovery
$ContinueDiscovery = $true
}

IF ($ContinueDiscovery)
{
#Get Queue Properties
$QPropcmd = "cmd /c 'echo Display Queue ($QueueName) TYPE DESCR MAXDEPTH MAXMSGL | runmqsc $QueueManagerName'"
$QPropout = Invoke-Expression $QPropcmd

FOREACH ($QPropLine in $QPropout)
{
$QPropMatch = $QPropLine | Select-String -Pattern 'TYPE\('
IF ($QPropMatch)
{
$Splitter = "TYPE"
$QPropLine1 = $QPropLine
$QPropLineSplit1 = $QPropLine1 -Split $Splitter
$TYPE = $QPropLineSplit1[1]
$TYPE = ($TYPE.Split(")"))[0]
$TYPE = $TYPE -Replace "[(]",""
$TYPE = $TYPE.Trim()
#Write-Host "$TYPE"
}

$QPropMatch2 = $QPropLine | Select-String -Pattern 'DESCR\('
IF ($QPropMatch2)
{
$QPropLine2 = $QPropLine
$Splitter = "DESCR"
$QPropLineSplit2 = $QPropLine2 -Split $Splitter
$DESCR = $QPropLineSplit2[1]
$DESCR = ($DESCR.Split(")"))[0]
$DESCR = $DESCR -Replace "[(]",""
$DESCR = $DESCR.Trim()
#Write-Host "$DESCR"
}

$QPropMatch3 = $QPropLine | Select-String -Pattern 'MAXDEPTH\('
IF ($QPropMatch3)
{
$QPropLine3 = $QPropLine
$Splitter = "MAXDEPTH"
$QPropLineSplit3 = $QPropLine3 -Split $Splitter
$MAXDEPTH = $QPropLineSplit3[1]
$MAXDEPTH = ($MAXDEPTH.Split(")"))[0]
$MAXDEPTH = $MAXDEPTH -Replace "[(]",""
$MAXDEPTH = $MAXDEPTH.Trim()
#Write-Host "$MAXDEPTH"
}

$QPropMatch4 = $QPropLine | Select-String -Pattern 'MAXMSGL\('
IF ($QPropMatch4)
{
$QPropLine4 = $QPropLine
$Splitter = "MAXMSGL"
$QPropLineSplit4 = $QPropLine4 -Split $Splitter
$MAXMSGL = $QPropLineSplit4[1]
$MAXMSGL = ($MAXMSGL.Split(")"))[0]
$MAXMSGL = $MAXMSGL -Replace "[(]",""
$MAXMSGL = $MAXMSGL.Trim()
#Write-Host "$MAXMSGL"
}
}

$momapi.LogScriptEvent($ScriptName,$EventID,0,"`nDiscovering Queue: ($QueueName) `nQueueManagerName: ($QueueManagerName). `nTYPE: ($TYPE). `nDESCR: ($DESCR). `nMAXDEPTH: ($MAXDEPTH). `nMAXMSGL: ($MAXMSGL)")

$instance = $DiscoveryData.CreateClassInstance("$MPElement[Name='IBM.MQ.Queue']$")
$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.Queue']/QueueManagerName$",$QueueManagerName)
$instance.AddProperty("$MPElement[Name='IBM.MQ.Queue']/QueueName$",$QueueName)
$instance.AddProperty("$MPElement[Name='IBM.MQ.Queue']/TYPE$",$TYPE)
$instance.AddProperty("$MPElement[Name='IBM.MQ.Queue']/DESCR$",$DESCR)
$instance.AddProperty("$MPElement[Name='IBM.MQ.Queue']/MAXDEPTH$",$MAXDEPTH)
$instance.AddProperty("$MPElement[Name='IBM.MQ.Queue']/MAXMSGL$",$MAXMSGL)
$instance.AddProperty("$MPElement[Name='System!System.Entity']/DisplayName$", $ComputerName)
$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>