Using TPL to enrich discovered data
While standard discovery processes can provide most key information, there are times when you might want to track information that is not available to discovery. A good example of this type of information is the exact location of a host. In most situations, there is nothing discoverable on a host that allows you to know that it is located in U23 of Rack 15 in Data Center 2 of the Houston campus. While the most common example of this is to track the location of hosts, similar approaches could be employed for relating hosts to organizational units, or owners.
BMC Discovery makes it very easy for you to extract information from external data sources and include it in its own data. Commonly, customers can use these capabilities to:
- Relate hosts to locations using a host naming scheme
- Reading location information from a file or registry setting
- Using a table in a pattern to relate subnets to locations
- Querying an SQL database for location information
These are described in the sections below.
In the TPL code (patterns) snippets, logging and basic error checking is shown in line with BMC Software recommendations. When you are developing patterns, you need to run them outside a normal discovery run against previously scanned host. For information on doing this, see Executing patterns manually.
Location using a naming scheme
template_host_location template pattern shows you how to relate hosts to locations based on hostname. This pattern relies on a naming scheme in which hostnames contain a location identifier such as
lon for London, or
hou for Houston.
See Pattern templates for a description of all template patterns supplied on the appliance.
Reading location from a file
A common way of incorporating location information into a host is to store a file in the host's file system. The
template_si_version_xml_file template pattern demonstrates taking information from an XML file to version an SI. The same approach can be used to extract location information from an XML file.
If the information is stored in an XML file use xpath as shown in the template pattern. The TPL xpath functions are described in the TPL Guide. In the case where information is placed in a flat file, a simple regex is the most effective method of extracting the location. The TPL regex functions are described in the TPL Guide.
Here is an example XML snippet for a file:
Here is the TPL which retrieves the file and uses xpath to obtain the location from the file:
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.
template_si_version_xml_file template pattern for an example of how these statements are used in the pattern.
Reading location from a registry key
Some administrators might prefer to place information in a registry setting rather then the files used in the previous section. The template pattern
template_si_version_registry demonstrates extracting information from the registry to version an SI. The same approach can be used to extract location information from the registry.
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.
The following TPL snippet shows the search from the host to associated subnet or subnets.
This TPL snippet uses the table to look up the location from the subnet.
Querying an SQL database for location information
template_sql_asset_integration template pattern is supplied with BMC Discovery which enables you to extract location information from an SQL database. To query a database you must define the asset database in the pattern and activate the pattern. After activation, this creates an integration point into which you add connection information. For information on using integration points to connect to databases, see Integration points.
Automatically creating locations
The pattern examples above have shown a number of ways of determining locations and how to create the relationship between host and existing location nodes. The following code snippet shows how you can create or update a location node, asserting that the location exists.