

翻訳は機械翻訳により提供されています。提供された翻訳内容と英語版の間で齟齬、不一致または矛盾がある場合、英語版が優先します。

# ServiceNow の接続
<a name="connecting-to-ticketing-and-chat-connecting-servicenow"></a>

このチュートリアルでは、ServiceNow インスタンスを AWS DevOps エージェントに接続して、チケットの作成時にインシデント対応調査を自動的に開始し、主要な検出結果を元のチケットに投稿できるようにします。また、特定のチケットのみを DevOps エージェントスペースに送信するように ServiceNow インスタンスを設定する方法と、複数の DevOps エージェントスペース間でチケットルーティングを調整する方法の例も含まれています。

## 初期セットアップ
<a name="initial-setup"></a>

最初のステップは、 AWS DevOps が ServiceNow インスタンスにアクセスするために使用できる OAuth アプリケーションクライアントを ServiceNow に作成することです。

### ServiceNow OAuth アプリケーションクライアントを作成する
<a name="create-a-servicenow-oauth-application-client"></a>

1. インスタンスのクライアント認証情報システムプロパティを有効にする

   1. フィルター検索ボックス`sys_properties.list`で検索し、Enter キーを押します ( オプションは表示されませんが、Enter キーを押すと機能します）。

   1. 新規を選択する

   1. 名前を `glide.oauth.inbound.client.credential.grant_type.enabled`、値を true に追加し、型を true \$1 false

![\[alt text not found\]](http://docs.aws.amazon.com/ja_jp/devopsagent/latest/userguide/images/09ed6d5ff911.png)


1. フィルター検索ボックスから System OAuth > Application Registry に移動します。

1. 「新規」 >「新しいインバウンド統合エクスペリエンス」 >「新しい統合」 >OAuth - クライアント認証情報付与」を選択します。

1. 名前を選択し、OAuth アプリケーションユーザーを「問題管理者」に設定し、「保存」をクリックします。

![\[alt text not found\]](http://docs.aws.amazon.com/ja_jp/devopsagent/latest/userguide/images/aeff4c127f7c.png)


### ServiceNow OAuth クライアントを AWS DevOps エージェントに接続する
<a name="connect-your-servicenow-oauth-client-to-aws-devops-agent"></a>

1. このプロセスは 2 つの場所で開始できます。まず、**Capability Providers** ページに移動し、**Communication** で **ServiceNow** を見つけ、**Register** をクリックします。または、作成した DevOps エージェントスペースを選択して、機能 → 通信 → 追加 → ServiceNow に移動し、登録をクリックします。

1. 次に、先ほど作成した OAuth アプリケーションクライアントを使用して、DevOps Agent が ServiceNow インスタンスにアクセスすることを許可します。

![\[alt text not found\]](http://docs.aws.amazon.com/ja_jp/devopsagent/latest/userguide/images/3db5a9aafc5f.png)

+ 次のステップに従い、ウェブフックに関する結果情報を保存します。

**重要**  
この情報は再度表示されません

![\[alt text not found\]](http://docs.aws.amazon.com/ja_jp/devopsagent/latest/userguide/images/80d0a319f87e.png)


### ServiceNow ビジネスルールを設定する
<a name="configure-your-servicenow-business-rule"></a>

接続を確立したら、ServiceNow でビジネスルールを設定して、DevOps エージェントスペース (複数可) にチケットを送信する必要があります。

1. アクティビティサブスクリプション → 管理 → ビジネスルールに移動し、新規をクリックします。

1. 「Table」フィールドを「Incident [incident]」に設定し、「Advanced」チェックボックスをオンにして、挿入、更新、削除後にルールを実行するように設定します。

![\[alt text not found\]](http://docs.aws.amazon.com/ja_jp/devopsagent/latest/userguide/images/6f2a7370e2c0.png)


1. 「詳細」タブに移動し、次のウェブフックスクリプトを追加し、ウェブフックシークレットと URL を指定された場所に挿入して、送信をクリックします。

```
(function executeRule(current, previous /*null when async*/ ) {

    var WEBHOOK_CONFIG = {
        webhookSecret: GlideStringUtil.base64Encode('<<< INSERT WEBHOOK SECRET HERE >>>'),
        webhookUrl: '<<< INSERT WEBHOOK URL HERE >>>'
    };

    function generateHMACSignature(payloadString, secret) {
        try {
            var mac = new GlideCertificateEncryption();
            var signature = mac.generateMac(secret, "HmacSHA256", payloadString);
            return signature;
        } catch (e) {
            gs.error('HMAC generation failed: ' + e);
            return null;
        }
    }

    function callWebhook(payload, config) {
        try {
            var timestamp = new Date().toISOString();
            var payloadString = JSON.stringify(payload);
            var payloadWithTimestamp =`${timestamp}:${payloadString}`;

            var signature = generateHMACSignature(payloadWithTimestamp, config.webhookSecret);

            if (!signature) {
                gs.error('Failed to generate signature');
                return false;
            }

            gs.info('Generated signature: ' + signature);

            var request = new sn_ws.RESTMessageV2();
            request.setEndpoint(config.webhookUrl);
            request.setHttpMethod('POST');

            request.setRequestHeader('Content-Type', 'application/json');
            request.setRequestHeader('x-amzn-event-signature', signature);
            request.setRequestHeader('x-amzn-event-timestamp', timestamp);

            request.setRequestBody(payloadString);

            var response = request.execute();
            var httpStatus = response.getStatusCode();
            var responseBody = response.getBody();

            if (httpStatus >= 200 && httpStatus < 300) {
                gs.info('Webhook sent successfully. Status: ' + httpStatus);
                return true;
            } else {
                gs.error('Webhook failed. Status: ' + httpStatus + ', Response: ' + responseBody);
                return false;
            }

        } catch (ex) {
            gs.error('Error sending webhook: ' + ex.getMessage());
            return false;
        }
    }

    function createReference(field) {
        if (!field || field.nil()) {
            return null;
        }

        return {
            link: field.getLink(true),
            value: field.toString()
        };
    }

    function getStringValue(field) {
        if (!field || field.nil()) {
            return null;
        }
        return field.toString();
    }

    function getIntValue(field) {
        if (!field || field.nil()) {
            return null;
        }
        var val = parseInt(field.toString());
        return isNaN(val) ? null : val;
    }

    var eventType = (current.operation() == 'insert') ? "create" : "update";

    var incidentEvent = {
        eventType: eventType.toString(),
        sysId: current.sys_id.toString(),
        priority: getStringValue(current.priority),
        impact: getStringValue(current.impact),
        active: getStringValue(current.active),
        urgency: getStringValue(current.urgency),
        description: getStringValue(current.description),
        shortDescription: getStringValue(current.short_description),
        parent: getStringValue(current.parent),
        incidentState: getStringValue(current.incident_state),
        severity: getStringValue(current.severity),
        problem: createReference(current.problem),
        additionalContext: {}
    };

    incidentEvent.additionalContext = {
        number: current.number.toString(),
        opened_at: getStringValue(current.opened_at),
        opened_by: current.opened_by.nil() ? null : current.opened_by.getDisplayValue(),
        assigned_to: current.assigned_to.nil() ? null : current.assigned_to.getDisplayValue(),
        category: getStringValue(current.category),
        subcategory: getStringValue(current.subcategory),
        knowledge: getStringValue(current.knowledge),
        made_sla: getStringValue(current.made_sla),
        major_incident: getStringValue(current.major_incident)
    };

    for (var key in incidentEvent.additionalContext) {
        if (incidentEvent.additionalContext[key] === null) {
            delete incidentEvent.additionalContext[key];
        }
    }

    gs.info(JSON.stringify(incidentEvent, null, 2)); // Pretty print for logging only

    if (WEBHOOK_CONFIG.webhookUrl && WEBHOOK_CONFIG.webhookSecret) {
        callWebhook(incidentEvent, WEBHOOK_CONFIG);
    } else {
        gs.info('Webhook not configured.');
    }

})(current, previous);
```

**機能プロバイダー**ページから ServiceNow 接続を登録する場合は、ServiceNow インシデントチケットを調査する DevOps エージェントスペースに移動し、機能 → 通信を選択し、機能プロバイダーページで登録した ServiceNow インスタンスを登録する必要があります。これで、すべてを設定する必要があり、発信者が「問題管理者」に設定されているすべてのインシデント ( AWS DevOps OAuth クライアントに付与したアクセス許可を模倣するため) は、設定された DevOps エージェントスペースでインシデント対応調査をトリガーします。これをテストするには、ServiceNow で新しいインシデントを作成し、インシデントの発信者フィールドを「問題管理者」に設定します。

![\[alt text not found\]](http://docs.aws.amazon.com/ja_jp/devopsagent/latest/userguide/images/4c7d24a85f88.png)


### ServiceNow チケットの更新
<a name="servicenow-ticket-updates"></a>

トリガーされたすべてのインシデント対応調査中、DevOps エージェントは主要な検出結果、根本原因分析、緩和計画の更新を元のチケットに提供します。エージェントの検出結果はインシデントのコメントに投稿され、現在、タイプ `finding`、、`cause``investigation_summary`、`mitigation_summary`、および調査ステータスの更新 (例: `AWS DevOps Agent started/finished its investigation`) のエージェントレコードのみを投稿します。

## チケットルーティングとオーケストレーションの例
<a name="ticket-routing-and-orchestration-examples"></a>

### シナリオ: DevOps エージェントスペースに送信されるインシデントのフィルタリング
<a name="scenario-filtering-which-incidents-are-sent-to-a-devops-agent-space"></a>

これは簡単なシナリオですが、インシデントソースを追跡するために ServiceNow でフィールドを作成するには、ServiceNow でいくつかの設定が必要です。この例では、SNOW フォームビルダーを使用して新しいソース (u\$1source) フィールドを作成します。これにより、インシデントソースを追跡し、それを使用して特定のソースから DevOps エージェントスペースにリクエストをルーティングできます。ルーティングは、Service Now ビジネスルールを作成し、「When」トリガーと「Filter Conditions」を設定するタブで実行します。この例では、フィルター条件を次のように設定します。

![\[alt text not found\]](http://docs.aws.amazon.com/ja_jp/devopsagent/latest/userguide/images/fac7a186beee.png)


### シナリオ: 複数の DevOps エージェントスペースにインシデントをルーティングする
<a name="scenario-routing-incidents-across-multiple-devops-agent-spaces"></a>

この例では、緊急度が 、カテゴリが `1`、またはサービスが の場合に DevOps エージェントスペース B で調査をトリガーし`AWS`、サービスが `Software` `AWS`、ソースが の場合に DevOps エージェントスペース A で調査をトリガーする方法を示します`Dynatrace`。

このシナリオは 2 つの方法で実現できます。ウェブフックスクリプト自体を更新して、このビジネスロジックを含めることができます。このシナリオでは、ServiceNow ビジネスルールを使用してこれを実現する方法を示し、透明性を高め、デバッグを簡素化します。ルーティングは、2 つの Service Now ビジネスルールを作成することで実現されます。
+ ServiceNow for DevOps エージェントスペース A でビジネスルールを作成し、条件ビルダーを使用して条件を作成し、指定した条件に基づいてのみイベントを送信します。

![\[alt text not found\]](http://docs.aws.amazon.com/ja_jp/devopsagent/latest/userguide/images/bca2f3928bf0.png)

+ 次に、ServiceNow for AgentSpace B で別のビジネスルールを作成します。このビジネスルールは、サービスが AWS でソースが Dynatrace の場合にのみトリガーされます。

![\[alt text not found\]](http://docs.aws.amazon.com/ja_jp/devopsagent/latest/userguide/images/bc29e4db1a76.png)


これで、指定された条件に一致する新しいインシデントを作成すると、DevOps エージェントスペース A または DevOps エージェントスペース B の調査がトリガーされ、インシデントルーティングをきめ細かく制御できるようになります。