---
policy: /ce/ca/aws/cloudwatch/metric-alarm-without-actions
logic: /ce/ca/aws/cloudwatch/metric-alarm-without-actions/prod.logic.yaml
executionTime: 2025-10-08T17:39:06.832548645Z
generationMs: 63
executionMs: 706
rows:
  - id: test1
    match: true
    status:
      expected: DISAPPEARED
      actual: DISAPPEARED
    conditionIndex:
      expected: 99
      actual: 99
    conditionText:
      expected: isDisappeared(CA10__disappearanceTime__c)
      actual: isDisappeared(CA10__disappearanceTime__c)
    runtimeError: {}
  - id: test2
    match: true
    status:
      expected: INCOMPLIANT
      actual: INCOMPLIANT
    conditionIndex:
      expected: 199
      actual: 199
    conditionText:
      expected: not(extract('CA10__actionsEnabled__c'))
      actual: not(extract('CA10__actionsEnabled__c'))
    runtimeError: {}
  - id: test3
    match: true
    status:
      expected: INCOMPLIANT
      actual: INCOMPLIANT
    conditionIndex:
      expected: 299
      actual: 299
    conditionText:
      expected: extract('CA10__alarmActions__c').isEmpty() && extract('CA10__insufficientDataActions__c').isEmpty()
        && extract('CA10__okActions__c').isEmpty()
      actual: extract('CA10__alarmActions__c').isEmpty() && extract('CA10__insufficientDataActions__c').isEmpty()
        && extract('CA10__okActions__c').isEmpty()
    runtimeError: {}
  - id: test4
    match: true
    status:
      expected: COMPLIANT
      actual: COMPLIANT
    conditionIndex:
      expected: 300
      actual: 300
    conditionText:
      expected: otherwise
      actual: otherwise
    runtimeError: {}
