logo

NJP

Listing Container Packages for an App Service

Import · Apr 04, 2024 · article

With ServiceNow's ability to list the packages in a container image, we have all the pieces in the CMDB to answer questions like "what software is this App Service using?" and "which App Services have this software?". The piece that requires a bit of customization is getting that information directly, vs. having to pull it together each time. Here's an example of using a custom table and no code subflow to have that data at your fingertips for tag-based application services created using Kubernetes metadata.

NOTE: the content in this example comes with no support or warranty, explicit or implied.

Subflow

The core of this example is the subflow "App Service Software Packages"; it takes an Application Service reference as input and performs the following steps:

- look up cmdb_rel_ci records with the app service as parent and relationship "Depends on::Used by"

- for each record found, look up cmdb_rel_ci records with the previous child as the parent and relationship "Depends on::Used by"

- for each record found, look up cmdb_rel_ci records with the previous child as the parent, relationship "Instantiates::Instantiated by", and class Kubernetes Pod

- for each record found, look up cmdb_rel_ci records with the previous child as the parent, and class Docker Image

- for each record found, look up sn_itom_pattern_container_image_os_packages records with the previous child as the image

- for each record found, create a record in the custom table with the app service set to the subflow input and the package referencing the current record

Flow

I created a flow which could be used to trigger the subflow on the desired basis, such as an App Service record being modified, or a scheduled basis. For some reason I haven't yet figured out, I'm not seeing consistent triggering when an App Service is updated, which prompted me to also create a UI action.

UI Action

Using the "Code Snippet" functionality of the subflow editor, I also generated a UI action for the App Service table (cmdb_ci_service_by_tags), named "Update Software Inventory".

The example scoped app I created is included as an attachment here. Feel free to browse it for further insight and ideas.

View original source

https://www.servicenow.com/community/itom-articles/listing-container-packages-for-an-app-service/ta-p/2888334