Using vRealize Orchestrator hosted workflows, you can integrate vRealize Automation Cloud Assembly with ServiceNow for ITSM compliance.

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 vRealize Automation Cloud Assembly with ServiceNow for CMDB and ITSM using vRealize Orchestrator hosted workflows. When using vRealize 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 vRealize Automation Cloud Assembly.
Note: You can also integrate ServiceNow with vRealize Automation Cloud Assembly using extensibility action scripts. For information about integrating ServiceNow using extensibility action scripts, see How do I integrate Cloud Assembly 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 CAS IaaS API with additional virtual machine properties outside of the payload.

Prerequisites

  • A standalone or clustered vRealize Orchestrator environment.
  • A vRealize Orchestrator integration in vRealize Automation Cloud Assembly. For information on integrating a standalone vRealize Orchestrator with vRealize Automation Cloud Assembly, see Configure vRealize Orchestrator integration in Cloud Assembly.

Procedure

  1. Create and save a configuration file in vRealize Orchestrator that contains common configuration used in multiple workflows.
  2. Save your CAS API token in the same location, as the configuration file from Step 1.
    Note: The CAS API token has an expiration.
  3. Create a workflow in vRealize 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

vRealize Automation Cloud Assembly is successfully integrated with ITSM ServiceNow. For more information on how you can use workflows to integrate ServiceNow in vRealize Automation Cloud Assembly, see Extending Cloud Assembly with vRealize Orchestrator for ServiceNow Integration.