Search code examples
eventstimezoneibm-mqgmt

Parse IBM MQ Event Monitoring messages in local time


I am using IBM provided sample program amqsevt to monitor MQ event queues and parse the messages. But I notice that by default the event creation time is represented in GMT time. I would like to get it converted to System local time. Is there a way to accomplish this?

**** Message #1 (120 Bytes) on Queue SYSTEM.ADMIN.CHANNEL.EVENT ****
Event Type                       : Channel Event [46]
Reason                           : Channel Stopped By User [2279]
Event created                    : 2018/09/04 20:17:39.48 GMT

Solution

  • The source for the sample can be found on Linux with MQ installed in /opt/mqm at /opt/mqm/samp/amqsevta.c.

    In the MQMD (Message Descriptor) of every message there is a PutDate and PutTime field that is always stored in GMT and are each simple 8 digit strings for example:

    • PutDate: 20180904 (YYYYMMDD)
    • PutTime: 20173948 (HHMMSSSS)

    In the sample program it just converts that to the displayed format of 2018/09/04 20:17:39.48 and appends GMT to the end since it knows this is always in GMT.

      /**********************************************************/
      /* Timestamp is read from the MQMD - it is always in GMT  */
      /* regardless of local timezone. Do not want to try to    */
      /* convert it, because this machine may be a client in a  */
      /* different timezone than the server generating the      */
      /* event. So stick to GMT (or UCT if you prefer).         */
      /**********************************************************/
      sprintf(valbuf,"%4.4s/%2.2s/%2.2s %2.2s:%2.2s:%2.2s.%2.2s GMT",
         &pMsgDesc->PutDate[0],
         &pMsgDesc->PutDate[4],
         &pMsgDesc->PutDate[6],
         &pMsgDesc->PutTime[0],
         &pMsgDesc->PutTime[2],
         &pMsgDesc->PutTime[4],
         &pMsgDesc->PutTime[6]);
      printLine(offset,"Event created",valbuf);
    

    It looks like you could use the c function strptime to parse the string into a epoch time stamp and then print that in your local time zone.