usedFiles:
  - path: /ce/ca/aws/cloudwatch/metric-alarm-without-actions/policy.yaml
    md5Hash: 49FAF65A9CD918CB97C1E0D193BEEEC1
    content: "---\nnames:\n  full: \"AWS CloudWatch Metric Alarm does not have any\
      \ actions configured\"\n  contextual: \"Metric Alarm does not have any actions\
      \ configured\"\ndescription: \"Ensure that Amazon CloudWatch alarms are configured\
      \ with at least\\\n  \\ one action for the ALARM, INSUFFICIENT_DATA, or OK states.\
      \ Actions are essential\\\n  \\ for notifying personnel or triggering automated\
      \ responses when an alarm changes\\\n  \\ state, ensuring that operational or\
      \ security events are not missed.\"\ntype: \"COMPLIANCE_POLICY\"\ncategories:\n\
      \  - \"RELIABILITY\"\n  - \"SECURITY\"\nframeworkMappings:\n  - \"/frameworks/cloudaware/logging-and-monitoring/alerting-and-notification\"\
      \n  - \"/frameworks/aws-well-architected/operational-excellence/prepare/ops04/bp05\"\
      \n  - \"/frameworks/nist-sp-800-53-r5/au/06/01\"\n  - \"/frameworks/nist-sp-800-53-r5/au/06/05\"\
      \n  - \"/frameworks/nist-sp-800-53-r5/ca/07\"  \n  - \"/frameworks/nist-sp-800-53-r5/si/04/12\"\
      \  \n  - \"/frameworks/nist-sp-800-53-r5/si/02\"\nsimilarPolicies:\n  awsSecurityHub:\n\
      \    - name: \"[CloudWatch.17] CloudWatch alarm actions should be activated\"\
      \n      url: \"https://docs.aws.amazon.com/securityhub/latest/userguide/cloudwatch-controls.html#cloudwatch-17\""
  - path: /ce/ca/aws/cloudwatch/metric-alarm-without-actions/prod.logic.yaml
    md5Hash: 5F5C5F84269BB31151422BB7B5444A6A
    content: |-
      ---
      inputType: "CA10__CaAwsCloudWatchMetricAlarm__c"
      testData:
        - file: "test-data.json"
      importExtracts:
        - file: "/types/CA10__CaAwsCloudWatchMetricAlarm__c/object.extracts.yaml"
      conditions:
        - status: "INCOMPLIANT"
          currentStateMessage: "The CloudWatch alarm actions are disabled."
          remediationMessage: "Consider enabling the alarm actions if the alarm is still required."
          check:
            NOT:
              arg:
                EXTRACT: "CA10__actionsEnabled__c" # actionsEnabled != true
        - status: "INCOMPLIANT"
          currentStateMessage: "The CloudWatch alarm does not have any actions configured\
            \ for the ALARM, INSUFFICIENT_DATA, or OK states."
          remediationMessage: "Configure at least one action for the ALARM, INSUFFICIENT_DATA,\
            \ or OK state to ensure notifications or automated responses are triggered\
            \ when the alarm changes state."
          check:
            AND:
              args:
                - IS_EMPTY:
                    arg:
                      EXTRACT: "CA10__alarmActions__c"
                - IS_EMPTY:
                    arg:
                      EXTRACT: "CA10__insufficientDataActions__c"
                - IS_EMPTY:
                    arg:
                      EXTRACT: "CA10__okActions__c"
      otherwise:
        status: "COMPLIANT"
        currentStateMessage: "The CloudWatch alarm has at least one action configured."
  - path: /ce/ca/aws/cloudwatch/metric-alarm-without-actions/test-data.json
    md5Hash: 0C17AE7232E0AB7ED9391E156FFF6C47
    content: |-
      [
          {
              "expectedResult": {
                  "status": "DISAPPEARED",
                  "conditionIndex": "99",
                  "conditionText": "isDisappeared(CA10__disappearanceTime__c)",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2025-10-08T06:14:51Z"
              },
              "CA10__disappearanceTime__c": "2025-10-03T17:45:53Z",
              "CA10__actionsEnabled__c": true,
              "CA10__alarmActions__c": "alarmActions",
              "CA10__insufficientDataActions__c": "",
              "CA10__okActions__c": "",
              "Id": "test1"
          },
          {
              "expectedResult": {
                  "status": "INCOMPLIANT",
                  "conditionIndex": "199",
                  "conditionText": "not(extract('CA10__actionsEnabled__c'))",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2025-10-08T06:14:51Z"
              },
              "CA10__disappearanceTime__c": null,
              "CA10__actionsEnabled__c": false,
              "CA10__alarmActions__c": "",
              "CA10__insufficientDataActions__c": "insufficientDataActions",
              "CA10__okActions__c": "okActions",
              "Id": "test2"
          },
          {
              "expectedResult": {
                  "status": "INCOMPLIANT",
                  "conditionIndex": "299",
                  "conditionText": "extract('CA10__alarmActions__c').isEmpty() && extract('CA10__insufficientDataActions__c').isEmpty() && extract('CA10__okActions__c').isEmpty()",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2025-10-08T06:14:51Z"
              },
              "CA10__disappearanceTime__c": null,
              "CA10__actionsEnabled__c": true,
              "CA10__alarmActions__c": "",
              "CA10__insufficientDataActions__c": "",
              "CA10__okActions__c": "",
              "Id": "test3"
          },
          {
              "expectedResult": {
                  "status": "COMPLIANT",
                  "conditionIndex": "300",
                  "conditionText": "otherwise",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2025-10-08T06:14:51Z"
              },
              "CA10__disappearanceTime__c": null,
              "CA10__actionsEnabled__c": true,
              "CA10__alarmActions__c": "alarmActions",
              "CA10__insufficientDataActions__c": "",
              "CA10__okActions__c": "",
              "Id": "test4"
          }
      ]
  - path: /types/CA10__CaAwsCloudWatchMetricAlarm__c/object.extracts.yaml
    md5Hash: 1CA53D6631ECBBFFDE69117572DA2544
    content: "---\nextracts:\n# Checkbox. Can't have no access, retrieved via cloudwatch:DescribeAlarms\n\
      \  - name: \"CA10__actionsEnabled__c\"\n    value: \n      FIELD:\n        path:\
      \ \"CA10__actionsEnabled__c\"\n# Nullable. Can't have no access, retrieved via\
      \ cloudwatch:DescribeAlarms\n  - name: \"CA10__alarmActions__c\"\n    value:\
      \ \n      FIELD:\n        path: \"CA10__alarmActions__c\"\n# Nullable. Can't\
      \ have no access, retrieved via cloudwatch:DescribeAlarms\n  - name: \"CA10__insufficientDataActions__c\"\
      \n    value: \n      FIELD:\n        path: \"CA10__insufficientDataActions__c\"\
      \n# Nullable. Can't have no access, retrieved via cloudwatch:DescribeAlarms\n\
      \  - name: \"CA10__okActions__c\"\n    value: \n      FIELD:\n        path:\
      \ \"CA10__okActions__c\"\n"
