--- title: "ServiceNow: 配置与XOps事件的集成" slug: "servicenow-configuring-integration-with-xops-stories" updated: 2026-07-30T03:39:59Z published: 2026-07-30T03:39:59Z canonical: "knowledge.catonetworks.com/servicenow-configuring-integration-with-xops-stories" --- > ## Documentation Index > Fetch the complete documentation index at: https://knowledge.catonetworks.com/llms.txt > Use this file to discover all available pages before exploring further. # ServiceNow: 配置与XOps事件的集成 ## 概概览 XOps支持XOps事件与外部服务管理平台之间的双向同步。 此集成有助于将调查活动保持在跨平台的一致性,因此在一个平台中的更新将反映在另一个平台中。 欲了解更多信息,请参见[创建与服务管理平台的双向集成](/v1/docs/creating-bi-directional-integrations-with-service-management-platforms)。 ## 配置ServiceNow集成 要配置ServiceNow集成,请完成以下五个步骤。 ### 步骤1:创建自定义字段 在Cato管理应用程序中,创建字段以便在工单记载时填充。 **要创建自定义字段:** 1. 登录到ServiceNow平台。 2. 打开任何事件。 3. 从顶部横幅,右键单击并导航到**配置 > 表单生成器**。 4. 如果需要,请同意试用Form Builder,并选择默认视图。 5. 点击 **在事件表中添加新字段**。 6. 添加这些字段: - CMA账户ID - 类型:整数 - 属性:只读、必填、活跃 - CMA事件ID - 类型:字符串 - 属性:只读、必填、活跃 ### 步骤2:在CMA中创建服务API密钥 服务API密钥启用与外部工具和服务的可扩展集成,格式如下:`R=<...>|K=<...>`。 欲了解有关如何创建服务API密钥的更多信息,请参见[为Cato API生成API密钥](/v1/docs/generating-api-keys-for-the-cato-api)。 创建服务API密钥后,将其复制并保存,以便可输入到ServiceNow平台。 ### 步骤3:在安全的系统属性中安全存储API密钥 在ServiceNow平台中,创建一个安全的系统属性以存储API密钥。 **要创建一个安全的系统属性:** 1. 导航到 https://.service-now.com/sys_properties_list.do 2. **新建集成** 面板打开。 3. 在 **系统属性新记录** 表单中,添加以下详细信息: ![SN5.png](https://cdn.document360.io/81d0367c-2b69-4ba8-b412-1c8f46ce677e/Images/Documentation/35697265552285.png?sv=2026-02-06&spr=https&st=2026-11-19T06%3A49%3A46Z&se=2026-11-19T07%3A49%3A46Z&sr=b&sp=r&sig=0zXRMlYUeBWb1%2BNGmY3FcihGVAjTu5b4jYk4iIUmcZs%3D) - 名称:cma_prod_api_key - 类型:密码2 - 值:您在步骤2中创建的服务API密钥 4. 点击 **提交**。 ### 步骤4:创建REST消息 创建一个REST消息以发送ServiceNow事件的详细信息到Cato: **要创建REST消息:** 1. 在您的ServiceNow平台中,导航到 **全部>系统Web服务 > 出站 > REST 消息**。 2. **新建集成** 面板打开。 3. 在 **REST 消息** 表单中,添加以下详细信息: - 名称:为REST消息添加一个名称 - 端点:https://<您的Cato账户名称>.cc.catonetworks.com/api/v1/graphql2 - 认证类型:无认证 - HTTP方法:点击 **新建** 并添加以下详细信息: - 名称:添加一个名称 - HTTP方法:POST - 端点:https://<您的Cato账户名称>.cc.catonetworks.com/api/v1/graphql2 4. 点击**提交**。 ### 步骤5:创建业务规则 创建一个触发REST消息的业务规则。 **要创建业务规则:** 1. 在您的ServiceNow平台中,导航到 **全部 > 系统定义 > 业务规则**。 2. 单击 **新建**。 3. 在 **业务规则新记录** 表单中,添加以下详细信息: ![SN6.png](https://cdn.document360.io/81d0367c-2b69-4ba8-b412-1c8f46ce677e/Images/Documentation/35697286501149.png?sv=2026-02-06&spr=https&st=2026-11-19T06%3A49%3A46Z&se=2026-11-19T07%3A49%3A46Z&sr=b&sp=r&sig=gnKse85jk5avhfe5JB0Yt2KEYNK3TRDoq3dV2umEnxo%3D) - 名称:为业务规则添加一个名称 - 表:事件 - 时间:之后 - 更新:为真(选中复选框) - 过滤条件:备注变更 4. 在 **高级** 标签上,添加此脚本: ```plaintext (function executeRule(current, previous) {  try {    var lastComment = current.comments.getJournalEntry(1) || '';    lastComment = stripJournalHeader(lastComment);    if (!lastComment) {      gs.info("GraphQL webhook: Empty comment, skipping " + current.number);      return;    }    var accountId = current.u_cma_account_id;    var storyId = current.u_cma_story_id;        gs.info("GraphQL webhook: accountId " + accountId + " story " + storyId);    if (!accountId || !storyId) {      gs.error("GraphQL webhook: Missing accountId/storyId for " + current.number);      return;    }    var gqlQuery =      "mutation CreateStoryComment($accountId: ID!, $input: AddStoryCommentInput!) {" +      "  xdr(accountId: $accountId) {" +      "    addStoryComment(input: $input) {" +      "      comment { id type __typename }" +      "      __typename" +      "    }" +      "    __typename" +      "  }" +      "}";    var body = {      query: gqlQuery,      variables: {        accountId: accountId.toString(),        input: {          type: "USER",          storyId: storyId.toString(),          text: lastComment        }      }    };        var apiKey = gs.getProperty('cma_prod_api_key');    var r = new sn_ws.RESTMessageV2('Update XDR story comments CMA Prod', 'post');    r.setRequestHeader('Content-Type', 'application/json');    r.setRequestHeader('Accept', 'application/json');        r.setRequestHeader('x-api-key', apiKey);    r.setRequestBody(JSON.stringify(body));    //var response = r.execute(); // can be changed to Async - only for debug purposes        var eccSysId = r.executeAsync();    gs.info("GraphQL webhook queued, ECC sys_id=" + eccSysId);    var status = response.getStatusCode();    var responseBody = response.getBody();  // Safe logging (see next section for masking)     gs.info("GraphQL webhook: status=" + status);     gs.info("GraphQL webhook: responseBody=" + responseBody);  } catch (ex) {    gs.info("GraphQL webhook: Failed: " + ex.message);  }  function stripJournalHeader(text) {    text = text || '';    if (text.indexOf('\n') > -1) {      return text.split('\n').slice(1).join('\n').trim();    }    return text.trim();  } })(current, previous); ``` 5. 点击 **提交**。 ## 故障排查 您可以在以下位置识别问题和错误: - 系统日志:导航到 **系统日志 > 全部** 并搜索包含 `GraphQL webhook` 的信息。 - ECC记录:导航到 https://.service-now.com/sys_ecc_queue_list.do并定位具有记录`ECC sys_id` 的ECC 记录。 ### 常见问题 以下是常见问题及其原因的列表: | 问题 | 原因 | | --- | --- | | 评论未发送 | 评论文本为空 | | 缺少账户/事件ID | 自定义字段未填充 | | API返回400 | 请求格式错误 | | API返回401 | API密钥无效 |