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 Helix 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
"10.10.10.0/24" -> "London Victoria";
"10.10.11.0/24" -> "London Egham";
"172.17.94.0/24" -> "Houston";
"172.18.95.0/24" -> "Dallas";
default -> "unknown";
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
where ip_address_range defined
list_size := size(subnet_list);
log.debug("subnet_list size is %list_size%");
// The search returns a list. We pick the first IP range for which there
// is an entry in the SubnetLocations table
location_name := none;
for ip_address_range in subnet_list do
if ip_address_range in SubnetLocations then
// Matched, so set the location_name and break out of the loop
location_name := SubnetLocations[ip_address_range];
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 Helix Discovery. The syncmapping is described in the TPL Guide.
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
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;
The body of the
template_cmdb_location pattern loops through each location reached by the traversal, and transforms the subgraph of data in the BMC Helix 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;
// 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"