This documentation supports the 9.1 to 9.1 Service Pack 3 version and its patches of BMC Atrium Core. The documentation for version 9.1.04 and its patches is available here.

To view the latest version, select the version from the Product version menu.

Example- Finding all computers in the payroll division using the CMDBQueryByPath function

This CMDBQueryByPath example uses a common query scenario, where you want to search for all computers in a specific division in your organization.

At the fictional Calbro Services company, Allen Allbrook wants to view all the computers in the payroll division to compare their configurations. Because Allen knows the exact data model path to follow in the query, he uses the CMDBQueryByPath function in his program.

For information about the CIs and relationships in the common data model, see the BMC Atrium CMDB Common Data Model Diagram. The following pseudocode shows the construct for building the query.

BMC_ComputerSystem > BMC_MemberOfCollection --> BMC_Organization 'BusinessCategory'=Payroll

To search for all computers within the payroll division, Allen needs to query the BMC_ComputerSystem and the BMC_Organization classes that share a BMC_MemberOfCollection relationship and where the BusinessCategory attribute of the BMC_Organization class is equal to Payroll.

In the following sample program, Allen creates the queryObjects, queryObjectsOptional, qObj, and query variables. He then initializes these variables with specific values and passes them to the CMDBQueryByPath function as parameters.


/*declare variables*/

  CMDBQueryObjectList  queryObjects;
  CMDBQueryObjectList queryObjectsOptional;
  CMDBQueryObject *qObj;
  CMDBQueryStruct query;
  CMDBQueryStruct query;

/*Reset the memory space allocated for the query variable*/
  memset(&query, 0, sizeof(CMDBQueryStruct));
  memset(&query, 0, sizeof(CMDBQueryStruct));

/*Set values to the members of the query structure*/
  strcpy(query.datasetId, "BMC.ASSET");
  query.datasetMask = 0;
  query.datasetMask = 0;

/*Reset the memory space allocated for the queryObjects variable*/
  memset(&queryObjects, 0, sizeof(CMDBQueryObjectList));
  memset(&queryObjects, 0, sizeof(CMDBQueryObjectList));
  memset(&queryObjects, 0, sizeof(CMDBQueryObjectList));

/*Set values to the members of the queryObjects structure*/
  queryObjects.numItems = 3;
  queryObjects.queryObjectList = (CMDBQueryObject *) calloc(3, sizeof(CMDBQueryObject));
  queryObjects.queryObjectList = (CMDBQueryObject *) calloc(3, sizeof(CMDBQueryObject));

/* Initialize the qObj CMDBQueryObject structure for the BMC_ComputerSystem class*/
  qObj = &queryObjects.queryObjectList[0];
  strcpy(qObj->classNameId.namespaceName,"BMC.CORE");
  strcpy(qObj->classNameId.className, "BMC_ComputerSystem ");
  strcpy(qObj->alias, "class1");
  qObj->qualification = NULL;
  qObj->qualification = NULL;

/* Initialize the second query object for the BMC_MemberOfCollection class*/
  qObj = &queryObjects.queryObjectList[1];
  strcpy(qObj->classNameId.namespaceName,"BMC.CORE");
  strcpy(qObj->classNameId.className, "BMC_MemberOfCollection");
  strcpy(qObj->alias, "relationship1");
  qObj->qualification = NULL;
  qObj->qualification = NULL;

/* Initialize the third query Object for the BMC_Organization class*/
  qObj = &queryObjects.queryObjectList[2];
  strcpy(qObj->classNameId.namespaceName,"BMC.CORE");
  strcpy(qObj->classNameId.className, "BMC_Organization ");
  strcpy(qObj->alias, "class2");
  strcpy(qObj->alias, "class2");

/*Memory space allocated to contain qualification for the BMC_Organization class*/
  qObj->qualification = ( *) calloc (sizeof(), 1);
  qObj->qualification = ( *) calloc (sizeof(), 1);

/*Specify SIMPLE type operation for the qualification*/
  qObj->qualification->operation = CMDB_QUERY_QUAL_OP_SIMPLE;
  qObj->qualification->u.simpleOp = (CMDBQueryQualifierSimpleOpStruct *) calloc (sizeof(CMDBQueryQualifierSimpleOpStruct), 1);
  qObj->qualification->u.simpleOp = (CMDBQueryQualifierSimpleOpStruct *) calloc (sizeof(CMDBQueryQualifierSimpleOpStruct), 1);

/*Specify the attribute and arithmetic condition for the qualification*/
  qObj->qualification->u.simpleOp->operation = CMDB_QUERY_QUAL_SIMPLEOP_EQUAL;
  strcpy(qObj->qualification->u.simpleOp->attribute, "BusinessCategory");
  strcpy(qObj->qualification->u.simpleOp->attribute, "BusinessCategory");

/*Specify the expression to the right of the condition (right operand)*/
  qObj->qualification->u.simpleOp->operandRight = (CMDBQueryQualifierValueStruct *) calloc (sizeof(CMDBQueryQualifierValueStruct), 1);
  qObj->qualification->u.simpleOp->operandRight = (CMDBQueryQualifierValueStruct *) calloc (sizeof(CMDBQueryQualifierValueStruct), 1);

