MQ Monitoring User Exit

The following user exit can be used to monitor MQ connections.

The user exit module must be called ES_MQMONEX and placed in your product's %ProgramFiles(x86)%\Micro Focus\Enterprise Developer\bin (Windows) or $COBDIR/lib (UNIX) directory:

       identification division.
       program-id. ES_MQMONEX.

      *****************************************************************
      *** Example MQ monitoring exit.                               ***
      *** Stores a table of object handles and their names.         ***
      *****************************************************************

       environment division.
       configuration section.

       data division.
       working-storage section.

       78 78-exit-version                      value 1.

       *> -- Flag to enable initialisation on first call
       01 ws-initialised-flag                  pic x value 'n'.
          88 ws-initialised-88                 value 'y' false 'n'.

       *> -- Table to store mapping of objects and queue names
       01 ws-object-table. 
          78 78-table-size                     value 10.
          03 ws-obj-idx                        pic x(4) comp-5.
          03 ws-object occurs 78-table-size times.
             05 ws-obj-handle                  pic x(4) comp-5.
             05 ws-obj-name                    pic x(48).

       linkage section.
       copy casmqmon.cpy replacing ==()== by ==lk==.

       procedure division using lk-mqmonex-out.

           if not ws-initialised-88

               *> -- Initialise on first entry 
               if 78-exit-version not = lk-mqmonex-version

                  *> -- This exit is using a different version of casmqmon.cpy
                  *> -- compared to the product, so switch off the exit.

                  set lk-mqmonex-switch-off-88
                                       to true
                  goback

               end-if

               initialize ws-object-table

               set ws-initialised-88   to true

           end-if

           evaluate lk-mqmonex-api

           when = 'MQCONN'
           when = 'MQCONNX'
           when = 'MQDISC'

               *> -- No queue, so do nothing

               continue

           when = 'MQOPEN'

               *> -- Find a free space to save queue name and handle
               perform varying ws-obj-idx from 1 by 1
               until ws-obj-idx > 78-table-size

                   if ws-obj-handle(ws-obj-idx) = 0

                       *> -- Empty space found so populate with queue name and handle

                       move lk-mqmonex-hobj
                                       to ws-obj-handle(ws-obj-idx)

                       move lk-mqmonex-qname
                                       to ws-obj-name(ws-obj-idx)

                       exit perform

                   end-if

               end-perform

               if ws-obj-idx > 78-table-size

                   *> -- No space in table to store this queue name and handle.
                   *> -- Handle the error!

                   continue

               end-if

           when other

               *> -- Locate queue name in table using object handle that was passed.

               perform varying ws-obj-idx from 1 by 1
               until ws-obj-idx > 78-table-size

                   if ws-obj-handle(ws-obj-idx) = lk-mqmonex-hobj

                       *> -- Found the queue name in the table at ws-obj-idx

                       exit perform

                   end-if

               end-perform

               if ws-obj-idx > 78-table-size

                   *> -- Failed to find the queue name
                   *> -- Handle the error!

                   continue

               end-if

           end-evaluate

           perform do-something 

           if lk-mqmonex-api = 'MQCLOSE'

               *> -- Initialise element containing closed queue

               perform varying ws-obj-idx from 1 by 1 until 
               ws-obj-idx > 78-table-size

                   if ws-obj-handle(ws-obj-idx) = lk-mqmonex-hobj

                       *> -- Found the queue, so clear this element

                       initialize ws-object(ws-obj-idx)

                       exit perform

                   end-if

               end-perform

           end-if

           goback
           .

       do-something section.

           *> -- Log the data somewhere

           exit section
           .

           end program ES_MQMONEX.

casmqmon.cpy:

       01 ()-mqmonex-out.
          03 ()-mqmonex-version                    pic x(4) comp-5.
             88 ()-mqmonex-version-1-88            value 1.
             88 ()-mqmonex-switch-off-88           value 255.
          03 ()-mqmonex-qmanager-name              pic x(48).
          03 ()-mqmonex-api-call-info.
             05 ()-mqmonex-hconn                   pic x(4) comp-5.
             05 ()-mqmonex-api                     pic x(8).
             05 ()-mqmonex-qname                   pic x(48).
             05 ()-mqmonex-hobj                    pic x(4) comp-5.
             05 ()-mqmonex-jobname.
                07 ()-mqmonex-termid               pic x(4).
                07 ()-mqmonex-tranid               pic x(4).
             05 ()-mqmonex-task                    pic x(4) comp-5.
             05 ()-mqmonex-pid                     pic x(4) comp-5.
             05 ()-mqmonex-timein.
                07 ()-mqmonex-timein-year          pic x(2) comp-x.
                07 ()-mqmonex-timein-month         pic x(1) comp-x.
                07 ()-mqmonex-timein-day           pic x(1) comp-x.
                07 ()-mqmonex-timein-hour          pic x(1) comp-x.
                07 ()-mqmonex-timein-minute        pic x(1) comp-x.
                07 ()-mqmonex-timein-seconds       pic x(1) comp-x.
                07 ()-mqmonex-timein-ms            pic x(2) comp-x.
             05 ()-mqmonex-timeout.
                07 ()-mqmonex-timeout-year         pic x(2) comp-x.
                07 ()-mqmonex-timeout-month        pic x(1) comp-x.
                07 ()-mqmonex-timeout-day          pic x(1) comp-x.
                07 ()-mqmonex-timeout-hour         pic x(1) comp-x.
                07 ()-mqmonex-timeout-minute       pic x(1) comp-x.
                07 ()-mqmonex-timeout-seconds      pic x(1) comp-x.
                07 ()-mqmonex-timeout-ms           pic x(2) comp-x.
             05 ()-mqmonex-duration-ms             pic x(8) comp-x.
             05 ()-mqmonex-compcode                pic x(4) comp-5.
             05 ()-mqmonex-reason                  pic x(4) comp-5.