ASG
IBM
Zystems
Cressida
Icon
Netflexity
 
  MQSeries.net
Search  Search       Tech Exchange      Education      Certifications      Library      Info Center      SupportPacs      LinkedIn  Search  Search                                                                   FAQ  FAQ   Usergroups  Usergroups
 
Register  ::  Log in Log in to check your private messages
 
RSS Feed - WebSphere MQ Support RSS Feed - Message Broker Support

MQSeries.net Forum Index » General IBM MQ Support » MQSeries Channel Status PCF

Post new topic  Reply to topic
 MQSeries Channel Status PCF « View previous topic :: View next topic » 
Author Message
kingsley
PostPosted: Wed Sep 17, 2003 5:51 am    Post subject: MQSeries Channel Status PCF Reply with quote

Disciple

Joined: 30 Sep 2001
Posts: 175
Location: Hursley

Hi ,If any one has a program that uses PCF to find the channel status, pls. send it across asap.
Back to top
View user's profile Send private message Visit poster's website
clindsey
PostPosted: Wed Sep 17, 2003 7:04 am    Post subject: Reply with quote

Knight

Joined: 12 Jul 2002
Posts: 586
Location: Dallas, Tx

This is your lucky day.
I happen to have one I just used to test a problem. This only shows status,
bytes sent and bytes received. You should be able to follow what was
done for these attributes and plug in code to display the items you want.

Charlie

Code:

/******************************************************************************/
/* Includes                                                                   */
/******************************************************************************/
#include <stdio.h>
#include <string.h>           
#include <stdlib.h>         
#include <ctype.h>             

#include <cmqc.h>                          /* MQI                             */
#include <cmqcfc.h>                        /* PCF                             */
#include <cmqbc.h>                         /* MQAI                            */

#define  WAIT_TIME    5000                 /* wait time for mqexecute         */

/******************************************************************************/
/* Function prototypes                                                        */
/******************************************************************************/
void CheckCallResult(MQCHAR *, MQLONG , MQLONG);

