Extending the CDM mapping

The following example shows how to extend the default CDM mapping for a host to create BMC_PhysicalLocation CIs from location information determined in BMC Discovery and relate these to BMC_ComputerSystem CIs.

The first pattern is used to determine the location of the host. Taken from Using TPL to enrich discovered data:

Using a table in a pattern to relate subnets to locations

Subnets can be used to identify locations of hosts. You can extend the template_host_location pattern to map subnets to locations. The following TPL snippet shows how you could use a table to map the subnet to hosts. You could also hard code a mapping of hostnames to locations if that information is available. See TPL Guide for more information on tables.

table SubnetLocations 1.0

    "" -> "London Victoria";
    "" -> "London Egham";
    "" -> "Houston";
    "" -> "Dallas";
    default -> "unknown";

end table;

The following TPL snippet shows the search from the host to associated subnet or subnets.

    subnet_list := search(in host traverse DeviceWithAddress:DeviceAddress:IPv4Address:IPAddress
                                  traverse DeviceOnSubnet:DeviceSubnet:Subnet:Subnet);
    location_id := '';
    list_size := size(subnet_list);
    log.debug("Subnet_2_Locations: subnet_list size is %list_size%");
    for subnet_node in subnet_list do
        log.debug("Subnet_2_Locations: Current subnet_node is %subnet_node.ip_address_range%");
        // if subnet_node is "None" get next node otherwise we can use this one
        if '%subnet_node.ip_address_range%' <> "None" then
            location_id:= '%subnet_node.ip_address_range%';
        end if;
    end for;

This TPL snippet uses the table to look up the location from the subnet.

    // Look up the location name from the table
    location_name := SubnetLocations[location_id];

Now you can create or update the relationship between the host and location node. The following code snippet uses the model.uniquerel function to create or update the relationship.

    // Relate host to location. Using "uniquerel" rather than "rel" means that
    // any existing Location relationships between this Host (the first 
    // parameter) and any Location nodes other than the one given (the second
    // parameter) are removed. If a host has changed location, this keeps the
    // model up-to-date.
    log.info("Subnet_2_Locations: model.uniquerel.Location %host% %location%");
       ElementInLocation := host, 
       Location := location

The host is now related to the location node which represents its physical location.

The second pattern is the template_cmdb_location template which is available in the Pattern Templates section of the Pattern Management page. See Pattern templates for more information on the template patterns supplied with BMC Discovery. The syncmapping is described in the TPL Guide.

The template_cmdb_location syncmapping extends the root mapping for Host nodes. The mapping section specifies the extension to the root mapping using the from keyword. The traversal finds related location nodes, and the mapping from phys_loc to BMC_PhysicalLocation is defined.

The name defined by the traversal can only be used in a for each expression; it cannot be used in any other context.

    mapping from Host_ComputerSystem.host as host
        traverse ElementInLocation:Location:Location:Location as location
	    phys_loc -> BMC_PhysicalLocation;

        end traverse;

    end mapping;

The body of the template_cmdb_location pattern loops through each location reached by the traversal, and transforms the subgraph of data in the Discovery model into a subgraph of CIs in the target CMDB model. This is copied across and then the relationship is created between the BMC_ComputerSystem and the new BMC_PhysicalLocation in the CMDB.

        computersystem := Host_ComputerSystem.computersystem;

        for each location do
            // ADDM Location nodes created by patterns have a key
            // attribute, but those created in the UI do not. We use
            // the name attribute if the key is not present.
            if location.key then
                key := location.key;
                key := location.name;
            end if;

            // Specify the BMC_PhysicalLocation CI. You may wish to
            // add more attributes to the ADDM Location node and copy
            // them across here.
            phys_loc := sync.shared.BMC_PhysicalLocation(
                key              := key,
                Name             := location.name,
                ShortDescription := location.name,
                Description      := location.description,
                Address          := location.address,
                Category         := "Reference Configuration",
                Type             := "Facilities",
                Item             := "Space Management"
            // Relate the BMC_ComputerSystem to the new BMC_PhysicalLocation
                Source      := computersystem,
                Destination := phys_loc,
                Name        := "ELEMENTLOCATION"
        end for;

    end body;
Was this page helpful? Yes No Submitting... Thank you