MQ

MQ

Join this online group to communicate across IBM product users and experts by sharing advice and best practices with peers and staying up to date regarding product enhancements.

 View Only

Unix Multi Line Search Tool for IBM MQ Needs

By Tim Zielke posted Thu September 12, 2024 04:14 PM

  

I wanted to pass on a Unix based script command that I found helpful.

Sometimes you want to search a file for multiple search texts that are split across multiple lines. For example, here is an error message in the IBM MQ AMQERR01.LOG that is written out across multiple lines.

08/23/2024 09:38:54 AM - Process(9072.913690) User(mqm) Program(amqrmppa)

                    Host(server1) Installation(Installation1)

                    VRMF(9.3.0.15) QMgr(QM1)

                    Time(2024-08-23T14:38:54.888Z)

                    RemoteHost(10.10.10.100)

                    ArithInsert1(420)

                    CommentInsert1(APP1.TLS.SERVER)

                    CommentInsert2(gsk_secure_soc_read)

                    CommentInsert3(ip-10-10-10-100 (10.10.10.100))

AMQ9665E: SSL connection closed by remote end of channel 'APP1.TLS.SERVER'.

EXPLANATION:

The SSL or TLS connection was closed by the remote host 'ip-10-10-10-100

(10.10.10.100)' during the secure socket handshake. The channel is

'APP1.TLS.SERVER'; in some cases its name cannot be determined and so is shown

as '????'. The channel did not start.

ACTION:

Check the remote end of the channel for SSL and TLS errors. Fix them and

restart the channel.

----- amqccisa.c : 12115 ------------------------------------------------------

Let’s say you wanted to search for all messages in the AMQERR01.LOG file that have both AMQ9665E and 10.10.10.100 in the error message. Below is a script command (you can run it as one command from a shell prompt) that can help.

HoldTx=""; while read LineTx; do if [ A"${LineTx:0:3}" = A--- ];then echo "$HoldTx"; HoldTx=""; fi; HoldTx=$HoldTx${LineTx:0:${#LineTx}}"  "; done < AMQERR01.LOG > AMQERR01.LOG.2; echo "$HoldTx" >> AMQERR01.LOG.2

What it does is read in lines from the AMQERR01.LOG file, with each line being appended together until it encounters a line that starts with “---”. Once it hits this line, it writes out all the appended lines as one line to the AMQERR01.LOG.2 file, clears out the buffer, and starts the process all over again. The “---” line is the delimiter for an IBM MQ error message. Once the command completes, you now have a AMQERR01.LOG.2 file that has the IBM MQ error messages written out as one line per error message. With this new file, you can then grep for messages that have both AMQ9665E and 10.17.28.200 in the error message.

One note, this command does not perform very well with large files. However, it can run very quickly with a file the size of the AMQERR01.LOG that is around 12 Mb and around 250,000 lines.

Another use case for this command is the Application Activity Trace. The Application Activity Trace is a powerful debugging tool, but one of the hurdles is how to process the data that is produced from reporting tools like amqsact. With the above concept, you could pull pieces out of the amqsact report like MonitoringType, Channel Name, ConnName, ApplicationName, Operation Id, Expiry:

egrep '(^MonitoringType:|^Channel Name:|^ConnName:|^ApplicationName:|Operation Id:|Expiry:)' amqsact.out > tmp1

And then rebuild this into a file that is one line for each Application Activity Trace record.

HoldTx=""; while read LineTx; do if [ A"${LineTx:0:15}" = AMonitoringType: ];then echo "$HoldTx"; HoldTx=""; fi; HoldTx=$HoldTx${LineTx:0:${#LineTx}}"  "; done < tmp1 > tmp2; echo "$HoldTx" >> tmp2

Now you have a tmp2 file that is one line per Application Activity Trace record, and is easier for doing certain types of searches and analysis.

1 comment
16 views

Permalink

Comments

Tue September 24, 2024 11:58 PM

For the queue manger logs here is another option:

cat AMQERR01.LOG | mqrc -i text -o json - | grep AMQ9665E | grep 10.17.28.200 | mqrc -i json -o text -