【问题标题】:Best way to create PagerDuty alarm based on Cloudwatch Rule基于 Cloudwatch 规则创建 PagerDuty 警报的最佳方法
【发布时间】:2019-06-24 05:36:54
【问题描述】:

PagerDuty (PD) 与 Cloudwatch (CW) 集成,每当触发 CW 警报时,我都会使用它来进行寻呼:https://support.pagerduty.com/docs/aws-cloudwatch-integration-guide

如果触发了 CW 规则,我希望被寻呼。看起来我可以使用 PD 全局事件路由,然后配置 CW 输入以发送 PD 全局事件端点期望的响应。但我喜欢 CW 警报如何发布到 SNS 主题,我所要做的就是将 SNS 主题消息转发给 PD,所以如果 CW 规则有类似的东西会很好。

【问题讨论】:

    标签: terraform amazon-cloudwatch pagerduty


    【解决方案1】:

    事实证明,我可以使用 TriggeredRules 指标从规则创建 CW 警报。然后我可以使用现有的 PagerDuty CW 集成。这是我写的 terraform 代码:​​

    data "template_file" "ecs_task_stopped" {
      template = <<EOF
    {
      "source": ["aws.ecs"],
      "detail-type": ["ECS Task State Change"],
      "detail": {
        "clusterArn": ["arn:aws:ecs:$${aws_region}:$${account_id}:cluster/$${cluster}"],
        "desiredStatus": ["Running"],
        "lastStatus": ["STOPPED"]
      }
    }
    EOF
    
      vars {
        account_id = "${data.aws_caller_identity.current.account_id}"
        cluster    = "${var.ecs_cluster_name}"
        aws_region = "${data.aws_region.current.name}"
      }
    }
    
    resource "aws_cloudwatch_event_rule" "ecs_task_stopped" {
      count         = "${var.should_create == "true" ? 1 : 0}"
      name          = "${var.env}_${var.ecs_cluster_name}_task_stopped"
      description   = "${var.env}_${var.ecs_cluster_name} Essential container in task exited"
      event_pattern = "${data.template_file.ecs_task_stopped.rendered}"
    }
    
    resource "aws_cloudwatch_metric_alarm" "alarm_task_stopped_rule_triggered" {
      count               = "${var.should_create == "true" ? 1 : 0}"
      alarm_name          = "${var.ecs_cluster_name}-task-stopped"
      comparison_operator = "GreaterThanOrEqualToThreshold"
      evaluation_periods  = "1"
      datapoints_to_alarm = "1"
      metric_name         = "TriggeredRules"
      namespace           = "AWS/Events"
      period              = "60"
      statistic           = "Maximum"
      threshold           = "1"
      alarm_description   = "Essential container in ${var.ecs_cluster_name} task exited"
      alarm_actions       = ["${var.cw_sns_topic_id}"]
      ok_actions          = ["${var.cw_sns_topic_id}"]
    
      dimensions {
        RuleName = "${aws_cloudwatch_event_rule.ecs_task_stopped.name}"
      }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-08-27
      • 1970-01-01
      • 1970-01-01
      • 2021-08-07
      • 1970-01-01
      • 2022-01-01
      • 2020-06-10
      • 2020-09-13
      相关资源
      最近更新 更多