/******************************************************************************/
/* Function: main                                                             */
/******************************************************************************/
int main(int argc, char *argv[])                 
{
   /***************************************************************************/
   /* MQAI variables                                                          */
   /***************************************************************************/
   MQHCONN hConn;                          /* handle to MQ connection         */
   MQCHAR qmName[MQ_Q_MGR_NAME_LENGTH+1]=""; /* default QMgr name             */
   MQCHAR cName[MQ_CHANNEL_NAME_LENGTH+1]=""; /* channel name to query        */
   MQLONG reason;                          /* reason code                     */
   MQLONG connReason;                      /* MQCONN reason code              */
   MQLONG compCode;                        /* completion code                 */
   MQHBAG adminBag = MQHB_UNUSABLE_HBAG;   /* admin bag for mqExecute         */
   MQHBAG responseBag = MQHB_UNUSABLE_HBAG; /* response bag for mqExecute     */
   MQHBAG optionsBag = MQHB_UNUSABLE_HBAG; /* options bag for mqExecute       */
   MQHBAG qAttrsBag;                       /* bag containing q attributes     */
   MQHBAG errorBag;                        /* bag containing cmd server error */
   MQLONG mqExecuteCC;                     /* mqExecute completion code       */
   MQLONG mqExecuteRC;                     /* mqExecute reason code           */
   MQLONG strAttrLength;                   /* Actual length of q name         */
   MQLONG intAttr;                         /* integer attribute returned      */
   MQLONG i;                               /* loop counter                    */
   MQLONG numberOfBags;                    /* number of bags in response bag  */
   MQCHAR strAttr[256];                    /* string attribute returned       */


   if (argc < 2)
   {
      printf("Syntax: %s chlname <queue manager name>\n",argv[0]);
      printf("\tchlname may contain wildcard characters.\n");
      exit(-1);
   }

   strncpy(cName, argv[1], MQ_CHANNEL_NAME_LENGTH);
   printf("\nDisplay current status of channel %s\n\n", cName);

   /***************************************************************************/
   /* Connect to the queue manager                                            */
   /***************************************************************************/
   if (argc > 2)
      strncpy(qmName, argv[2], (size_t)MQ_Q_MGR_NAME_LENGTH);
   MQCONN(qmName, &hConn, &compCode, &connReason);   

   /***************************************************************************/
   /* Report the reason and stop if the connection failed.                    */
   /***************************************************************************/
   if (compCode == MQCC_FAILED)
   {
      CheckCallResult("Queue Manager connection", compCode, connReason);
      exit( (int)connReason);
   }

   /***************************************************************************/
   /* Create an admin bag for the mqExecute call                              */
   /***************************************************************************/
   mqCreateBag(MQCBO_ADMIN_BAG, &adminBag, &compCode, &reason);
   CheckCallResult("Create admin bag", compCode, reason);

   /***************************************************************************/
   /* Create a response bag for the mqExecute call                            */
   /***************************************************************************/
   if (compCode == MQCC_OK)
   {
      mqCreateBag(MQCBO_ADMIN_BAG, &responseBag, &compCode, &reason);
      CheckCallResult("Create response bag", compCode, reason);
   }

   /***************************************************************************/
   /* Create an options bag to set the timeout value of the mqexecute call    */
   /***************************************************************************/
   if (compCode == MQCC_OK)
   {
      mqCreateBag(MQCBO_USER_BAG, &optionsBag, &compCode, &reason);
      CheckCallResult("Create options bag", compCode, reason);
      if (compCode == MQCC_OK && reason == MQRC_NONE)
      {
         mqAddInteger(optionsBag, MQIACF_WAIT_INTERVAL, WAIT_TIME, &compCode, &reason);
      }

      /********************************************************/
      /* If generating the options bag fails, just use the    */
      /* default time of 30 seconds by setting options bag    */
      /* to MQHB_NONE                                         */
      /********************************************************/
      if (compCode != MQCC_OK)
      {
         optionsBag = MQHB_NONE;
         compCode   = MQCC_OK;
         reason     = MQRC_NONE;
      }
   }

   /***************************************************************************/
   /* Put the channel name into the admin bag                                 */
   /***************************************************************************/
   if (compCode == MQCC_OK)
   {
      mqAddString(adminBag, MQCACH_CHANNEL_NAME, MQBL_NULL_TERMINATED, cName, &compCode, &reason);
      CheckCallResult("Add chl name", compCode, reason);
   }

   /***************************************************************************/
   /* Put the instance type into the admin bag                                */
   /* "Current" is the default so this is more for documentation              */
   /***************************************************************************/
   if (compCode == MQCC_OK)
   {
      mqAddInteger(adminBag, MQIACH_CHANNEL_INSTANCE_TYPE, MQOT_CURRENT_CHANNEL, &compCode, &reason);
      CheckCallResult("Add channel instance type", compCode, reason);
   }

   /***************************************************************************/
   /* Indicate we want all attributes                                         */
   /***************************************************************************/
   if (compCode == MQCC_OK)
   {
      mqAddInteger(adminBag, MQIACH_CHANNEL_INSTANCE_ATTRS, MQIACF_ALL, &compCode, &reason);
      CheckCallResult("Add status attrs", compCode, reason);
   }

   /***************************************************************************/
   /* The mqExecute call creates the PCF structure required, sends it to      */
   /* the command server, and receives the reply from the command server into */
   /* the response bag. The attributes are contained in system bags that are  */
   /* embedded in the response bag, one set of attributes per bag.            */
   /***************************************************************************/
   if (compCode == MQCC_OK)
   {
      mqExecute(hConn,                /* MQ connection handle                 */
                MQCMD_INQUIRE_CHANNEL_STATUS,/* Command to be executed        */
                optionsBag,           /* No options bag                       */
                adminBag,             /* Handle to bag containing commands    */
                responseBag,          /* Handle to bag to receive the response*/
                MQHO_NONE,            /* Put msg on SYSTEM.ADMIN.COMMAND.QUEUE*/ 
                MQHO_NONE,            /* Create a dynamic q for the response  */
                &compCode,            /* Completion code from the mqexecute   */
                &reason);             /* Reason code from mqexecute call      */
   }

   /***************************************************************************/
   /* Check the command server is started. If not exit.                       */
   /***************************************************************************/
   if (reason == MQRC_CMD_SERVER_NOT_AVAILABLE)
   {
      printf("Please start the command server: <strmqcsv QMgrName>\n");
      MQDISC(&hConn, &compCode, &reason);
      CheckCallResult("Disconnect from Queue Manager", compCode, reason);         
      exit(98);
   }

   /***************************************************************************/
   /* Check the result from mqExecute call. If successful find a display      */
   /* a few channel attributes. If failed find the error.                     */
   /***************************************************************************/
   if ( compCode == MQCC_OK )                      /* Successful mqExecute    */
   {
      /*************************************************************************/
      /* Count the number of system bags embedded in the response bag from the */
      /* mqExecute call. The attributes for each queue are in a separate bag.  */
      /*************************************************************************/
      mqCountItems(responseBag, MQHA_BAG_HANDLE, &numberOfBags, &compCode, &reason);
      CheckCallResult("Count number of bag handles", compCode, reason);

      for ( i=0; i<numberOfBags; i++)
      {
         /***********************************************************************/
         /* Get the next system bag handle out of the mqExecute response bag.   */
         /* This bag contains the channel attributes                            */
         /***********************************************************************/
         mqInquireBag(responseBag, MQHA_BAG_HANDLE, i, &qAttrsBag, &compCode, &reason);
         CheckCallResult("Get the result bag handle", compCode, reason);

         if (compCode == MQCC_OK && reason == MQRC_NONE)
         {
            /***********************************************************************/
            /* Get the channel name out of the channel attributes bag              */
            /***********************************************************************/
            mqInquireString(qAttrsBag, MQCACH_CHANNEL_NAME, 0, MQ_CHANNEL_NAME_LENGTH, strAttr,
                            &strAttrLength, NULL, &compCode, &reason);
            if (compCode == MQCC_OK && reason == MQRC_NONE)
            {
               mqTrim(MQ_CHANNEL_NAME_LENGTH, strAttr, strAttr, &compCode, &reason);
               printf("Channel name:             %s\n", strAttr);
            }

            /***********************************************************************/
            /* Get the channel status out of the attributes bag                    */
            /***********************************************************************/
            mqInquireInteger(qAttrsBag, MQIACH_CHANNEL_STATUS, MQIND_NONE, &intAttr,
                             &compCode, &reason);
            if (compCode == MQCC_OK && reason == MQRC_NONE)
            {
               printf("Channel Status:           ");
               switch (intAttr)
               {
                  case MQCHS_BINDING:
                     printf("Binding\n");
                     break;
                  case MQCHS_STARTING:
                     printf("Starting\n");
                     break;
                  case MQCHS_RUNNING:
                     printf("Running\n");
                     break;
                  case MQCHS_PAUSED:
                     printf("Paused\n");
                     break;
                  case MQCHS_STOPPING:
                     printf("Stopping\n");
                     break;
                  case MQCHS_RETRYING:
                     printf("Retrying\n");
                     break;
                  case MQCHS_STOPPED:
                     printf("Stopped\n");
                     break;
                  case MQCHS_REQUESTING:
                     printf("Requesting\n");
                     break;
                  case MQCHS_INITIALIZING:
                     printf("Initializing\n");
                     break;
                  default:
                     printf("UNKNOWN\n");
               }
            }

            /***********************************************************************/
            /* Get the Number of Messages Sent out of the attributes bag           */
            /* cast to unsigned long to get up to 4G on 32bit OS                   */
            /***********************************************************************/
            mqInquireInteger(qAttrsBag, MQIACH_MSGS, MQIND_NONE, &intAttr,
                             &compCode, &reason);
            if (compCode == MQCC_OK && reason == MQRC_NONE)
            {
               printf("Number of Messages Sent:  %u\n",(unsigned long)intAttr);
            }

            /***********************************************************************/
            /* Get the Number of Bytes Sent out of the attributes bag              */
            /***********************************************************************/
            mqInquireInteger(qAttrsBag, MQIACH_BYTES_SENT, MQIND_NONE, &intAttr,
                             &compCode, &reason);
            if (compCode == MQCC_OK && reason == MQRC_NONE)
            {
               printf("Number of Bytes Sent:     %u\n",(unsigned long)intAttr);
            }

            /***********************************************************************/
            /* Get the Number of Bytes Received out of the attributes bag          */
            /***********************************************************************/
            mqInquireInteger(qAttrsBag, MQIACH_BYTES_RCVD, MQIND_NONE, &intAttr,
                             &compCode, &reason);
            if (compCode == MQCC_OK && reason == MQRC_NONE)
            {
               printf("Number of Bytes Received: %u\n",(unsigned long)intAttr);
            }

         }
         printf("\n");
      }
   }

   else                                               /* Failed mqExecute     */
   {
      /*************************************************************************/
      /* If the command fails get the system bag handle out of the mqexecute   */
      /* response bag.This bag contains the reason from the command server     */
      /* why the command failed.                                               */
      /*************************************************************************/
      switch (reason)
      {
         case MQRCCF_COMMAND_FAILED:

            mqInquireBag(responseBag, MQHA_BAG_HANDLE, 0, &errorBag, &compCode, &reason);
            CheckCallResult("Get the result bag handle", compCode, reason);

            /***********************************************************************/
            /* Get the completion code and reason code, returned by the command    */
            /* server, from the embedded error bag.                                */
            /***********************************************************************/
            mqInquireInteger(errorBag, MQIASY_COMP_CODE, MQIND_NONE, &mqExecuteCC,
                             &compCode, &reason );
            CheckCallResult("Get the completion code from the result bag", compCode, reason);
            mqInquireInteger(errorBag, MQIASY_REASON, MQIND_NONE, &mqExecuteRC,
                             &compCode, &reason);
            CheckCallResult("Get the reason code from the result bag", compCode, reason);
            if (mqExecuteRC == MQRCCF_CHL_STATUS_NOT_FOUND)
            {
               printf("No status available for channel %s.\n",cName);
            }
            else
            {
               printf("Error returned by the command server: Completion Code = %d : Reason = %d\n",
                      mqExecuteCC, mqExecuteRC);       
            }

            break;
         
         case MQRC_NO_MSG_AVAILABLE:

            printf("No results returned for channel %s. This channel may not exist.\n", cName);
            break;

         default:
            printf("Call to get channel status attributes failed: Completion Code = %d : Reason = %d\n",
                   compCode, reason);
      }

   } 

   /***************************************************************************/
   /* Delete the admin bag if successfully created.                           */
   /***************************************************************************/
   if (adminBag != MQHB_UNUSABLE_HBAG)
   {
      mqDeleteBag(&adminBag, &compCode, &reason);
      CheckCallResult("Delete the admin bag", compCode, reason);
   }

   /***************************************************************************/
   /* Delete the response bag if successfully created.                        */
   /***************************************************************************/
   if (responseBag != MQHB_UNUSABLE_HBAG)
   {
      mqDeleteBag(&responseBag, &compCode, &reason);
      CheckCallResult("Delete the response bag", compCode, reason);
   }

   /***************************************************************************/
   /* Disconnect from the queue manager if not already connected              */
   /***************************************************************************/
   if (connReason != MQRC_ALREADY_CONNECTED)
   {
      MQDISC(&hConn, &compCode, &reason);
      CheckCallResult("Disconnect from Queue Manager", compCode, reason);         
   }
   return MQCC_OK;                               
}


