<commit_before>module AmazonSnsToSlack
  module Middleware
    class CloudWatch
      def call(json)
        begin
          message = JSON.parse(json["Message"])

          return nil unless message["AlarmName"]

          payload = {
            "username" => "Amazon CloudWatch",
            "attachments" => [
              {
                "fallback" => json["Message"],
                "text" => json["Subject"] || "CloudWatch Notification",
                "fields" => [
                  {
                    "title" => "Alarm",
                    "value" => message["AlarmName"],
                    "short" => true
                  },
                  {
                    "title" => "Status",
                    "value" => message["NewStateValue"],
                    "short" => true
                  },
                  {
                    "title" => "Reason",
                    "value" => message["NewStateReason"],
                    "short" => false
                  }
                ]
              }
            ]
          }

          case message["NewStateValue"]
          when "OK"
            payload["attachments"]["color"] = "#7CD197"
          when "ALARM"
            payload["attachments"]["color"] = "#FF0000"
            payload["attachments"]["text"] = "@channel " + payload["attachments"]["text"]
          end

          payload
        rescue
          nil
        end
      end
    end
  end
end
<commit_msg>Fix payload<commit_after>module AmazonSnsToSlack
  module Middleware
    class CloudWatch
      def call(json)
        begin
          message = JSON.parse(json["Message"])

          return nil unless message["AlarmName"]

          payload = {
            "username" => "Amazon CloudWatch",
            "attachments" => [
              {
                "fallback" => json["Message"],
                "text" => message["NewStateReason"],
                "fields" => [
                  {
                    "title" => "Alarm",
                    "value" => message["AlarmName"],
                    "short" => true
                  },
                  {
                    "title" => "Status",
                    "value" => message["NewStateValue"],
                    "short" => true
                  }
                ]
              }
            ]
          }

          case message["NewStateValue"]
          when "OK"
            payload["attachments"]["color"] = "#7CD197"
          when "ALARM"
            payload["attachments"]["color"] = "#FF0000"
          end

          payload
        rescue
          nil
        end
      end
    end
  end
end

{'fraction_non_alphanumeric': 0.12158054711246201, 'fraction_numerical': 0.0060790273556231, 'mean_word_length': 1.0410852713178294, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 28, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2232210', 'n_tokens_mistral': 663, 'n_tokens_neox': 622, 'n_words': 124}