I have written three blog post on using the MQ REST API

  1. Setting up to use MQ Rest API and CURL to get to MQ on z/OS using digital certificates

  2. What can I do with the MQ Rest API data

  3.  Debug hints for MQ Rest API and CURL to get to MQ on z/OS using digital certificates

This post is  What can I do with the MQ Rest API data
I ran the commands below on my laptop running Redhat Linux, to a MQ Web server on z/OS.

First you need to know the IP address of the MQ Web server.

You can look in the //STDOUT statement of the MQ Web Server procedure

On the server, you can use the dspmqweb command to display information about the web server.
For example on z/OS your started procedure defines where the executables are stored, and the location of the configuration files.
INSTDIR=’/opt/mq904/web’¬† and USERDIR=’/var/mqweb/’

then in USS issue
export WLP_USER_DIR=/var/mqweb/
/opt/mq904/web/bin/dspmqweb    

On distributed you need to set the WLP_USER_DIR, and your path may already be set up for you.

You could put these commands into a shell script.

On z/OS this gave me
Server mqweb is running with process ID 65574.                                                   
URLS:
  http://winmvsca.hursley.ibm.com:9081/ibmmq/rest/v1/                                            
  https://winmvsca.hursley.ibm.com:9444/ibmmq/console/  
  http://winmvsca.hursley.ibm.com:9081/ibmmq/console/

What is the command syntax of the rest API?

See the documentation here.
Note: the syntax changed at MQ904
http://host:port/ibmmq/rest/v1/admin/qmgr/{qmgrName}/queue/{queueName}
Version 9.0.3 and earlier:
http://host:port/ibmmq/rest/v1/qmgr/{qmgrName}/queue/{queueName}

Some online documentation is available from the web server.
If you suffix your web address with /ibm/api/explorer/ for example http://winmvsca.hursley.ibm.com:9081ibm/api/explorer/ it displays a page giving some of the the syntax of the REST API.  It gave me GET /ibmmq/rest/v1/admin/qmgr/{qmgrName}

My first data at MQ 904

Using  curl ...   https://winmvsca.hursley.ibm.com:9444/ibmmq/rest/v1/admin/qmgr  gave me 
{
  "qmgr": [
    {
      "name": "MQPA",
      "state": "running"
    },
    {
      "name": "MQPB",
      "state": "running"
    },
    {
      "name": "MQPD",
      "state": "running"
    },
    {
      "name": "MQ7A",
      "state": "running"
    }
  ]
}

There is a program jq which processes JSON data.  To quote from the web site

jq is a lightweight and flexible command-line JSON processor.   jq is like sed for JSON data Рyou can use it to slice and filter and map and transform structured data with the same ease that sed, awk, grep and friends, let you play with text.

Extending the previous command.
curl¬†¬† …¬†¬† | jq ‘.qmgr | map([.name, .state] | join(“, “))’
gave

[
“MQPA, running”,
“MQPB, running”,
“MQPD, running”,
“MQ7A, running”
]

and
curl …¬†¬† |jq -r ‘.qmgr | map(.name), map(.state) | join(“, “)’

gave

MQPA, MQPB, MQPD, MQ7A
running, running, running, running

Using this you can easily format the data.

Getting queue information

There are two types of queue information

  1. Status Рthis information changes as messages are put and got.  For example queue depth
  2. Attributes – eg type of queue and triggering data.

For my queue manager MQPA and queue CP0000

curl … –url …/ibmmq/rest/v1/admin/qmgr/MQPA/queue/CP0000?status=*
gave me all of the status fields.

{"queue": [{
  "name": "CP0000",
  "queueSharingGroup": {"disposition": "qmgr"},
  "status": {
    "currentDepth": 0,
    "lastGet": "",
    "lastPut": "",....

curl¬† … –url …/ibmmq/rest/v1/admqmgr/MQPA/queue/CP0000?status=status.currentDepth gave me the requested field currentDepth.

{"queue": [{
  "name": "CP0000",
  "queueSharingGroup": {"disposition": "qmgr"},
  "status": {"currentDepth": 0},
  "type": "local"
}]}

How do I display the current depth of all SYSTEM.CHANNEL* queues?

You concatenate filters together using & but note, in a bash script & has a special meaning, so you have to escape it with \&
curl ... --url .../ibmmq/rest/v1/admin/qmgr/MQPA/queue?name=SYSTEM.CHANNEL*\&status=status.currentDepth| jq '.["queue"] |map([.name, .status.currentDepth|tostring ]  | join(","))  '

gave me
[
  "SYSTEM.CHANNEL.SYNCQ,10",
  "SYSTEM.CHANNEL.INITQ,0"
]

You can then use your standard script processing language to take this data and process it.

To extract more than one attribute:  currentDepth and openInputCount

curl … –url … ibmmq/rest/v1/admin/qmgr/MQPA/queue?name=SYSTEM.CHANNEL*\&status=status.currentDepth,status.openInputCount¬† |
jq ‘.[“queue”] |map([.name, (.status.openInputCount|tostring) ,(.status.currentDepth|tostring)] | join(“,”) ) ‘¬† gave me

[
  "SYSTEM.CHANNEL.SYNCQ,0,10",
  "SYSTEM.CHANNEL.INITQ,1,0"
]

Can I get the time from the data?

Information include the date and time from the server is sent down as part of the header information.  This is visible if you use curl -v ..
The easiest way of getting the time of day is to use your shell’s time command.¬† For example using bash, type date

 

Happy curling!

Join The Discussion

Your email address will not be published.