/******************************************************************************/
/*                                                                            */
/* Function: CheckCallResult                                                  */
/*                                                                            */
/******************************************************************************/
/*                                                                            */
/* Input Parameters:  Description of call                                     */
/*                    Completion code                                         */
/*                    Reason code                                             */
/*                                                                            */
/* Output Parameters: None                                                    */
/*                                                                            */
/* Logic: Display the description of the call, the completion code and the    */
/*        reason code if the completion code is not successful                */
/*                                                                            */
/******************************************************************************/
void  CheckCallResult(char *callText, MQLONG cc, MQLONG rc)
{
   if (cc != MQCC_OK)
      printf("%s failed: Completion Code = %d : Reason = %d\n", callText, cc, rc);

}
Back to top
View user's profile Send private message
kingsley
PostPosted: Wed Sep 17, 2003 9:45 am    Post subject: Reply with quote

Disciple

Joined: 30 Sep 2001
Posts: 175
Location: Hursley

clindsey
Thanks for the Program. It's running fine according to my requirement. The program uses MQAI. I will integrate this into my work.

If you have any program using PCF's alone, pls. post it again.

Thanks again.
kalyan
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic  Reply to topic Page 1 of 1

MQSeries.net Forum Index » General IBM MQ Support » MQSeries Channel Status PCF
Jump to:  



You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Protected by Anti-Spam ACP
 
 


Theme by Dustin Baccetti
Powered by phpBB © 2001, 2002 phpBB Group

Copyright © MQSeries.net. All rights reserved.