本文提供快訊政策範例,說明如何自訂快訊通知的內容。
事前準備
熟悉如何為 Personalized Service Health 設定快訊。
如要瞭解可在快訊通知和條件中設定的欄位,請參閱「Service Health 記錄檔結構定義參考資料」。
快訊觸發條件範例
下列各節提供詳細的快訊條件範例,可用於 Cloud Logging 或 Terraform。
針對特定 Google Cloud 產品的新事件發出快訊
將 ALERT_CONDITION
設為下列值:
labels."servicehealth.googleapis.com/new_event"=true AND jsonPayload.detailedCategory = \"CONFIRMED_INCIDENT\" AND jsonPayload.impactedProductIds =~ \"hV87iK5DcEXKgWU2kDri\" AND jsonPayload.@type = \"type.googleapis.com/google.cloud.servicehealth.logging.v1.EventLog\"
產品名稱採用常見的 Google Cloud 格式。如需格式範例,請參閱 Google Cloud 服務健康狀態。
特定區域發生新事件時收到快訊
將 ALERT_CONDITION
設為下列值:
labels."servicehealth.googleapis.com/new_event"=true AND jsonPayload.detailedCategory = \"CONFIRMED_INCIDENT\" AND jsonPayload.impactedLocations =~ \"us-central1\" AND jsonPayload.@type = \"type.googleapis.com/google.cloud.servicehealth.logging.v1.EventLog\"
地點名稱採用常見的 Google Cloud 格式。如需格式範例,請參閱 Google Cloud 服務健康狀態。
針對特定產品的新興事件發出快訊
將 ALERT_CONDITION
設為下列值:
labels."servicehealth.googleapis.com/new_event"=true AND jsonPayload.detailedCategory = \"EMERGING_INCIDENT\" AND jsonPayload.impactedProductIds =~ \"ix7u9beT8ivBdjApTif3\" AND jsonPayload.@type = \"type.googleapis.com/google.cloud.servicehealth.logging.v1.EventLog\"
針對事件的任何更新或變更發出快訊
將 ALERT_CONDITION
設為下列值:
jsonPayload.detailedCategory = \"CONFIRMED_INCIDENT\" AND jsonPayload.@type = \"type.googleapis.com/google.cloud.servicehealth.logging.v1.EventLog\"
在確認的事件有任何更新時發出快訊
將 ALERT_CONDITION
設為下列值:
jsonPayload.state =~ \"ACTIVE\" AND jsonPayload.detailedCategory = \"CONFIRMED_INCIDENT\" AND jsonPayload.detailedState != \"EMERGING\" AND jsonPayload.@type = \"type.googleapis.com/google.cloud.servicehealth.logging.v1.EventLog\"
狀態或相關性更新的快訊
將 ALERT_CONDITION
設為下列值:
jsonPayload.detailedCategory = \"CONFIRMED_INCIDENT\" AND "labels.servicehealth.googleapis.com/updated_fields" =~ \"'state'\" OR labels."servicehealth.googleapis.com/updated_fields" =~ \"'relevance'\" AND jsonPayload.@type = \"type.googleapis.com/google.cloud.servicehealth.logging.v1.EventLog\"
顯示完整事件詳細資料的快訊通知
以下快訊通知提供事件的完整詳細資料。
{
"displayName": "ALERT_NAME",
"combiner": "OR",
"conditions": [ {
"displayName": "Log match condition",
"conditionMatchedLog": {
"filter": "ALERT_CONDITION",
"labelExtractors": {
"description": "EXTRACT(jsonPayload.description)",
"impactedLocations": "EXTRACT(jsonPayload.impactedLocations)",
"impactedProducts": "EXTRACT(jsonPayload.impactedProducts)",
"startTime": "EXTRACT(jsonPayload.startTime)",
"state": "EXTRACT(jsonPayload.state)"
"detailedState": "EXTRACT(jsonPayload.detailedState)"
} } } ],
"documentation": {
"content": "# View details at [Service Health dashboard](https://console.cloud.google.com/servicehealth/incidentDetails/projects%2F${resource.labels.resource_container}%2Flocations%2F${resource.labels.location}%2Fevents%2F${resource.labels.event_id}?project=${resource.labels.resource_container}) \n## Description \n${log.extracted_label.description} \n## Impacted locations \n${log.extracted_label.impactedLocations} \n## Impacted products \n${log.extracted_label.impactedProducts} \n## Incident start time \n${log.extracted_label.startTime} \n## Event state \n${log.extracted_label.state} \n## Event detailed state \n ${log.extracted_label.detailedState}",
"mimeType": "text/markdown"
},
"notificationChannels": [ "NOTIFICATION_CHANNEL" ],
"enabled": true,
"alertStrategy": { "notificationRateLimit": { "period": "300s" }, "autoClose": "1800s" }
}
範例中的 labelExtractors
和 content
欄位包含事件的所有可用資訊。
快訊通知,內含 Service Health 資訊主頁的連結
以下範例提供服務健康狀態資訊主頁的連結。
{
"displayName": "ALERT_NAME",
"combiner": "OR",
"conditions": [ {
"displayName": "Log match condition",
"conditionMatchedLog": {
"filter": "ALERT_CONDITION",
"labelExtractors": {
"description": "EXTRACT(jsonPayload.description)",
"impactedLocations": "EXTRACT(jsonPayload.impactedLocations)",
"impactedProducts": "EXTRACT(jsonPayload.impactedProducts)",
"startTime": "EXTRACT(jsonPayload.startTime)",
"state": "EXTRACT(jsonPayload.state)",
"detailedState": "EXTRACT(jsonPayload.detailedState)"
} } } ],
"documentation": {
"content": "# View details at [Service Health dashboard](https://console.cloud.google.com/servicehealth/eventDetails/projects%2F${resource.labels.resource_container}%2Flocations%2F${resource.labels.location}%2Fevents%2F${resource.labels.event_id})",
"mimeType": "text/markdown"
},
"notificationChannels": [ "NOTIFICATION_CHANNEL" ],
"enabled": true,
"alertStrategy": { "notificationRateLimit": { "period": "300s" }, "autoClose": "1800s" }
}