[英]Terraform Google provider, create log-based alerting policy
I need to create a log-based alerting policy via Terraform Google cloud provider: https://cloud.google.com/logging/docs/alerting/monitoring-logs#lba我需要通过 Terraform Google 云提供商创建基于日志的警报策略: https://cloud.google.com/logging/docs/alerting/monitoring-logs#lba
I checked from the Terraform official documentation and i saw 'google_monitoring_alert_policy' resource: https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/monitoring_alert_policy我查看了 Terraform 官方文档,我看到了“google_monitoring_alert_policy”资源: https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/monitoring_alert_policy
I don't found with this doc how creating a log based alerting policy.我没有在本文档中找到如何创建基于日志的警报策略。
I can create an alerting policy with type 'Metrics' but not with type 'Logs'我可以创建类型为“指标”但类型为“日志”的警报策略
I use the latest version of Terraform Google cloud provider:https://registry.terraform.io/providers/hashicorp/google/latest我使用最新版本的 Terraform 谷歌云提供商:https://registry.terraform.io/providers/hashicorp/google/latest
How can i create a log-based alerting policy with Terraform Google provider please?请问如何使用 Terraform Google 提供商创建基于日志的警报策略?
Thanks in advance for your help.在此先感谢您的帮助。
Thanks Guillaume.谢谢纪尧姆。
Yes it's the way i solved the issue.是的,这就是我解决问题的方式。
Now there is no way to directly create alerting with 'log' type, via Terraform.现在无法通过 Terraform 直接创建“日志”类型的警报。
The steps to solve this problem:解决这个问题的步骤:
resource "google_logging_metric" "my_log_metrics" {
project = var.project_id
name = "my-log-metric"
filter = "..."
description = "..."
metric_descriptor {
metric_kind = "..."
value_type = "..."
}
}
resource "google_monitoring_alert_policy" "my_policy" {
project = var.project_id
display_name = "my-policy"
combiner = "OR"
conditions {
display_name = "my-policy"
condition_threshold {
filter = "metric.type=\"logging.googleapis.com/user/my-log-metric\" AND resource.type=\"cloud_composer_environment\""
...
}
}
Problem is solved with version 4.7.0 of google provider, which adds condition_matched_log .谷歌提供商的 4.7.0 版本解决了问题,它添加了condition_matched_log 。 Here is a working example:这是一个工作示例:
resource "google_monitoring_notification_channel" "email-me" {
display_name = "Email Me"
type = "email"
labels = {
email_address = "me@mycompany.com"
}
}
resource "google_monitoring_alert_policy" "workflows" {
display_name = "Workflows alert policy"
combiner = "OR"
conditions {
display_name = "Error condition"
condition_matched_log {
filter = "resource.type=\"workflows.googleapis.com/Workflow\" severity=ERROR"
}
}
notification_channels = [ google_monitoring_notification_channel.email-me.name ]
alert_strategy {
notification_rate_limit {
period = "300s"
}
}
}
The format is logging.googleapis.com/user/<user metrics name>
格式为logging.googleapis.com/user/<user metrics name>
Look at this example (no notification, only the alert policy)看这个例子(没有通知,只有警报政策)
resource "google_monitoring_alert_policy" "alert_policy" {
display_name = "My Alert Policy"
combiner = "OR"
conditions {
display_name = "test condition"
condition_threshold {
filter = "metric.type=\"logging.googleapis.com/user/test-metrics\" AND resource.type=\"cloud_run_revision\""
duration = "600s"
comparison = "COMPARISON_GT"
threshold_value = 1
}
}
user_labels = {
foo = "bar"
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.