0
votes

I have a requirement to write a shell script to check queue depth of few queues in remote Queue manager. Version of remote queue manager IBM websphere Mq v8. Can anyone advise on this?

2
Also one more thing remote queue manager is in mainframe - Johnwick

2 Answers

3
votes

You can do the following:

1) Create an mqsc file, say curdepth.mqsc containing the following:

  DIS QL(*) CURDEPTH 

The above will display curdepth of all queues. If you need for a specific queue, then

 DIS QL(<queue name>) CURDEPTH 

You can also wildcard in the name.

 DIS QL(SW*) CURDEPTH 

2) Setup MQSERVER environment variable to point to remote queue manager. For example:

SET MQSERVER=MQ_CHN/TCP/remotehost(1414)

3) Through your shell script

   runmqsc -c <qmgr> < curdepth.mqsc

The output would look something like

AMQ8409I: Display Queue details.
   QUEUE(SWIFTQ)                           TYPE(QLOCAL)
   CURDEPTH(0)

4) Then parse the output of the command.

2
votes

Well, I think it would be better to write an MQ/PCF in Java (or C) rather than do it by a shell script. But if you must, here's one I used back in the early 2000's that I called chkQdepth.sh:

#!/bin/sh
#
# A shell script to check the queue depth and alert 
# the user via email if it is too high.
#
# Parameters:
#  $1=Queue manager
#  $2=Queue name
#  $3=alert threshold
#  $4=mailing list
#  $5=mail subject
#  $6=mail message
#

if [ $# -ne 6 ] ; then exit; fi

QMGR="$1"
QUEUE="$2"
WARNING="$3"
MAILLIST="$4"
MAILSUB="$5"
MAILMSG="$6"

CURDEPTH=`/opt/mqm/bin/runmqsc $QMGR << EOF |sed -n '/CURDEPTH([0-9]*)/ {
s/.*CURDEPTH(\([0-9]*\))/\1/
p
}'
DISPLAY QUEUE($QUEUE) CURDEPTH
end
EOF`

if [ "x$CURDEPTH" != "x" ] ; then
    if [ $CURDEPTH -gt $WARNING ] ; then
        echo "Queue has more than $WARNING message(s)"
        mail -t $MAILLIST << EOF
Subject: $5

$6


Queue Manager: $QMGR

Queue Name: $QUEUE

Current queue depth is $CURDEPTH messages

Alerting Threshold is $WARNING

EOF
    else
        echo "Queue depth is equal to or less than $WARNING. (Current queue depth is $CURDEPTH messages)"
    fi
else
    echo "Queue depth not available"
fi

exit 0

The script requires 6 input parameters:

  • The name of the queue manager
  • The name of the queue to check
  • Alert threshold amount (a number)
  • The mailing list of user that will receive the email
  • The mail subject
  • The mail message

You can run the script manually but it is far better to setup it so that a scheduler runs it, say every 5 minutes. Most people on Unix / Linux will use CRON, so here's a crontab entry:

0-59/5 *  * * * /some/path/mqtools/chkQdepth.sh MQA1 TEST.Q1 50 [email protected]  "Alert: Test.Q1 has too many messages." "Please check application XYZ as queue TEST.Q1 has too many messages in it." >/dev/null 2>&1