

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# 在 Amazon OpenSearch Service 中設定提醒
<a name="alerting"></a>

在 Amazon OpenSearch Service 中設定提醒，以便在一或多個索引的資料符合特定條件時收到通知。例如，您可能希望在應用程式於 1 個小時內記錄超過 5 個以上的 HTTP 503 錯誤時收到電子郵件，或者在過去 20 分鐘內未有任何新文件編製成索引時通知開發人員。

提醒需要 OpenSearch 或 Elasticsearch 6.2 或更新版本。

**注意**  
本文件提供提醒的簡短概觀，並強調 Amazon OpenSearch Service 網域上的提醒與開放原始碼 OpenSearch 叢集上的提醒有何不同。如需完整的提醒文件，包括完整的 API 參考、複合監視器的可用請求欄位清單，以及可用觸發和動作變數的說明，請參閱 OpenSearch 文件中的[提醒](https://opensearch.org/docs/latest/monitoring-plugins/alerting/index/)。

**Topics**
+ [提醒許可](#alerting-diff-perms)
+ [提醒入門](#alerting-getstarted)
+ [通知](#alerting-notifications)
+ [差異](#alerting-diff)

## 提醒許可
<a name="alerting-diff-perms"></a>

提醒支援[精細存取控制](fgac.md)。如需混合和匹配許可以符合您的使用案例的詳細資訊，請參閱 OpenSearch 文件中的[提醒安全](https://opensearch.org/docs/latest/monitoring-plugins/alerting/security/)。

若要存取 OpenSearch Dashboards 中的**提醒**頁面，您必須至少對應至`alerting_read_access`預先定義的角色，或獲得同等許可。此角色授予檢視提醒、目的地和監視器的許可，但不認可提醒或修改目的地或監視器。

## 提醒入門
<a name="alerting-getstarted"></a>

若要建立提醒，您可以設定 *monitor* (監控)，這是按照定義的排程執行並查詢 OpenSearch 索引的任務。您也可以設定一個或多個*觸發條件*，這些觸發條件會定義產生事件的條件。最後，您可以設定 *action* (動作)，這是觸發提醒之後發生的動作。

**開始使用提醒**

1. 從 OpenSearch Dashboards 主選單中選擇 **Alerting** (提醒)，並選擇 **Choose Alerting** (建立提醒)。

1. 建立每個查詢、每個儲存貯體、每個叢集指標或每個文件監控。如需相關說明，請參閱 [Create a monitor](https://opensearch.org/docs/latest/monitoring-plugins/alerting/monitors/#create-a-monitor) (建立監控)。

1. 針對 **Trigger** (觸發條件)，建立一個或多個觸發條件。如需相關說明，請參閱 [Create triggers](https://opensearch.org/docs/latest/monitoring-plugins/alerting/monitors/#create-triggers) (建立觸發條件)。

1. 針對 **Action** (動作)，設定提醒的 [notification channel](#alerting-notifications) (通知頻道)。在 Slack、Amazon Chime、自訂 Webhook 或 Amazon SNS 之間進行選擇。如您所想，通知需要連線到相關頻道。例如，若要通知 Slack 頻道或將自訂 Webhook 傳送至第三方伺服器，您的 OpenSearch Service 網域需要適當的網路連線。自訂 Webhook 必須具有公有 IP 地址，以便 OpenSearch Service 網域向其傳送提醒。
**提示**  
當動作成功傳送簡訊之後，您就必須負責保護該簡訊的存取權 (例如，存取 Slack 頻道)。如果您的網域包含敏感資料，請考慮在沒有動作的情況下使用觸發程序，並定期檢查 Dashboards 是否有提醒。

## 通知
<a name="alerting-notifications"></a>

提醒與通知整合，這是 OpenSearch 通知的統一系統。通知可讓您設定要使用的通訊服務，並查看相關統計資料和疑難排解資訊。如需完整文件，請參閱 OpenSearch 文件中的[通知](https://opensearch.org/docs/latest/notifications-plugin/index/)。

您的網域必須執行 OpenSearch 2.3 版或更新版本才能使用通知。

**注意**  
OpenSearch 通知獨立於 OpenSearch 服務[通知](managedomains-notifications.md)，它提供有關服務軟體更新、自動調整增強功能以及其他重要網域層級資訊的詳細資訊。OpenSearch 通知針對特定的外掛程式。

從 OpenSearch 2.0 版開始，通知頻道取代了提醒目的地。目的地已被正式取代，並且所有提醒通知將透過未來的頻道進行管理。

當您將網域升級至 2.3 版或更新版本時 (由於 2.x 版的 OpenSearch Service 支援從 2.3 版開始)，您現有的目的地會自動移轉至通知頻道。如果目的地無法移轉，監控將繼續使用它，直到監控移轉到通知頻道為止。如需更多資訊，請參閱《OpenSearch 文件》中[關於目的地的問題](https://opensearch.org/docs/latest/observing-your-data/alerting/monitors/#questions-about-destinations)。

若要開始使用通知，請登入 OpenSearch Dashboards，然後選擇 **Notifications** (通知)、**Channels** (頻道) 和 **Create channel** (建立頻道)。

Amazon Simple Notification Service (Amazon SNS) 是支援的通知頻道類型。為了驗證使用者，您需要為使用者提供對 Amazon SNS 的完整存取權限，或讓他們擔任具有存取 Amazon SNS 許可的 IAM 角色。如需相關指示，請參閱《[Amazon SNS 作為頻道類型](https://opensearch.org/docs/latest/observing-your-data/notifications/index/#amazon-sns-as-a-channel-type)》。

## 差異
<a name="alerting-diff"></a>

Amazon OpenSearch Service 中的提醒與 OpenSearch 的開放原始碼版本相比，有一些顯著差異。

### 提醒設定
<a name="alerting-diff-settings"></a>

使用 OpenSearch Service 可修改下列[提醒設定](https://opensearch.org/docs/latest/observing-your-data/alerting/settings/#alerting-settings)：
+ `plugins.scheduled_jobs.enabled`
+ `plugins.alerting.alert_history_enabled`
+ `plugins.alerting.alert_history_max_age`
+ `plugins.alerting.alert_history_max_docs`
+ `plugins.alerting.alert_history_retention_period`
+ `plugins.alerting.alert_history_rollover_period`
+ `plugins.alerting.filter_by_backend_roles`

所有其他設定都會使用您無法變更的預設值。

若要停用提醒，請傳送下列請求：

```
PUT _cluster/settings
{
  "persistent" : {
    "plugins.scheduled_jobs.enabled" : false
  }
}
```

下列請求會將提醒設定為在七天後自動刪除歷史記錄索引，而不是預設的 30 天：

```
PUT _cluster/settings
{
  "persistent": {
    "plugins.alerting.alert_history_retention_period": "7d"
  }
}
```

如果您先前已建立監視器，並想要停止建立每日提醒索引，請刪除所有提醒歷史記錄索引：

```
DELETE .plugins-alerting-alert-history-*
```

若要減少歷史記錄索引的碎片計數，請建立索引範本。下列請求將提醒的歷史記錄索引設定為一個碎片和一個複本：

```
PUT _index_template/{{template-name}}
{
  "index_patterns": [".opendistro-alerting-alert-history-*"],
  "template": {
    "settings": {
      "number_of_shards": 1,
      "number_of_replicas": 1
    }
  }
}
```

根據您對資料丟失的容忍度，您甚至可以考慮使用零複本。如需建立和管理索引範本的詳細資訊，請參閱 OpenSearch 文件中的[索引範本](https://opensearch.org/docs/latest/opensearch/index-templates/)。