拡張性アクションを使用して、Cloud Assembly を ServiceNow のような Enterprise ITSM と統合できます。

ServiceNow 統合フローは、いくつかの Cloud Assembly、Amazon Web Services、ServiceNow サービスおよび API を経由します。
エンタープライズ ユーザーは、コンプライアンスを実現するために、一般的に Cloud Management Platform と IT サービス管理 (ITSM) および構成管理データベース (CMDB) プラットフォームを統合します。この例のとおりに、拡張性アクション スクリプトを使用することにより、 Cloud Assembly を CMDB および ITSM 用の ServiceNow と統合できます。
注: また、 vRealize Orchestrator ワークフローを使用することにより、ServiceNow を Cloud Assembly と統合することもできます。ワークフローを使用して ServiceNow と統合する方法については、 vRealize Orchestrator ワークフローを使用して、ITSM 用の Cloud Assembly を ServiceNow と統合する方法を参照してください。

この統合を作成するには、4 つの拡張性アクション スクリプトを使用します。最初の 3 つのスクリプトは、プロビジョニング中に、コンピューティング プロビジョニング後イベントで順番に開始されます。4 番目のスクリプトは、コンピューティング削除後イベントでトリガされます。

イベント トピックの詳細については、Cloud Assembly で提供されるイベント トピックを参照してください。

4 つの拡張性アクション スクリプトはそれぞれ優先度が異なります。最も高い優先度は、仮想マシンの詳細の取得と ServiceNow CMDB CI の使用中止の拡張性アクション スクリプトに付与されます。

[仮想マシンの詳細の取得]

仮想マシンの詳細の取得スクリプトは、CI の作成に必要な追加のペイロードの詳細と、Amazon Web Services Systems Manager パラメータ ストア (SSM) に保存されている ID トークンを取得します。また、このスクリプトは、後で使用するために、customProperties を追加プロパティで更新します。

[ServiceNow CMDB CI の作成]
ServiceNow CMDB CI の作成スクリプトは、ServiceNow インスタンス URL を入力として渡し、セキュリティ要件を満たすためにインスタンスを SSM に保存します。また、このスクリプトは、ServiceNow CMDB の一意のレコード識別子応答 (sys_id) を読み取ります。これを出力として渡し、作成中にカスタムプロパティ serviceNowSysId を書き込みます。この値は、インスタンスが破棄されたときに CI を使用中止としてマークするために使用されます。
注: Lambda が SSM パラメータ ストアにアクセスできるようにするために、 vRealize Automation services Amazon Web Services ロールに追加権限を割り当てることが必要になる場合があります。

[ServiceNow の変更の作成]

このスクリプトは、ServiceNow インスタンス URL を入力として渡し、ServiceNow 認証情報を SSM として保存してセキュリティ要件を満たすことで、ITSM の統合を完了します。

[ServiceNow の変更の作成]

ServiceNow CMDB CI の使用中止スクリプトは、ServiceNow に停止するように指示し、作成スクリプトで作成されたカスタムプロパティ serviceNowSysId に基づいて CI を使用中止とマークします。

前提条件

  • この統合を設定する前に、次の条件付きクラウド テンプレート プロパティを使用してすべてのイベント サブスクリプションをフィルタリングします。event.data["customProperties"]["enable_servicenow"] === "true"
    注: このプロパティは、ServiceNow との統合が必要なクラウド テンプレートで設定できます。
  • Python をダウンロードしてインストールします。

サブスクリプションのフィルタリングの詳細については、拡張サブスクリプションの作成を参照してください。

手順

  1. 仮想マシンからコマンドライン プロンプトを開きます。
  2. 仮想マシンの詳細の取得スクリプトを実行します。
    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. CMDB 構成アイテムの作成アクションを実行します。
    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. 作成アクション スクリプトを実行します。
    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)

結果

Cloud Assembly は ITSM ServiceNow と正常に統合されました。

次のタスク

必要に応じて、CMDB 構成アイテムの削除アクションを使用することにより、CI の使用を中止できます。
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)

Cloud Assembly で、拡張性アクションを使用して ServiceNow を統合する方法の詳細については、Extending Cloud Assembly with Action Based Extensibility for ServiceNow Integrationを参照してください。