設定出站整合以將IBM Cloud Logs與IBM Cloud Event Notifications連接

若要傳送 IBM Cloud Logs 範例中觸發警報時所產生的事件,您必須透過設定向外整合,將 IBM Cloud Logs 範例連接到 Event Notifications。

先決條件

步驟 1. 定義服務到服務授權

在IBM Cloud帳戶中使用服務到服務授權來授權IBM Cloud Logs服務將事件傳送到Event Notifications服務。

您必須設定一個服務來服務IBM Cloud Logs實例和Event Notifications實例之間的授權。 有關更多信息,請參閱 建立S2S授權以使用IBM Cloud Event Notifications服務

步驟 2. 使用 API 設定向外整合

您可以使用 API 建立向外整合。 如需 API 方法的詳細資訊,請參閱 建立向外整合

您只能透過 API 設定位於不同帳戶的 IBM Cloud Logs 與 Event Notifications 之間的整合。

例如,您可以使用下列 cURL 指令透過 API 建立整合:

curl -X POST "https://API-ENDPOINT/v1/outgoing_webhooks" \
 -H "Authorization: ${IAM_TOKEN}" \
 -H "Accept: application/json" \
 -H "Content-Type: application/json" \
 -d '{
  "type": "ibm_event_notifications",
  "name": "<NAME>",
  "ibm_event_notifications": {
   "event_notifications_instance_id": "<EventNotificationsInstanceID>",
   "region_id": "<Region-of-EventNotifications-Instance>",
   "endpoint_type": "default_or_public"
  }
 }'

其中

  • API-ENDPOINT:設定 IBM Cloud Logs 範例的 API 端點。

  • type:定義整合類型。 設定為 ibm _event_notifications。

  • name:輸入此資源定義的名稱。

  • IAM_TOKEN:輸入 IAM_TOKEN。 您可以執行下列指令來取得 IAM 令牌:

    export IAM_TOKEN=`ibmcloud iam oauth-tokens --output json | jq -r '.iam_token'`
    
  • event_notifications_instance_id:設定為 Event Notifications 範例 ID。

  • region_id:設定為 Event Notifications 範例可用的區域。

  • endpoint_type:定義整合是透過公用或專用網路進行。 有效值為:default_or_publicprivate

步驟 2. 在使用者介面中設定向外整合

完成下列步驟以設定向外整合:

  1. 在控制台中,按一下導航功能表圖示導覽功能表圖示> 資源清單
  2. 選擇您的IBM Cloud Logs實例。
  3. 在IBM Cloud Logs導覽中,按一下整合圖示整合圖示>出站整合
  4. 在出站整合部分中,找到Event Notifications並點選新增
  5. 整合頁面上,按一下新增
  6. 如果您的帳戶中不存在IBM Cloud Logs和Event Notifications之間的 IAM 授權,您必須透過按一下 IAM 授權進行設定。 依照提示授予服務之間的存取權限。 有關更多信息,請參閱 建立S2S授權以使用IBM Cloud Event Notifications服務
  7. 輸入整合的名稱。
  8. 選擇您想要連接到IBM Cloud Logs } 實例的Event Notifications服務實例。
  9. 選擇端點類型為公用或私有。 有關更多信息,請參閱 Event Notifications的服務端點
  10. 若要確認連接,請按一下 「儲存」

會建立一個 IBM Cloud Event Notifications 原始碼,其名稱如下:

IBM Cloud Logs - <CLOUD_LOGS_INSTANCE_ID>

例如,IBM Cloud Event Notifications 中的來源名稱如下所示:

IBM Cloud Logs - rfdt3147-484f-4dee-b3c7-ab0c85a8e5c7

出站整合的名稱不會用來命名 IBM Cloud Event Notifications 範例中的來源。

測試連線

啟用IBM Cloud Logs的通知後,測試您的連線以確保由IBM Cloud Logs產生的事件轉送到Event Notifications。

首先,在 Event Notifications 範例中完成下列步驟:

  1. 確認已在 IBM Cloud Event Notifications 範例中建立與您的整合名稱相符、名稱為 IBM Cloud Logs - <CLOUD_LOGS_INSTANCE_ID> 的來源。

    1. 選擇來源
    2. 尋找名稱為 IBM Cloud Logs - <CLOUD_LOGS_INSTANCE_ID> 的來源。
  2. 建立一個主題,指定此 Cloud Logs 範例為來源,且「事件類型」的範圍為「測試事件」。

    1. 選擇主題。 然後,按一下建立
    2. 輸入主題名稱,例如 CloudLogsInstance-test
    3. 選擇您要測試其整合的實體的來源 IBM Cloud Logs - <CLOUD_LOGS_INSTANCE_ID>
    4. 選擇事件類型 Test Event(測試事件 )。
    5. 選取新增條件 > 儲存來源
    6. 按一下建立
  3. 建立目的地 並確認目的地已設定。 例如,您可以設定 Slack 目的地或電子郵件。

  4. 建立主題與目的地配對的 Subscription。

    1. 輸入名稱,例如 Test integration
    2. 選擇主題 CloudLogsInstance-test
    3. 選擇目的地。
    4. 按一下建立

接下來,在 IBM Cloud Logs 中,完成以下步驟UI 中,完成以下步驟:

  1. 編輯向外整合。
  2. 按一下測試
  3. 檢查您選擇的目的地,並確認測試事件已傳送。