0

I need to display each IBM MQ Queue Manager queue along with its depth.

I can do this with a command like echo DISPLAY QLOCAL(QE*) WHERE(CURDEPTH GE 0) | runmqsc QMNAME. The output is similar to this:

5724-H72 (C) Copyright IBM Corp. 1994, 2023. Starting MQSC for queue manager QMNAME. 1 : DISPLAY QLOCAL(QE*) WHERE(CURDEPTH GE 0) AMQ8409I: Display Queue details. QUEUE(QE.QUEUE.NAME1) TYPE(QLOCAL) CURDEPTH(2) AMQ8409I: Display Queue details. QUEUE(QE.QUEUE.NAME2) TYPE(QLOCAL) CURDEPTH(90) AMQ8409I: Display Queue details. QUEUE(QE.QUEUE.NAME.QUEUE.NAME.QUEUE.NAME3) TYPE(QLOCAL) CURDEPTH(1) AMQ8409I: Display Queue details. QUEUE(QE.QUEUE.NAME.QUEUE.NAME.QUEUE.NAME4) TYPE(QLOCAL) CURDEPTH(0) AMQ8409I: Display Queue details. QUEUE(QE.QUEUE.NAME5) TYPE(QLOCAL) CURDEPTH(0) AMQ8409I: Display Queue details. QUEUE(QE.QUEUE.NAME.QUEUE.NAME6) TYPE(QLOCAL) CURDEPTH(0) AMQ8409I: Display Queue details. QUEUE(QE.QUEUE.NAME7) TYPE(QLOCAL) CURDEPTH(0) One MQSC command read. No commands have a syntax error. All valid MQSC commands were processed. 

Note that some queues have large names, and the output moves the "TYPE" and "CURDEPTH" fields down and to the right.


My goal is to display these queues as [TYPE] - [QUEUE.NAME] - [DEPTH]:

QLOCAL - QE.QUEUE.NAME.QUEUE.NAME.QUEUE.NAME3 - 1 

So I'm trying to use either sed or awk to accomplish this, and these are some of my attempts:

With awk

awk -F'(QUEUE|TYPE|CURDEPTH)' '/QUEUE\(.*\)/{printf "%s - %s - ", $2, $3}/CURDEPTH/{printf "%s\n", $2}'

$ echo DISPLAY QLOCAL(QE*) WHERE(CURDEPTH GE 0) | runmqsc QMNAME | cat teste | awk -F'(QUEUE|TYPE|CURDEPTH)' '/QUEUE\(.*\)/{printf "%s - %s - ", $2, $3}/CURDEPTH/{printf "%s\n", $2}' GE 0) (QE.QUEUE.NAME1) - (QLOCAL) - (0) (QE.QUEUE.NAME2) - (QLOCAL) - (0) (QE.QUEUE.NAME.QUEUE.NAME.QUEUE.NAME3) - - (QLOCAL) (QE.QUEUE.NAME.QUEUE.NAME.QUEUE.NAME4) - - (QLOCAL) (QE.QUEUE.NAME5) - (QLOCAL) - (0) (QE.QUEUE.NAME.QUEUE.NAME6) - - (QLOCAL) (QE.QUEUE.NAME7) - (QLOCAL) - (0) 

The main issue is that the output does not display the queue depth correctly when its name is large.


With sed

sed -rn 's|QUEUE\((.*)\)\s+TYPE\((.*)\)\s+CURDEPTH\((\d+)\)|\2 - \1 - \3|p'

$ echo DISPLAY QLOCAL(QE*) WHERE(CURDEPTH GE 0) | runmqsc QMNAME | sed -rn 's|QUEUE\((.*)\)\s+TYPE\((.*)\)\s+CURDEPTH\((\d+)\)|\2 - \1 - \3|p' 
$ echo DISPLAY QLOCAL(QE*) WHERE(CURDEPTH GE 0) | runmqsc QMNAME | sed -rn 's|QUEUE\((.*)\)\s+TYPE\((.*)\)|\2 - \1|p' QLOCAL - QUEUE.NAME1 QLOCAL - QUEUE.NAME2 QLOCAL - QE.QUEUE.NAME.QUEUE.NAME.QUEUE.NAME3 QLOCAL - QE.QUEUE.NAME.QUEUE.NAME.QUEUE.NAME4 QLOCAL - QE.QUEUE.NAME5 QLOCAL - QE.QUEUE.NAME.QUEUE.NAME6 QLOCAL - QE.QUEUE.NAME7 

sed shows nothing when I add the \s+CURDEPTH expression. Only when I remove it does it shows the queues, but then I lose the depth value.


Can you guys give me some recommendations on this?

0

2 Answers 2

0

This should work assuming you have GNU grep and awk commands (for example on Linux):

printf "DISPLAY QLOCAL(QE*) WHERE(CURDEPTH GE 0)" | runmqsc QMNAME | grep -o '^\w\+:\|\w\+[(][^)]\+[)]' | awk -F '[()]' 'function printValues() { if ("QUEUE" in p) { printf "%s - %s - %s\n", p["QUEUE"], p["TYPE"], p["CURDEPTH"] } } /^\w+:/ { printValues(); delete p; next } { p[$1] = $2 } END { printValues() }'|column -t

CSV output:

printf "DISPLAY QLOCAL(QE*) WHERE(CURDEPTH GE 0)" | runmqsc QMNAME | grep -o '^\w\+:\|\w\+[(][^)]\+[)]' | awk -F '[()]' -v OFS="," 'function printValues() { if ("QUEUE" in p) { print p["QUEUE"], p["TYPE"], p["CURDEPTH"] } } /^\w+:/ { printValues(); delete p; next } { p[$1] = $2 } END { printValues() }'

0

I ended up querying only the queue name and depth, and outputting it as a CSV.

The command is as follows.

echo 'DISPLAY QLOCAL(Q*) WHERE(CURDEPTH GE 0)' | runmqsc {$MQSERIES.QM.NAME} | (echo "QUEUE_NAME,CUR_DEPTH"; sed -n -E 's/\s+QUEUE\(([^)]+)\).*/\1/p; s/.*\s+CURDEPTH\(([^)]+)\)/\1/p' | awk 'NR%2{printf "%s,",$1; next}1') 

The output looks something like this.

QUEUE_NAME,CUR_DEPTH QD.QMLOGPR019,0 QE.QUEUE.NAME1,0 QE.QUEUE.NAME2,0 QE.QUEUE.NAME3,0 QE.QUEUE.NAME.QUEUE.NAME.QUEUE.NAME4,126 QE.QUEUE.NAME.QUEUE.NAME5,273 QE.QUEUE.NAME6,0 QE.QUEUE.NAME7,506 QI.QUEUE,0 

I've automated the query with Zabbix, and it's very fast for now. Note that Zabbix requires you to scape double-quotes.

I appreciate all the feedback.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.