Is there a way to mimic a CloudWatch SNS notification when creating an alert so that it will be picked up by the CloudWatch API integration instead of the Default API?
I've tried posting SNSEvent JSON payloads and CloudWatch JSON payloads to both my Alerts API with Geniekey and my alerts https endpoint.
The server returns error 422 Unprocessable Entity.
Creating custom alerts otherwise works fine using the parameters listed in the Alerts API
CloudWatch JSON example:
Hi @Joel Bradley !
What you could do is take that payload that SNS is sending to Opsgenie, and make an API request to your Cloudwatch integration endpoint in Opsgenie
You will want to ensure the payload you are sending in the POST request is in the same format that our Cloudwatch integration is expecting. An example of this payload is shown on our doc here. So you can take that payload, and just make a POST API request to the endpoint provided in your Cloudwatch integration in Opsgenie.
Hope that helps!
Thanks,
Samir
Hi Samir,
Thanks for your reply.
I tried POSTing the sample payload from the link you provided both with and without escaped quotation marks to my Cloudwatch API endpoint. The server still returns error 422. Unfortunately it doesn't say which character tripped the serializer up.
I've had problems with some serializers being unable to handle the nested objects inside a Cloudwatch payload.
Sample Cloudwatch JSON payload with escape sequences:
{ "Type": "Notification", "MessageId": "1cf7a0eb-4179-4181-b15b-ea22c5aa0280", "TopicArn": "arn:aws:sns:us-east-1:08931xxxxxx:CloudWatchHTTPAlarms", "Subject": "ALARM: \"cpuUtilTest\" in US - N. Virginia", "Message": "{\"AlarmName\":\"cpuUtilTest\",\"AlarmDescription\":\"testing alarms for cpu utilization\",\"AWSAccountId\":\"08931xxxxxx\",\"NewStateValue\":\"ALARM\",\"OldStateValue\":\"OK\",\"NewStateReason\":\"Threshold Crossed: 1 datapoint (5.199) was greater than or equal to the threshold (5.0).\",\"StateChangeTime\":\"2012-08-05T22:31:25.524+0000\",\"Region\":\"US - N. Virginia\",\"Trigger\":{\"MetricName\":\"CPUUtilization\",\"Namespace\":\"AWS/EC2\",\"Statistic\":\"AVERAGE\",\"Unit\":null,\"Dimensions\":[{\"name\":\"InstanceId\",\"value\":\"i-39e64c5f\"}],\"Period\":900,\"EvaluationPeriods\":1,\"ComparisonOperator\":\"GreaterThanOrEqualToThreshold\",\"Threshold\":5.0}}", "Timestamp": "2012-08-05T22:31:30.673Z", "SignatureVersion": "1", "Signature": "XrsO2wtE0b+ofOl1ZxxxxxxxxlimTUg+rV4U9RmNSSBEdlmyWvtGgpjebsmNv1wkjUsBQOJZjZnpZp5FBn6quAn3twNdRMmMLf15lv6ESbYFxxxxxxxx0vmjj/ZLwiH9Pr/cxVYxxxxxxxYn8w6g=", "SigningCertURL": "https://sns.us-east-1.amazonaws.com/SimpleNotificationService-f3ecfb7224c72xxxxxxxxx6de52f.pem", "UnsubscribeURL": "https://sns.us-east-1.amazonaws.com/?Action=Unsubscribe&SubscriptionArn=arn:aws:sns:us-east-1:08931xxxxxxxx:CloudWatchHTTPAlarms:1841c5ca-ddda-450e-bbfb-xxxxxxxxx" }
Sample Cloudwatch JSON payload without escape sequences:
{
"Type": "Notification",
"MessageId": "1cf7a0eb-4179-4181-b15b-ea22c5aa0280",
"TopicArn": "arn:aws:sns:us-east-1:08931xxxxxx:CloudWatchHTTPAlarms",
"Subject": "ALARM: "cpuUtilTest" in US - N. Virginia",
"Message": "{"AlarmName":"cpuUtilTest","AlarmDescription":"testing alarms for cpu utilization","AWSAccountId":"08931xxxxxx","NewStateValue":"ALARM","OldStateValue":"OK","NewStateReason":"Threshold Crossed: 1 datapoint (5.199) was greater than or equal to the threshold (5.0).","StateChangeTime":"2012-08-05T22:31:25.524+0000","Region":"US - N. Virginia","Trigger":{"MetricName":"CPUUtilization","Namespace":"AWS/EC2","Statistic":"AVERAGE","Unit":null,"Dimensions":[{"name":"InstanceId","value":"i-39e64c5f"}],"Period":900,"EvaluationPeriods":1,"ComparisonOperator":"GreaterThanOrEqualToThreshold","Threshold":5.0}}",
"Timestamp": "2012-08-05T22:31:30.673Z",
"SignatureVersion": "1",
"Signature": "XrsO2wtE0b+ofOl1ZxxxxxxxxlimTUg+rV4U9RmNSSBEdlmyWvtGgpjebsmNv1wkjUsBQOJZjZnpZp5FBn6quAn3twNdRMmMLf15lv6ESbYFxxxxxxxx0vmjj/ZLwiH9Pr/cxVYxxxxxxxYn8w6g=",
"SigningCertURL": "https://sns.us-east-1.amazonaws.com/SimpleNotificationService-f3ecfb7224c72xxxxxxxxx6de52f.pem",
"UnsubscribeURL": "https://sns.us-east-1.amazonaws.com/?Action=Unsubscribe&SubscriptionArn=arn:aws:sns:us-east-1:08931xxxxxxxx:CloudWatchHTTPAlarms:1841c5ca-ddda-450e-bbfb-xxxxxxxxx"
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Joel Bradley ,
You need to include the following 2 Headers as well...
Content-Type: text/plain; charset=UTF-8
x-amz-sns-message-type: Notification
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Samir,
That's exactly what I was looking for.
Thanks very much!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
There is a even easier solution to this issue. Simply use the "Incoming Amazon SNS" integration. The CloudWatch integration didn't work for us either, it seems like the json payload sent from the SNS topic in AWS is not setup to be received properly on the Opsgenie side. As far as I know, an SNS topic is the only way to send alerts from CloudWatch and therefore the SNS integration is the correct configuration.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.