Using extensibility actions you can integrate Automation Assembler with an Enterprise ITSM, like ServiceNow.

The ServiceNow integration flow goes through several Automation Assembler, Amazon Web Services, 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 by using extensibility action scripts.
Nota: You can also integrate ServiceNow with Automation Assembler by using Automation Orchestrator workflows. For information about integrating ServiceNow by using workflows, see Cómo se integra Automation Assembler para ITSM con ServiceNow mediante flujos de trabajo de Automation Orchestrator.

To create this integration, you use four extensibility action scripts. The first three scripts are initiated in sequence during provisioning, at the compute provision post event. The fourth script triggers at the compute removal post event.

For more information on event topics, refer to Temas de eventos proporcionados con Automation Assembler.

The four extensibility action scripts have different levels of priority. The highest level of priority is given for the Get VM Details and Retire Service Now CMDB CI extensibility action scripts.

Get VM Details

The Get VM details script acquires additional payload details required for CI creation and an identity token that is stored in Amazon Web Services Systems Manager Parameter Store (SSM). Also, this script updates customProperties with additional properties for later use.

Create ServiceNow CMDB CI
The Create ServiceNow CMDB CI script passes the ServiceNow instance URL as an input and stores the instance in SSM to meet security requirements. This script also reads the ServiceNow CMDB unique record identifier response (sys_id). It passes it as an output and writes the custom property serviceNowSysId during creation. This value is used to mark the CI as retired when the instance is destroyed.
Nota: Additional permissions might need to be allocated to your VMware Aria Automation services Amazon Web Services role to allow Lambda to access the SSM Parameter Store.

Create ServiceNow Change

This script finishes the ITSM integration by passing the ServiceNow instance URL as an input and storing the ServiceNow credentials as SSM to meet security requirements.

Create ServiceNow Change

The retire ServiceNow CMDB CI script prompts the ServiceNow to stop and marks the CI as retired based on the custom property serviceNowSysId that was created in the creation script.

Requisitos previos

  • Before configuring this integration, filter all event subscriptions with the conditional cloud template property: event.data["customProperties"]["enable_servicenow"] === "true"
    Nota: This property exists on cloud templates that require a ServiceNow integration.
  • Download and install Python.

For more information on filtering subscriptions, see .Crear una suscripción de extensibilidad.

