9

我已将pagerdutyAWS cloudwatch集成,我正在尝试手动将消​​息发布到由pagerdutyemail订阅的SNS 主题。但我无法在pagerduty中发生事件。但是,cloudwatch 警报正在使用同一主题触发pagerduty中的事件。

我参考了一些有关pagerduty消息有效负载的文档。但无法使其工作。我的SNS消息 JSON 如下,

{
 "default":"test message",
 "email":"test email message",
 "https":{
    "service_key":"XXXX",
    "event_type":"trigger",
    "description":"Example alert on host1.example.com"
  }
}

它不会触发pagerduty中的事件。我不确定请求正文中缺少什么。我正在从同一邮件正文正确接收电子邮件。有人可以指出错误吗?

提前致谢。

4

5 回答 5

4

为此,您必须为 PagerDuty 集成选择自定义事件转换器选项。在集成中,您可以编写自己的 JavaScript 代码,如下所示:

var normalized_event = {
    event_type: PD.Trigger,
    description: "SNS Event",
    details: PD.inputRequest
};

PD.emitGenericEvents([normalized_event]);

要解析从 SNS 接收到的有效负载,您可以使用:

var rawBody = PD.inputRequest.rawBody;
var obj = JSON.parse(unescape(rawBody));

并根据您的 SNS 消息对待obj来对待您的事件。

于 2019-11-04T14:42:45.937 回答
3

我来不及回答这个问题,但仍然添加 @filipebarretto 建议我们需要使用自定义事件转换器进行这种类型的集成。

设置:~ AWS Cloudwatch (RDS Metric) -> AWS SNS -> PagerDuty (CET)

我已通过自定义事件转换器成功地将 AWS SNS 集成到 PagerDuty

var body = JSON.parse(PD.inputRequest.rawBody)
var message = body.NewStateReason

var normalized_event = {
      event_type: PD.Trigger,
      description: body.AlarmName,
      details: message
    };
PD.emitGenericEvents([normalized_event]);

上面的代码将发送incidentasAlarmNamedetailsas NewStateReason

于 2020-06-04T10:56:38.530 回答
2

我相信 PagerDuty 的原生AWS CloudWatch 集成是固执己见的。因此自定义 SNS 消息不会触发事件。

但是 PagerDuty 有一个入站集成类型,允许您使用 JS (ES5) 创建脚本来解析发送到此集成的任何自定义消息 - 然后可以根据脚本的逻辑触发事件。

关于自定义事件转换器的文档:https ://v2.developer.pagerduty.com/docs/creating-an-integration-inline

于 2019-01-10T14:09:38.710 回答
1

我使用以下示例事件作为 SNS 消息进行了测试,它工作正常。

{
  "version": "0",
  "id": "bba1bcef-5268-9967-8628-9a6d09e042e9",
  "detail-type": "CloudWatch Alarm State Change",
  "source": "aws.cloudwatch",
  "account": "[Account ID]",
  "time": "2020-11-17T06:25:42Z",
  "region": "[region Id]",
  "resources": [
    "arn:aws:cloudwatch:[region Id]:[Account ID]:alarm:CPUUtilize"
  ],
  "detail": {
    "alarmName": "CPUUtilize",
    "state": {
      "value": "ALARM",
      "reason": "Threshold Crossed: 1 out of the last 1 datapoints [4.314689265544354 (17/11/20 06:20:00)] was less than the threshold (70.0) (minimum 1 datapoint for OK -> ALARM transition).",
      "reasonData": {
        "version": "1.0",
        "queryDate": "2020-11-17T06:25:42.491+0000",
        "startDate": "2020-11-17T06:20:00.000+0000",
        "statistic": "Average",
        "period": 300,
        "recentDatapoints": [
          4.314689
        ],
        "threshold": 70
      },
      "timestamp": "2020-11-17T06:25:42.493+0000"
    },
    "previousState": {
      "value": "OK",
      "reason": "Threshold Crossed: 1 out of the last 1 datapoints [4.484088172640544 (17/11/20 05:44:00)] was not greater than or equal to the threshold (70.0) (minimum 1 datapoint for ALARM -> OK transition).",
      "reasonData": {
        "version": "1.0",
        "queryDate": "2020-11-17T05:49:53.688+0000",
        "startDate": "2020-11-17T05:44:00.000+0000",
        "statistic": "Average",
        "period": 300,
        "recentDatapoints": [
          4.484088
        ],
        "threshold": 70
      },
      "timestamp": "2020-11-17T05:49:53.691+0000"
    },
    "configuration": {
      "description": "Alarm Notification in my local timezone",
      "metrics": [
        {
          "id": "16baea70-421b-0a6e-f6f1-bc913d2bf647",
          "metricStat": {
            "metric": {
              "namespace": "AWS/EC2",
              "name": "CPUUtilization",
              "dimensions": {
                "InstanceId": "i-0e448XXXXXXXXXXXX"
              }
            },
            "period": 300,
            "stat": "Average"
          },
          "returnData": true
        }
      ]
    }
  }
}

取自https://aws.amazon.com/blogs/mt/customize-amazon-cloudwatch-alarm-notifications-to-your-local-time-zone-part-1/

于 2021-08-11T10:53:39.837 回答
0

我什至迟到了这里的比赛,但是......

您如何“手动”发送事件?您是否检查过有关 SNS 主题的策略是否允许从您用于发布事件的任何服务发布通知?

我在从 AWS Backup 发布通知/事件时遇到了类似的问题。我不得不在访问策略中添加这样的内容:

{
      "Sid": "My-statement-id",
      "Effect": "Allow",
      "Principal": {
        "Service": "backup.amazonaws.com"
      },
      "Action": "SNS:Publish",
      "Resource": "arn:aws:sns:region:account-id:myTopic"
}
于 2020-07-23T13:51:05.367 回答