/*Specify the operand type for the right operand*/
  qObj->qualification->u.simpleOp->operandRight->type = CMDB_QUERY_QUAL_VALUE_TYPE_VALUE;
  qObj->qualification->u.simpleOp->operandRight->u.value.dataType = AR_DATA_TYPE_CHAR;
  qObj->qualification->u.simpleOp->operandRight->u.value.dataType = AR_DATA_TYPE_CHAR;

/* Specify the literal value for the comparison in the qualification*/
  qObj->qualification->u.simpleOp->operandRight->u.value.u.charVal = strdup("Payroll");
  qObj->qualification->u.simpleOp->operandRight->u.value.u.charVal = strdup("Payroll");

/*Specifies the object type for the top level object in the query*/
  qObj->queryObjectType = CMDB_QUERY_OBJECT_TYPE_REGULAR;
  qObj->queryObjectType = CMDB_QUERY_OBJECT_TYPE_REGULAR;

/*Set the queryObjectsOptional object with 0s to indicate that all attributes in the CMDBQueryObjectSelectorList object are required*/
  memset(&queryObjectsOptional, 0, sizeof(CMDBQueryObjectList));
  memset(&queryObjectsOptional, 0, sizeof(CMDBQueryObjectList));

/*Initialize the querySelector object*/
  memset(&querySelector, 0, sizeof(CMDBQueryObjectSelectorList));
  querySelector.numItems = 1;
  querySelector.queryObjectSelectorList = (CMDBQueryObjectSelectorStruct *) calloc(2, sizeof(CMDBQueryObjectSelectorStruct));
  querySelector.queryObjectSelectorList = (CMDBQueryObjectSelectorStruct *) calloc(2, sizeof(CMDBQueryObjectSelectorStruct));

/*Initialize the selector object*/
  selector = &querySelector.queryObjectSelectorList[0];
  strcpy(selector->alias, "class1");
  selector->attributes = (ARNameList *) calloc(sizeof (ARNameList), 1);
  selector->attributes->numItems = 1;
  selector->attributes->nameList = (ARNameType *) calloc(sizeof(ARNameType), 1);
  selector->attributes->nameList = (ARNameType *) calloc(sizeof(ARNameType), 1);

/*Specify the name of the attribute to retrieve*/
  strcpy(selector->attributes->nameList[0], "InstanceId"); querySelector.flags = CMDB_QUERY_OBJECTSELECTOR_FLAG_DEFAULT_NONE;
  query.queryObjects = &queryObjects;
  query.queryObjects = &queryObjectsOptional;
  query.queryObjectsToSelect = &querySelector;
  query.firstRetrieve = 0;
  query.maxRetrieve = 500;
  result = CMDBQueryByPath(GetControlStructPtr(), &query, &resultStruct, &status);



Allen wants to query the production dataset for all computer systems in the Payroll division. Therefore, he sets the datasetId member of the query variable to BMC.ASSET and the datasetMask member to 0. He then initializes the members of the queryObjects object and sets the numItems member to 3 to include the classes identified in the query: BMC_ComputerSystem, BMC_MemberOfCollection, and BMC_Organization.

Allen sets the qObj variable to the first queryObject object in the queryObjectList. He then initializes the Namespace, ClassName, alias, and qualification members to contain information about the BMC_ComputerSystem class. He initializes the second queryObject object to contain information about the BMC_MemberOfCollection class. For both BMC_ComputerSystem and BMC_MemberOfCollection classes, he does not specify any qualification.

Allen initializes the third queryObject object in the list to contain information about the BMC_Organization class. Because the qualification for this class is to be specified as BMC_Organization = 'Payroll', Allen allocates the memory space for the qualification member. He sets the operation type for the qualification to CMDB_QUERY_QUAL_OP_SIMPLE.

Allen then specifies the qualification for the BMC_Organization class. He sets the operation for the u.simpleOp member to CMDB_QUERY_QUAL_SIMPLEOP_EQUAL and the attribute to BusinessCategory.

Because Allen wants to query all computers in the Payroll division, the expression to the right of the condition in the query in this case is a literal value. Therefore, he sets the operand type for the right operand to CMDB_QUERY_QUAL_VALUE_TYPE_VALUE. He specifies the data type of the value as AR_DATA_TYPE_CHAR and sets the value for the right operand in the qualification to Payroll.

Allen sets the queryObjectType member of the qObj object to CMDB_QUERY_OBJECT_TYPE_REGULAR to indicate that the class information that qObj structure holds is a regular class. Because this query returns all the attributes specified in the selector list, he sets the &queryObjectsOptional object to 0 s.

Allen then initializes the querySelector object with the numItems member set to 1. He initializes the selector object, which points to the first object in the querySelector array, with values for the nameList member. Because Allen requires only the instance IDs of the computer systems, the InstanceId is the only attribute that is selected from the query result.

Allen sets the flags member of the querySelector object to CMDB_QUERY_OBJECTSELECTOR_FLAG_DEFAULT_NONE, which means that no attributes are selected from the query result by default. He sets the queryObjects, queryObjectsOptional, querySelector, firstRetrieve, and maxRetrieve members of the query object with the filled-in structures of each of the objects. He then finally passes these objects to the CMDBQueryByPath function. The query result is stored in the result variable, which is of type CMDBQueryResultStruct.

Was this page helpful? Yes No Submitting... Thank you

Comments