Using Automation Orchestrator hosted workflows, you can integrate Automation Assembler with ServiceNow for ITSM compliance.

The ServiceNow integration flow goes through several Cloud Assembly, vSphere, vRealize Orchestrator, and ServiceNow services and APIs.

Enterprise users commonly integrate their Cloud Management Platform with an IT Service Management (ITSM) and Configuration Management Database (CMDB) platform for compliance. Following this example, you can integrate Automation Assembler with ServiceNow for CMDB and ITSM using Automation Orchestrator hosted workflows. When using Automation Orchestrator integrations and workflows, capability tags are especially useful if you have multiple instances for different environments. For more information on capability tags, See Using capability tags in Automation Assembler.
Note: You can also integrate ServiceNow with Automation Assembler using extensibility action scripts. For information about integrating ServiceNow using extensibility action scripts, see How do I integrate Automation Assembler with ServiceNow using extensibility actions.

In this example, the ServiceNow integration is composed of three top-level workflows. Each workflow has their own subscriptions so that you can update and iterate each component individually.

  • Event subscription entry point - Basic logging, identifies the requesting user and vCenter VM, if applicable.
  • Integration workflow - Separates objects and feeds inputs into the technical workflow, handles logging, property, and output updates.
  • Technical workflow - Downstream system integration for ServiceNow API to create the CMDB CI, CR, and Automation Assembler IaaS API with additional virtual machine properties outside of the payload.

Prerequisites

Procedure

  1. Create and save a configuration file in Automation Orchestrator that contains common configuration used in multiple workflows.
  2. Save your Automation Assembler API token in the same location, as the configuration file from Step 1.
    Note: The Automation Assembler API token has an expiration.
  3. Create a workflow in Automation Orchestrator with the provided script element. This script references and locates a REST Host. It also standardizes REST actions that use an optional parameter of a token, which is added as an extra authorization header.
    var configPath = "CS"
    var configName = "environmentConfig"
    var attributeName = "CASRestHost"
    
    //get REST Host from configuration element
    var restHost = System.getModule("au.com.cs.example").getRestHostFromConfig(configPath,configName,attributeName)
    
    var ConfigurationElement = System.getModule("au.com.cs.example").getConfigurationElementByName(configName,configPath);
    System.debug("ConfigurationElement:" + ConfigurationElement);
    var casToken = ConfigurationElement.getAttributeWithKey("CASToken")["value"]
    if(!casToken){
    	throw "no CAS Token";
    }
    //REST Template
    var opName = "casLogin";
    var opTemplate = "/iaas/login";
    var opMethod = "POST";
    
    // create the REST operation:
    var opLogin = System.getModule("au.com.cs.example").createOp(restHost,opName,opMethod,opTemplate);
    
    //cas API Token
    var contentObject = {"refreshToken":casToken}
    postContent = JSON.stringify(contentObject);
    
    var loginResponse = System.getModule("au.com.cs.example").executeOp(opLogin,null,postContent,null) ;
    
    try{
    	var tokenResponse = JSON.parse(loginResponse)['token']
    	System.debug("token: " + tokenResponse);
    } catch (ex) {
    	throw ex + " No valid token";
    }
    
    //REST Template  Machine Details
    var opName = "machineDetails";
    var opTemplate = "/iaas/machines/" + resourceId;
    var opMethod = "GET";
    
    var bearer = "Bearer " + tokenResponse;
    
    var opMachine = System.getModule("au.com.cs.example").createOp(restHost,opName,opMethod,opTemplate);
    
    // (Rest Operation, Params, Content, Auth Token)
    var vmResponse = System.getModule("au.com.cs.example").executeOp(opMachine,null,"",bearer) ;
    
    try{
    	var vm = JSON.parse(vmResponse);
    } catch (ex) {
    	throw ex + " failed to parse vm details"
    }
    
    System.log("cpuCount: " + vm["customProperties"]["cpuCount"]);
    System.log("memoryInMB: " + vm["customProperties"]["memoryInMB"]);
    
    cpuCount =  vm["customProperties"]["cpuCount"];
    memoryMB = vm["customProperties"]["memoryInMB"];

    This script sends the output cpuCount and memoryMB to the parent workflow and updates the existing customProperties properties. These values can be used in subsequent workflows when creating the CMDB.

  4. Add the ServiceNow CMDB Create CI script element to your workflow. This element locates the ServiceNow REST Host using the configuration item, creates a REST operation for the cmdb_ci_vmware_instance table, creates a string of content object based on workflow inputs for post data, and outputs the returned sys_id.
    var configPath = "CS"
    var configName = "environmentConfig"
    var attributeName = "serviceNowRestHost"
    var tableName = "cmdb_ci_vmware_instance"
    
    //get REST Host from configuration element
    var restHost = System.getModule("au.com.cs.example").getRestHostFromConfig(configPath,configName,attributeName)
    
    //REST Template
    var opName = "serviceNowCreatCI";
    var opTemplate = "/api/now/table/" + tableName;
    var opMethod = "POST";
    
    // create the REST operation:
    var opCI = System.getModule("au.com.cs.example").createOp(restHost,opName,opMethod,opTemplate);
    
    
    //cmdb_ci_vm_vmware table content to post;
    var contentObject = {};
    contentObject["name"] = hostname;
    contentObject["cpus"] = cpuTotalCount;
    contentObject["memory"] = MemoryInMB;
    contentObject["correlation_id"]=  deploymentId
    contentObject["disks_size"]=  diskProvisionGB
    contentObject["location"] = "Sydney";
    contentObject["vcenter_uuid"] = vcUuid;
    contentObject["state"] = "On";
    contentObject["owned_by"] = owner;
    
    postContent = JSON.stringify(contentObject);
    System.log("JSON: " + postContent);
    
    // (Rest Operation, Params, Content, Auth Token)
    var ciResponse = System.getModule("au.com.cs.example").executeOp(opCI,null,postContent,null) ;
    
    try{
    	var cmdbCI = JSON.parse(ciResponse);
    } catch (ex) {
    	throw ex + " failed to parse ServiceNow CMDB response";
    }
    
    serviceNowSysId = cmdbCI['result']['sys_id'];
  5. Using the output from the child workflow, create a properties object using the existing customProperties and overwrite the serviceNowSysId property with the value from ServiceNow. This unique id is used in the CMDB to mark an instance as retired on destroy.

Results

Automation Assembler is successfully integrated with ITSM ServiceNow.