script: |-
  CREATE TEMP FUNCTION mock_ExpectedResult()
  RETURNS ARRAY<STRUCT<
          Id STRING,
          expectedResult STRUCT<status STRING, conditionIndex DECIMAL, conditionText STRING, runtimeError STRING>
      >>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
    return [ {
    "Id" : "test1",
    "expectedResult" : {
      "status" : "DISAPPEARED",
      "conditionIndex" : "99",
      "conditionText" : "isDisappeared(CA10__disappearanceTime__c)",
      "runtimeError" : null
    }
  }, {
    "Id" : "test2",
    "expectedResult" : {
      "status" : "INCOMPLIANT",
      "conditionIndex" : "199",
      "conditionText" : "not(extract('CA10__actionsEnabled__c'))",
      "runtimeError" : null
    }
  }, {
    "Id" : "test3",
    "expectedResult" : {
      "status" : "INCOMPLIANT",
      "conditionIndex" : "299",
      "conditionText" : "extract('CA10__alarmActions__c').isEmpty() && extract('CA10__insufficientDataActions__c').isEmpty() && extract('CA10__okActions__c').isEmpty()",
      "runtimeError" : null
    }
  }, {
    "Id" : "test4",
    "expectedResult" : {
      "status" : "COMPLIANT",
      "conditionIndex" : "300",
      "conditionText" : "otherwise",
      "runtimeError" : null
    }
  } ];
  """;

  CREATE TEMP FUNCTION mock_CA10__CaAwsCloudWatchMetricAlarm__c()
  RETURNS ARRAY<STRUCT<
      CA10__disappearanceTime__c TIMESTAMP,
      CA10__actionsEnabled__c BOOLEAN,
      CA10__alarmActions__c STRING,
      CA10__insufficientDataActions__c STRING,
      CA10__okActions__c STRING,
      Id STRING,
      context STRUCT<
          snapshotTime TIMESTAMP
      >
  >>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
    return [ {
    "context" : {
      "snapshotTime" : new Date("2025-10-08T06:14:51Z")
    },
    "CA10__disappearanceTime__c" : new Date("2025-10-03T17:45:53Z"),
    "CA10__actionsEnabled__c" : true,
    "CA10__alarmActions__c" : "alarmActions",
    "CA10__insufficientDataActions__c" : "",
    "CA10__okActions__c" : "",
    "Id" : "test1"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-10-08T06:14:51Z")
    },
    "CA10__actionsEnabled__c" : false,
    "CA10__alarmActions__c" : "",
    "CA10__insufficientDataActions__c" : "insufficientDataActions",
    "CA10__okActions__c" : "okActions",
    "Id" : "test2"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-10-08T06:14:51Z")
    },
    "CA10__actionsEnabled__c" : true,
    "CA10__alarmActions__c" : "",
    "CA10__insufficientDataActions__c" : "",
    "CA10__okActions__c" : "",
    "Id" : "test3"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-10-08T06:14:51Z")
    },
    "CA10__actionsEnabled__c" : true,
    "CA10__alarmActions__c" : "alarmActions",
    "CA10__insufficientDataActions__c" : "",
    "CA10__okActions__c" : "",
    "Id" : "test4"
  } ];
  """;

  CREATE TEMP FUNCTION process_CA10__CaAwsCloudWatchMetricAlarm__c(
      obj STRUCT<
          CA10__disappearanceTime__c TIMESTAMP,
          CA10__actionsEnabled__c BOOLEAN,
          CA10__alarmActions__c STRING,
          CA10__insufficientDataActions__c STRING,
          CA10__okActions__c STRING,
          Id STRING
      >,
      snapshotTime TIMESTAMP
  )
  RETURNS STRUCT<status STRING, conditionIndex DECIMAL, conditionText STRING, currentStateMessage STRING, currentStateReferences STRING, remediation STRING, runtimeError STRING>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
  var TextLib = new function () {
      this.normalize = function(arg) {
          return arg == null ? '' : arg.replace(/\s+/g, ' ').trim().toLowerCase();
      };
      this.isEmpty = function(arg) {
          return this.normalize(arg) == '';
      };
      this.isNotEmpty = function(arg) {
          return this.normalize(arg) != '';
      };
      this.equal = function(left, right) {
          return this.normalize(left) == this.normalize(right);
      };
      this.notEqual = function(left, right) {
          return this.normalize(left) != this.normalize(right);
      };
      this.startsWith = function(arg, substring) {
          return this.normalize(arg).startsWith(this.normalize(substring));
      };
      this.endsWith = function(arg, substring) {
          return this.normalize(arg).endsWith(this.normalize(substring));
      };
      this.contains = function(arg, substring) {
          return this.normalize(arg).includes(this.normalize(substring));
      };
      this.containsAll = function(arg, substrings) {
          if (substrings == null || substrings.length === 0) return false;
          let normalizedArg = this.normalize(arg);
          return substrings.every(sub => normalizedArg.includes(this.normalize(sub)));
      };
      this.containsAny = function(arg, substrings) {
          if (substrings == null || substrings.length === 0) return false;
          let normalizedArg = this.normalize(arg);
          return substrings.some(sub => normalizedArg.includes(this.normalize(sub)));
      };
  }();
      var references1 = [];
      // condition[0], conditionIndex:[0..99]
      references1.push('Deleted From AWS [CA10__disappearanceTime__c]: ' + obj.CA10__disappearanceTime__c);
      if (obj.CA10__disappearanceTime__c != null) {
          return {status: 'DISAPPEARED', conditionIndex: 99, conditionText: "isDisappeared(CA10__disappearanceTime__c)", currentStateMessage: "Object is deleted in the source", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
      }
      // condition[1], conditionIndex:[100..199]
      function extract3() { if (!this.out) { this.out = obj.CA10__actionsEnabled__c; } return this.out; };
      references1.push('Actions Enabled [obj.CA10__actionsEnabled__c]: ' + obj.CA10__actionsEnabled__c);
      if (!extract3.call(extract3)) {
          return {status: 'INCOMPLIANT', conditionIndex: 199, conditionText: "not(extract('CA10__actionsEnabled__c'))", currentStateMessage: "The CloudWatch alarm actions are disabled.", currentStateReferences: references1.join('\n'), remediation: "Consider enabling the alarm actions if the alarm is still required.", runtimeError: null};
      }
      // condition[2], conditionIndex:[200..299]
      function extract6() { if (!this.out) { this.out = obj.CA10__alarmActions__c; } return this.out; };
      function extract9() { if (!this.out) { this.out = obj.CA10__insufficientDataActions__c; } return this.out; };
      function extract12() { if (!this.out) { this.out = obj.CA10__okActions__c; } return this.out; };
      references1.push('Alarm Actions [obj.CA10__alarmActions__c]: ' + obj.CA10__alarmActions__c);
      references1.push('Insufficient Data Actions [obj.CA10__insufficientDataActions__c]: ' + obj.CA10__insufficientDataActions__c);
      references1.push('OK Actions [obj.CA10__okActions__c]: ' + obj.CA10__okActions__c);
      if (TextLib.isEmpty(extract6.call(extract6)) && TextLib.isEmpty(extract9.call(extract9)) && TextLib.isEmpty(extract12.call(extract12))) {
          return {status: 'INCOMPLIANT', conditionIndex: 299, conditionText: "extract('CA10__alarmActions__c').isEmpty() && extract('CA10__insufficientDataActions__c').isEmpty() && extract('CA10__okActions__c').isEmpty()", currentStateMessage: "The CloudWatch alarm does not have any actions configured for the ALARM, INSUFFICIENT_DATA, or OK states.", currentStateReferences: references1.join('\n'), remediation: "Configure at least one action for the ALARM, INSUFFICIENT_DATA, or OK state to ensure notifications or automated responses are triggered when the alarm changes state.", runtimeError: null};
      }
      return {status: 'COMPLIANT', conditionIndex: 300, conditionText: "otherwise", currentStateMessage: "The CloudWatch alarm has at least one action configured.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
  """;


  SELECT
    expectedResult.Id as Id,
    IF (
      IFNULL(expectedResult.expectedResult.status, '') = IFNULL(sObject.result.status, '')
      AND IFNULL(expectedResult.expectedResult.conditionIndex, -1) = IFNULL(sObject.result.conditionIndex, -1)
      AND IFNULL(expectedResult.expectedResult.conditionText, '') = IFNULL(sObject.result.conditionText, '')
      AND IFNULL(expectedResult.expectedResult.runtimeError, '') = IFNULL(sObject.result.runtimeError, ''),
      "MATCH",
      "FAIL"
    ) as match,
    expectedResult.expectedResult.status as expectedStatus, sObject.result.status as actualStatus,
    expectedResult.expectedResult.conditionIndex as expectedConditionIndex, sObject.result.conditionIndex as actualConditionIndex,
    expectedResult.expectedResult.conditionText as expectedConditionText, sObject.result.conditionText as actualConditionText,
    expectedResult.expectedResult.runtimeError as expectedRuntimeError, sObject.result.runtimeError as actualRuntimeError
  FROM UNNEST(mock_ExpectedResult()) expectedResult
  LEFT JOIN (
      SELECT
          sObject.CA10__disappearanceTime__c AS CA10__disappearanceTime__c,
          sObject.CA10__actionsEnabled__c AS CA10__actionsEnabled__c,
          sObject.CA10__alarmActions__c AS CA10__alarmActions__c,
          sObject.CA10__insufficientDataActions__c AS CA10__insufficientDataActions__c,
          sObject.CA10__okActions__c AS CA10__okActions__c,
          sObject.Id AS Id,
          process_CA10__CaAwsCloudWatchMetricAlarm__c(
              STRUCT(
                  sObject.CA10__disappearanceTime__c AS CA10__disappearanceTime__c,
                  sObject.CA10__actionsEnabled__c AS CA10__actionsEnabled__c,
                  sObject.CA10__alarmActions__c AS CA10__alarmActions__c,
                  sObject.CA10__insufficientDataActions__c AS CA10__insufficientDataActions__c,
                  sObject.CA10__okActions__c AS CA10__okActions__c,
                  sObject.Id AS Id
              ),
              sObject.context.snapshotTime
          ) as result
      FROM UNNEST(mock_CA10__CaAwsCloudWatchMetricAlarm__c()) AS sObject
  ) sObject ON sObject.Id = expectedResult.Id;
