How to Create Discovery Pattern Extensions and Why to Use Them

What is a discovery pattern extension

A pattern extension provides the ability to modify a pattern without customizing it. No more dreaded “Skipped Updates” to review during upgrades. Extensions can even be used to add connections for service mapping, just make sure you check that pattern_runtime_mode variable to not run for horizontal to discovery.

Important: At least one identification section needs to succeed in order for extensions to run. In the case where no identification sections are passing, you need to evaluate whether a new pattern is needed or to modify the existing one. If it is a minor change, I would personally customize the identification section and document the change. This will make it easier to evaluate future skipped updates.



How to build an extension and deploy

The scenario

In this scenario, the server team deploys a JSON file as part of the build process. We want to parse this file to populate some additional information on the CI.

Example File:

{
    "BuildDate": "2023-10-28",
    "Environment": "Development",
    "Notes": "Ubuntu container for testing discovery"
}

Create the new Extension

  1. Go to Pattern Designer - Discovery patterns in the navigator Discovery Patterns

  2. Search for Linux Server and open. Linux Server Pattern

  3. Click on the New button in the extension section. New Extension

  4. Type a descriptive name and click done. New Extension Section Note: ServiceNow will automatically increment the order. Order is important with extensions. Extensions will run in order and the last to run will win if there are any conflicting values. I want the values from our custom extension to always populate, so I am leaving the order as is.

  5. Click on the newly created extension to launch pattern designer New Extension Section



Build out the steps of the new extension

  1. You should now be greeted by pattern designer and an untitled step. Pattern Designer

  2. Click the Debug button and populate the ip address of a server to test with. If needed modify the mid server selection. Click connect and wait for the identification and lower order extension sections to run. Debug Debug Progress

  3. Once debugging is complete, You should see CI Attributes populated and temporary variables from previous identification sections and extensions. Debug Attributes

  4. Lets change the operation of the first step to Parse File, set the file location, set the parsing strategy to JSON, and terminate the extension if not found. Also rename the step to something descriptive Parse Files

  5. Click the **Retrieve File Content" button and let’s start parsing. The easiest way is to select the text you want to match on, then you will be prompted for the variable name. Make sure you remember to change the table name from Table_Name to something more descriptive. Select file outputs

  6. Now that we have defined our table, let’s click test and verify everything is working. Test Step

  7. Lets add a new step so we can use this data. Select Transform Table so we can update the values of the Linux Server with our parsed values. Remember to rename the step to something descriptive. Add Step

  8. Add a PreConditon that $BuildInfo is not empty. Set the source and target to our target CMDB table(Linux Server) and start populating data. All variables start with the $ sign and you should see autocomplete values to make this process easier. Transform Table

  9. Once done click Test and let’s validate our results. Test Table Transform

  10. Now that everything looks good, lets Save

  11. To ensure our pattern update is synced to the mid servers, go to Mid Servers - Servers and then click on the “Pattern Sync to Mid” button. You can check the status of the sync by looking at the ECC Queue Pattern Sync



Validating all our hard work

Now it’s time to see the new extension in action by running discovery on an endpoint.

  1. Go to Discovery - Schedules and click the Quick Discovery button Quick Discovery button

  2. Populate the ip of a hostname that should be discoverable and the correct mid server. Click ok to run. Quick Discovery Button

  3. Open the new discovery status and wait for the discovery to be completed. Go to the Discovery Log tab and find an item with the message Exploring CI Pattern, Pattern name: Linux Server, To Check Pattern Log Press Here. Find the extension on the left and click on it. You should now see logs from the execution. If there was an error, you could use the debug button top right to troubleshoot. Pattern Log

  4. Close the Pattern Log and go to the *Devices tab. Click on the link to the discovered configuration item. These fields are not on the form by default, so you need to show xml or add them. I added a section for illustration purposes. Config Item



Closing Thoughts

This is a very simple example of an extension. Discovery patterns and extensions can become quite complex and may include items such as pre/post processing scripts. Hopefully this helps and I’ve included some helpful links below.

Related Posts