简体   繁体   English

Terraform Google 提供商,创建基于日志的警报策略

[英]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:解决这个问题的步骤:

  • Create un log based metric with expected filter使用预期过滤器创建基于非日志的指标
  • Create an alerting policy with type 'metric' based on the previous created log based metric根据先前创建的基于日志的指标创建类型为“指标”的警报策略
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.

相关问题 如何在 Terraform 中设置基于 GCP 监控日志的警报? - How to set up a GCP Monitoring log-based alert in Terraform? 使用 terraform 在 GCP 中创建云功能错误警报策略 - Creating a cloud-function error alerting policy in GCP with terraform 使用 Terraform 创建 Azure 策略 - Create Azure policy with Terraform 仅当最后一条消息符合两个条件时才基于 GCP 日志发出警报 - GCP log-based alert only if the last message matches two conditions 在 terraform 上创建参数化资源策略 - Create parameterized resource policy on terraform 让基于日志的指标自动确定来自 JSON 过滤日志有效负载的标签 - Have Log-Based Metric Automatically Determine Labels from JSON Payload of Filtered Logs Google Cloud CloudSQL 实例无法使用 Terraform 提供程序创建,并出现错误“未找到每产品每项目服务帐户” - Google Cloud CloudSQL Instance Fails To Create using Terraform Provider With Error "Per-Product Per-Project Service Account is not found" 是否可以在 Google Cloud 中为丢失的数据创建基于日志的指标? - Is it possible to create log based metrics in Google Cloud for missing data? 失败的 GKE CronJob 的 GCP 警报策略 - GCP Alerting Policy for failed GKE CronJob 谷歌云平台——创建警报策略——如何在警报文档降价中指定消息变量? - google cloud platform -- creating alert policy -- how to specify message variable in alerting documentation markdown?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM