|
| 1 | +require "test_helper" |
| 2 | + |
| 3 | +module PagerTree::Integrations |
| 4 | + class AwsCloudwatch::V3Test < ActiveSupport::TestCase |
| 5 | + include Integrateable |
| 6 | + |
| 7 | + setup do |
| 8 | + @integration = pager_tree_integrations_integrations(:aws_cloudwatch_v3) |
| 9 | + |
| 10 | + @create_request = { |
| 11 | + Type: "Notification", |
| 12 | + MessageId: "836fe1ec-79e0-56b8-827f-b66569e37e11", |
| 13 | + TopicArn: "arn:aws:sns:us-east-1:498849832712:update-cherwell-cmdb", |
| 14 | + Message: "{\r\n \"AlarmName\":\"Saffron-Octopus-RDS\",\r\n \"AlarmDescription\":null,\r\n \"AWSAccountId\":\"498849832712\",\r\n \"NewStateValue\":\"ALARM\",\r\n \"NewStateReason\":\"Threshold Crossed: 1 datapoint [2.1533759377604764 (20\/07\/20 21:07:00)] was greater than or equal to the threshold (0.0175).\",\r\n \"StateChangeTime\":\"2020-07-20T21:12:01.544+0000\",\r\n \"Region\":\"US East (N. Virginia)\",\r\n \"AlarmArn\":\"arn:aws:cloudwatch:us-east-1:498849832712:alarm:Saffron-Octopus-RDS\",\r\n \"OldStateValue\":\"INSUFFICIENT_DATA\",\r\n \"Trigger\":{\r\n \"MetricName\":\"CPUUtilization\",\r\n \"Namespace\":\"AWS\/RDS\",\r\n \"StatisticType\":\"Statistic\",\r\n \"Statistic\":\"AVERAGE\",\r\n \"Unit\":null,\r\n \"Dimensions\":[\r\n {\r\n \"value\":\"sm16lm1jrrjf0rk\",\r\n \"name\":\"DBInstanceIdentifier\"\r\n }\r\n ],\r\n \"Period\":300,\r\n \"EvaluationPeriods\":1,\r\n \"ComparisonOperator\":\"GreaterThanOrEqualToThreshold\",\r\n \"Threshold\":0.0175,\r\n \"TreatMissingData\":\"\",\r\n \"EvaluateLowSampleCountPercentile\":\"\"\r\n }\r\n}", |
| 15 | + Timestamp: "2020-07-15T14:08:03.824Z", |
| 16 | + SignatureVersion: "1", |
| 17 | + Signature: "JNdxahPfT0tVsX8+ZVPeA23M09UcCbIQ8uar5AZ4VqscGhzqpMcy4v00mluwr3eyJuFsogxhv1RprFIHU0ZH4bNRWxDpzdVnFIGVSnSBZDVi075ynf+oxagTLhSs7aa9Aar38RcQicaYBc6kHiCg5FHIwwU1OXeehVjHavFKC1ymSegaxtD2pUG4jST30gC2P55I+qyFItPOj+Ih8ZqRBXc3H989mwDKU0Qa54/lQ0cFMC8YwZcQzqwSoZQwIvsrCzLjNR7l2IIEq4pk9d2thq9C/tySFNlXd4/HP/Vd6I9wuP08c0nspmmWxQY1X7CQOvwKway7V9WmKVpku3avxQ==", |
| 18 | + SigningCertURL: "https://sns.us-east-1.amazonaws.com/SimpleNotificationService-a86cb10b4e1f29c941702d737128f7b6.pem", |
| 19 | + UnsubscribeURL: "https://sns.us-east-1.amazonaws.com/?Action=Unsubscribe&SubscriptionArn=arn:aws:sns:us-east-1:498849832712:update-cherwell-cmdb:e0cff011-7a6a-4425-9c0c-e812474debe5" |
| 20 | + }.with_indifferent_access |
| 21 | + |
| 22 | + @resolve_request = { |
| 23 | + Type: "Notification", |
| 24 | + MessageId: "836fe1ec-79e0-56b8-827f-b66569e37e11", |
| 25 | + TopicArn: "arn:aws:sns:us-east-1:498849832712:update-cherwell-cmdb", |
| 26 | + Message: "{\r\n \"AlarmName\":\"Saffron-Octopus-RDS\",\r\n \"AlarmDescription\":null,\r\n \"AWSAccountId\":\"498849832712\",\r\n \"NewStateValue\":\"OK\",\r\n \"NewStateReason\":\"Threshold Crossed: 1 datapoint [2.1533759377604764 (20\/07\/20 21:07:00)] was greater than or equal to the threshold (0.0175).\",\r\n \"StateChangeTime\":\"2020-07-20T21:12:01.544+0000\",\r\n \"Region\":\"US East (N. Virginia)\",\r\n \"AlarmArn\":\"arn:aws:cloudwatch:us-east-1:498849832712:alarm:Saffron-Octopus-RDS\",\r\n \"OldStateValue\":\"INSUFFICIENT_DATA\",\r\n \"Trigger\":{\r\n \"MetricName\":\"CPUUtilization\",\r\n \"Namespace\":\"AWS\/RDS\",\r\n \"StatisticType\":\"Statistic\",\r\n \"Statistic\":\"AVERAGE\",\r\n \"Unit\":null,\r\n \"Dimensions\":[\r\n {\r\n \"value\":\"sm16lm1jrrjf0rk\",\r\n \"name\":\"DBInstanceIdentifier\"\r\n }\r\n ],\r\n \"Period\":300,\r\n \"EvaluationPeriods\":1,\r\n \"ComparisonOperator\":\"GreaterThanOrEqualToThreshold\",\r\n \"Threshold\":0.0175,\r\n \"TreatMissingData\":\"\",\r\n \"EvaluateLowSampleCountPercentile\":\"\"\r\n }\r\n}", |
| 27 | + Timestamp: "2020-07-15T14:08:03.824Z", |
| 28 | + SignatureVersion: "1", |
| 29 | + Signature: "JNdxahPfT0tVsX8+ZVPeA23M09UcCbIQ8uar5AZ4VqscGhzqpMcy4v00mluwr3eyJuFsogxhv1RprFIHU0ZH4bNRWxDpzdVnFIGVSnSBZDVi075ynf+oxagTLhSs7aa9Aar38RcQicaYBc6kHiCg5FHIwwU1OXeehVjHavFKC1ymSegaxtD2pUG4jST30gC2P55I+qyFItPOj+Ih8ZqRBXc3H989mwDKU0Qa54/lQ0cFMC8YwZcQzqwSoZQwIvsrCzLjNR7l2IIEq4pk9d2thq9C/tySFNlXd4/HP/Vd6I9wuP08c0nspmmWxQY1X7CQOvwKway7V9WmKVpku3avxQ==", |
| 30 | + SigningCertURL: "https://sns.us-east-1.amazonaws.com/SimpleNotificationService-a86cb10b4e1f29c941702d737128f7b6.pem", |
| 31 | + UnsubscribeURL: "https://sns.us-east-1.amazonaws.com/?Action=Unsubscribe&SubscriptionArn=arn:aws:sns:us-east-1:498849832712:update-cherwell-cmdb:e0cff011-7a6a-4425-9c0c-e812474debe5" |
| 32 | + }.with_indifferent_access |
| 33 | + |
| 34 | + @other_request = { |
| 35 | + Type: "Notification", |
| 36 | + MessageId: "836fe1ec-79e0-56b8-827f-b66569e37e11", |
| 37 | + TopicArn: "arn:aws:sns:us-east-1:498849832712:update-cherwell-cmdb", |
| 38 | + Message: "{\r\n \"AlarmName\":\"Saffron-Octopus-RDS\",\r\n \"AlarmDescription\":null,\r\n \"AWSAccountId\":\"498849832712\",\r\n \"NewStateValue\":\"UNKNOW\",\r\n \"NewStateReason\":\"Threshold Crossed: 1 datapoint [2.1533759377604764 (20\/07\/20 21:07:00)] was greater than or equal to the threshold (0.0175).\",\r\n \"StateChangeTime\":\"2020-07-20T21:12:01.544+0000\",\r\n \"Region\":\"US East (N. Virginia)\",\r\n \"AlarmArn\":\"arn:aws:cloudwatch:us-east-1:498849832712:alarm:Saffron-Octopus-RDS\",\r\n \"OldStateValue\":\"INSUFFICIENT_DATA\",\r\n \"Trigger\":{\r\n \"MetricName\":\"CPUUtilization\",\r\n \"Namespace\":\"AWS\/RDS\",\r\n \"StatisticType\":\"Statistic\",\r\n \"Statistic\":\"AVERAGE\",\r\n \"Unit\":null,\r\n \"Dimensions\":[\r\n {\r\n \"value\":\"sm16lm1jrrjf0rk\",\r\n \"name\":\"DBInstanceIdentifier\"\r\n }\r\n ],\r\n \"Period\":300,\r\n \"EvaluationPeriods\":1,\r\n \"ComparisonOperator\":\"GreaterThanOrEqualToThreshold\",\r\n \"Threshold\":0.0175,\r\n \"TreatMissingData\":\"\",\r\n \"EvaluateLowSampleCountPercentile\":\"\"\r\n }\r\n}", |
| 39 | + Timestamp: "2020-07-15T14:08:03.824Z", |
| 40 | + SignatureVersion: "1", |
| 41 | + Signature: "JNdxahPfT0tVsX8+ZVPeA23M09UcCbIQ8uar5AZ4VqscGhzqpMcy4v00mluwr3eyJuFsogxhv1RprFIHU0ZH4bNRWxDpzdVnFIGVSnSBZDVi075ynf+oxagTLhSs7aa9Aar38RcQicaYBc6kHiCg5FHIwwU1OXeehVjHavFKC1ymSegaxtD2pUG4jST30gC2P55I+qyFItPOj+Ih8ZqRBXc3H989mwDKU0Qa54/lQ0cFMC8YwZcQzqwSoZQwIvsrCzLjNR7l2IIEq4pk9d2thq9C/tySFNlXd4/HP/Vd6I9wuP08c0nspmmWxQY1X7CQOvwKway7V9WmKVpku3avxQ==", |
| 42 | + SigningCertURL: "https://sns.us-east-1.amazonaws.com/SimpleNotificationService-a86cb10b4e1f29c941702d737128f7b6.pem", |
| 43 | + UnsubscribeURL: "https://sns.us-east-1.amazonaws.com/?Action=Unsubscribe&SubscriptionArn=arn:aws:sns:us-east-1:498849832712:update-cherwell-cmdb:e0cff011-7a6a-4425-9c0c-e812474debe5" |
| 44 | + }.with_indifferent_access |
| 45 | + end |
| 46 | + |
| 47 | + test "sanity" do |
| 48 | + assert @integration.adapter_supports_incoming? |
| 49 | + assert @integration.adapter_incoming_can_defer? |
| 50 | + assert_not @integration.adapter_supports_outgoing? |
| 51 | + assert @integration.adapter_show_alerts? |
| 52 | + assert @integration.adapter_show_logs? |
| 53 | + assert_not @integration.adapter_show_outgoing_webhook_delivery? |
| 54 | + end |
| 55 | + |
| 56 | + test "adapter_actions create" do |
| 57 | + @integration.adapter_incoming_request_params = @create_request |
| 58 | + assert_equal :create, @integration.adapter_action |
| 59 | + end |
| 60 | + |
| 61 | + test "adapter_actions resolve" do |
| 62 | + @integration.adapter_incoming_request_params = @resolve_request |
| 63 | + assert_equal :resolve, @integration.adapter_action |
| 64 | + end |
| 65 | + |
| 66 | + test "adapter_actions other" do |
| 67 | + @integration.adapter_incoming_request_params = @other_request |
| 68 | + assert_equal :other, @integration.adapter_action |
| 69 | + end |
| 70 | + |
| 71 | + test "adapter_thirdparty_id" do |
| 72 | + @integration.adapter_incoming_request_params = @create_request |
| 73 | + assert_equal "arn:aws:sns:us-east-1:498849832712:update-cherwell-cmdb:Saffron-Octopus-RDS", @integration.adapter_thirdparty_id |
| 74 | + end |
| 75 | + |
| 76 | + test "adapter_process_create" do |
| 77 | + @integration.adapter_incoming_request_params = @create_request |
| 78 | + |
| 79 | + true_alert = Alert.new( |
| 80 | + title: "Saffron-Octopus-RDS", |
| 81 | + description: "Threshold Crossed: 1 datapoint [2.1533759377604764 (20/07/20 21:07:00)] was greater than or equal to the threshold (0.0175).", |
| 82 | + urgency: nil, |
| 83 | + thirdparty_id: "arn:aws:sns:us-east-1:498849832712:update-cherwell-cmdb:Saffron-Octopus-RDS", |
| 84 | + dedup_keys: ["arn:aws:sns:us-east-1:498849832712:update-cherwell-cmdb:Saffron-Octopus-RDS"], |
| 85 | + additional_data: [ |
| 86 | + AdditionalDatum.new(format: "text", label: "AWS Account ID", value: "498849832712"), |
| 87 | + AdditionalDatum.new(format: "text", label: "Region", value: "US East (N. Virginia)"), |
| 88 | + AdditionalDatum.new(format: "text", label: "Alarm ARN", value: "arn:aws:cloudwatch:us-east-1:498849832712:alarm:Saffron-Octopus-RDS"), |
| 89 | + AdditionalDatum.new(format: "datetime", label: "State Change Time", value: "2020-07-20T21:12:01.544+0000") |
| 90 | + ] |
| 91 | + ) |
| 92 | + |
| 93 | + assert_equal true_alert.to_json, @integration.adapter_process_create.to_json |
| 94 | + end |
| 95 | + end |
| 96 | +end |
0 commit comments