Procedimiento

  1. Open a command-line prompt from your Virtual Machine.
  2. Run the Get VM details script.
    from botocore.vendored import requests
    import json
    import boto3
    client = boto3.client('ssm','ap-southeast-2')
    
    def handler(context, inputs):
        baseUri = inputs['url']
        casToken = client.get_parameter(Name="casToken",WithDecryption=True)
        
        url = baseUri + "/iaas/login"
        headers = {"Accept":"application/json","Content-Type":"application/json"}
        payload = {"refreshToken":casToken['Parameter']['Value']}
        
        results = requests.post(url,json=payload,headers=headers)
        
        bearer = "Bearer "
        bearer = bearer + results.json()["token"]
        
        deploymentId = inputs['deploymentId']
        resourceId = inputs['resourceIds'][0]
        
        print("deploymentId: "+ deploymentId)
        print("resourceId:" + resourceId)
        
        machineUri = baseUri + "/iaas/machines/" + resourceId
        headers = {"Accept":"application/json","Content-Type":"application/json", "Authorization":bearer }
        resultMachine = requests.get(machineUri,headers=headers)
        print("machine: " + resultMachine.text)
        
        print( "serviceNowCPUCount: "+ json.loads(resultMachine.text)["customProperties"]["cpuCount"] )
        print( "serviceNowMemoryInMB: "+ json.loads(resultMachine.text)["customProperties"]["memoryInMB"] )
        
        #update customProperties
        outputs = {}
        outputs['customProperties'] = inputs['customProperties']
        outputs['customProperties']['serviceNowCPUCount'] = int(json.loads(resultMachine.text)["customProperties"]["cpuCount"])
        outputs['customProperties']['serviceNowMemoryInMB'] = json.loads(resultMachine.text)["customProperties"]["memoryInMB"]
        return outputs
  3. Run the CMDB configuration item creation action.
    from botocore.vendored import requests
    import json
    import boto3
    client = boto3.client('ssm','ap-southeast-2')
    
    def handler(context, inputs):
    
        snowUser = client.get_parameter(Name="serviceNowUserName",WithDecryption=False)
        snowPass = client.get_parameter(Name="serviceNowPassword",WithDecryption=True)
        table_name = "cmdb_ci_vmware_instance"
        url = "https://" + inputs['instanceUrl'] + "/api/now/table/{0}".format(table_name)
        headers = {'Content-type': 'application/json', 'Accept': 'application/json'}
        payload = {
            'name': inputs['customProperties']['serviceNowHostname'],
            'cpus': int(inputs['customProperties']['serviceNowCPUCount']),
            'memory': inputs['customProperties']['serviceNowMemoryInMB'],
            'correlation_id': inputs['deploymentId'],
            'disks_size': int(inputs['customProperties']['provisionGB']),
            'location': "Sydney",
            'vcenter_uuid': inputs['customProperties']['vcUuid'],
            'state': 'On',
            'sys_created_by': inputs['__metadata']['userName'],
            'owned_by': inputs['__metadata']['userName']
            }
        results = requests.post(
            url,
            json=payload,
            headers=headers,
            auth=(snowUser['Parameter']['Value'], snowPass['Parameter']['Value'])
        )
        print(results.text)
    
        #parse response for the sys_id of CMDB CI reference
        if json.loads(results.text)['result']:
            serviceNowResponse = json.loads(results.text)['result']
            serviceNowSysId = serviceNowResponse['sys_id']
            print(serviceNowSysId)
    
            #update the serviceNowSysId customProperty
            outputs = {}
            outputs['customProperties'] = inputs['customProperties']
            outputs['customProperties']['serviceNowSysId'] = serviceNowSysId;
            return outputs
  4. Run the Creation action script.
    from botocore.vendored import requests
    import json
    import boto3
    client = boto3.client('ssm','ap-southeast-2')
    
    def handler(context, inputs):
        snowUser = client.get_parameter(Name="serviceNowUserName",WithDecryption=False)
        snowPass = client.get_parameter(Name="serviceNowPassword",WithDecryption=True)
        table_name = "change_request"
        url = "https://" + inputs['instanceUrl'] + "/api/now/table/{0}".format(table_name)
        headers = {'Content-type': 'application/json', 'Accept': 'application/json'}
        payload = {
            'short_description': 'Provision CAS VM Instance'      
                  }
        results = requests.post(
            url,
            json=payload,
            headers=headers,
            auth=(snowUser['Parameter']['Value'], snowPass['Parameter']['Value'])
        )
        print(results.text)

Resultados

Automation Assembler is successfully integrated with ITSM ServiceNow.

Qué hacer a continuación

When desired, you can retire your CI by using the CMDB configuration item retire action:
from botocore.vendored import requests
import json
import boto3
client = boto3.client('ssm','ap-southeast-2')

def handler(context, inputs):
    snowUser = client.get_parameter(Name="serviceNowUserName",WithDecryption=False)
    snowPass = client.get_parameter(Name="serviceNowPassword",WithDecryption=True)
    tableName = "cmdb_ci_vmware_instance"
    sys_id =inputs['customProperties']['serviceNowSysId']
    url = "https://" + inputs['instanceUrl'] + "/api/now/"+tableName+"/{0}".format(sys_id)
    headers = {'Content-type': 'application/json', 'Accept': 'application/json'}
    payload = {
        'state': 'Retired'
        }

    results = requests.put(
        url,
        json=payload,
        headers=headers,
        auth=(inputs['username'], inputs['password'])
    )
    print(results.text)

For more information on how you can use extensibility actions to integrate ServiceNow in Automation Assembler, see Extending Cloud Assembly with Action Based Extensibility for ServiceNow Integration.