Configuring health indicators using a client application

Health monitor configuration is accessible through the db2GetAlertCfg, db2UpdateAlertCfg, and db2ResetAlertCfg APIs in a C or C++ application. Each of these APIs can access the factory, instance, global, and object settings.

Before you begin

You must have an instance attachment to access the health monitor configuration. If there is not an attachment to an instance, then a default instance attachment is created. To access the health monitor configuration of a remote instance, you must first attach to that instance.

About this task

Combinations of the objType and defaultType parameters in the db2GetAlertCfgData structure allow access to the various levels of health indicator configuration.
Table 1. Settings for objType and defaultType to access configuration levels
Setting objType and defaultType
Factory settings objType = DB2ALERTCFG_OBJTYPE_{DBM | DATABASES |TABLESPACES | CONTAINERS} and defaultType = DB2ALERTCFG_DEFAULT
Global settings
objType = DB2ALERTCFG_OBJTYPE_{DBM |
DATABASES | TABLESPACES | CONTAINERS}
and defaultType = DB2ALERTCFG_NOT_DEFAULT  

or  

objType = DB2ALERTCFG_OBJTYPE_{DATABASE |
TABLESPACE | CONTAINER} and
defaultType = DB2ALERTCFG_DEFAULT
Object settings objType = DB2ALERTCFG_OBJTYPE_{DATABASE | TABLESPACE | CONTAINER} and defaultType = DB2ALERTCFG_NOT_DEFAULT

Procedure

  1. To get the specific object setting for health indicators on the SAMPLE database:
    1. Include the db2ApiDf.h header file, which is located in the sqllib\include directory.
      #include <db2ApiDf.h>
    2. Declare and initialize the sqlca and db2GetAlertCfgData structures.
      struct sqlca ca;
      memset (&sqlca, '\0', sizeof(struct sqlca));
       
      char* objName = NULL;
      char* dbName = "SAMPLE";
      db2Uint32 objType = DB2ALERTCFG_OBJTYPE_DATABASE;
      db2Uint32 defaultType = DB2ALERTCFG_NOT_DEFAULT;
       
      db2GetAlertCfgData data = {objType, objName, defaultType, dbName, 0, NULL} ;
      
    3. Call the db2GetAlertCfg API.
      rc = db2GetAlertCfg (db2Version810, &data, &ca);
    4. Process the returned configuration and free the buffer allotted by the API.
      if (rc >= SQLO_OK) {
        if ((data.ioNumIndicators > 0) && (data.pioIndicators != NULL)) {
          db2GetAlertCfgInd *pIndicators = data.pioIndicators;
       
          for (db2Uint32 i=0; i  data.ioNumIndicators; i++) {
      	//process the entry as necessary using fields defined in db2ApiDf.h
          }
        }
       
        db2GetAlertCfgFree (db2Version810, &data, &ca);
      }
  2. The following steps detail the procedure to update the alert configuration of the db.sort_shrmem_util health indicator for the global settings for database objects, setting warning threshold to 80 and adding task action 1.1:
    1. Include the db2ApiDf.h header file, which is located in the sqllib\include directory.
      #include <db2ApiDf.h>
    2. Declare and initialize the sqlca and db2AlertTaskAction structures.
      struct sqlca ca;
      memset (&sqlca, '\0', sizeof(struct sqlca));
       
      db2Uint32 objType = DB2ALERTCFG_OBJTYPE_DATABASES;
       
      db2Uint32 taskCondition = DB2ALERTCFG_CONDITION_WARNING;
      char* taskname = "1.1";
      char* hostname = NULL;
      char* userid = "nobody";
      char* password = "nothing";
       
      db2AlertTaskAction newTask={taskname,taskCondition,userid,password,hostname};
      
    3. Declare and initialize the db2UpdateAlertCfgData structure.
      struct db2UpdateAlertCfgData setData;
       
      setData.iObjType = objType;
      setData.piObjName = NULL;
      setData.piDbName = NULL;
       
      setData.iIndicatorID = 1002;
       
      setData.iNumIndAttribUpdates = 1;
      setData.piIndAttribUpdates[0].iAttribID = DB2ALERTCFG_WARNING;
      setData.piIndAttribUpdates[0].piAttribValue == 80;
       
      setData.iNumActionUpdates = 0;
      setData.piActionUpdates = NULL;
       
      setData.iNumActionDeletes = 0;
      setData.piActionDeletes = NULL;
       
      setData.iNumNewActions = 1;
      setData.piNewActions[0].iActionType = DB2ALERTCFG_ACTIONTYPE_TASK;
      setData.piNewActions[0].piScriptAttribs = NULL;
      setData.piNewActions[0].piTaskAttribs = &newTask;
      
    4. Call the db2UpdateAlertCfg API.
      rc = db2UpdateAlertCfg(db2Version810, &setData, &ca);
  3. The following steps detail the procedure to RESET the custom settings for the MYTS table space in the SAMPLE database.
    1. Include the db2ApiDf.h header file, which is located in the sqllib\include directory.
      #include <db2ApiDf.h>
    2. Declare and initialize the sqlca and db2ResetAlertCfgData structures.
      struct sqlca ca;
      memset (&sqlca, '\0', sizeof(struct sqlca));
       
      char* objName = "MYTS";
      char* dbName = "SAMPLE";
      db2Uint32 objType = DB2ALERTCFG_OBJTYPE_TABLESPACE;
       
      db2ResetAlertCfgData data = {objType, objName, dbName};
    3. Call the db2ResetAlertCfg API.
      rc = db2ResetAlertCfg (db2Version810, &data, &ca);