---
policy: /ce/ca/aws/mq/broker-logging
logic: /ce/ca/aws/mq/broker-logging/prod.logic.yaml
executionTime: 2026-01-17T12:02:54.252310797Z
generationMs: 71
executionMs: 668
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: INAPPLICABLE
      actual: INAPPLICABLE
    conditionIndex:
      expected: 199
      actual: 199
    conditionText:
      expected: extract('CA10__engineType__c') != 'ACTIVEMQ'
      actual: extract('CA10__engineType__c') != 'ACTIVEMQ'
    runtimeError: {}
  - id: test3
    match: true
    status:
      expected: INCOMPLIANT
      actual: INCOMPLIANT
    conditionIndex:
      expected: 399
      actual: 399
    conditionText:
      expected: extract('CA10__logsAudit__c') == 'Disabled'
      actual: extract('CA10__logsAudit__c') == 'Disabled'
    runtimeError: {}
  - id: test4
    match: true
    status:
      expected: COMPLIANT
      actual: COMPLIANT
    conditionIndex:
      expected: 499
      actual: 499
    conditionText:
      expected: extract('CA10__logsAudit__c') == 'Enabled'
      actual: extract('CA10__logsAudit__c') == 'Enabled'
    runtimeError: {}
usedFiles:
  - path: /ce/ca/aws/mq/broker-logging/policy.yaml
    md5Hash: 03938E5300A08F546D128DABA709BBBF
    content: "---\nnames:\n  full: \"AWS MQ ActiveMQ Broker Audit Logging is not enabled\"\
      \n  contextual: \"ActiveMQ Broker Audit Logging is not enabled\"\ndescription:\
      \ >\n  Ensure that Amazon MQ brokers have audit logging enabled. Audit logs\
      \ provide a \n  record of management actions performed on the broker via the\
      \ API or the web console, \n  which is essential for security auditing and tracking\
      \ configuration changes.\ntype: \"COMPLIANCE_POLICY\"\ncategories:\n  - \"SECURITY\"\
      \nframeworkMappings:\n  - \"/frameworks/cloudaware/logging-and-monitoring/logging-and-monitoring-configuration\"\
      \n  - \"/frameworks/aws-fsbp-v1.0.0/mq/02\"\nsimilarPolicies:\n  awsSecurityHub:\n\
      \    - name: \"[MQ.2] ActiveMQ brokers should stream audit logs to CloudWatch\"\
      \n      url: \"https://docs.aws.amazon.com/securityhub/latest/userguide/mq-controls.html#mq-2\""
  - path: /ce/ca/aws/mq/broker-logging/prod.logic.yaml
    md5Hash: 1B01D352D73F02B6A963A892C348A4D2
    content: "---\ninputType: \"CA10__CaAwsMqBroker__c\"\nimportExtracts:\n  - file:\
      \ \"/types/CA10__CaAwsMqBroker__c/object.extracts.yaml\"\ntestData:\n  - file:\
      \ \"test-data.json\"\nconditions:\n  - status: \"INAPPLICABLE\"\n    currentStateMessage:\
      \ \"Audit logging is only supported for ActiveMQ brokers.\"\n    check:\n  \
      \    NOT_EQUAL:\n        left:\n          EXTRACT: \"CA10__engineType__c\"\n\
      \        right:\n          TEXT: \"ACTIVEMQ\"\n  - status: \"UNDETERMINED\"\n\
      \    currentStateMessage: \"Unable to determine audit logging status for this\
      \ ActiveMQ broker.\"\n    check:\n      IS_EMPTY:\n        arg:\n          EXTRACT:\
      \ \"CA10__logsAudit__c\"\n  - status: \"INCOMPLIANT\"\n    currentStateMessage:\
      \ \"Audit logging is disabled for this ActiveMQ broker.\"\n    remediationMessage:\
      \ \"Enable audit logging in the broker's log configuration settings.\"\n   \
      \ check:\n      IS_EQUAL:\n        left:\n          EXTRACT: \"CA10__logsAudit__c\"\
      \n        right:\n          TEXT: \"Disabled\"\n  - status: \"COMPLIANT\"\n\
      \    currentStateMessage: \"Audit logging is enabled for the MQ broker.\"  \
      \  \n    check:\n      IS_EQUAL:\n        left:\n          EXTRACT: \"CA10__logsAudit__c\"\
      \n        right:\n          TEXT: \"Enabled\"\notherwise:\n  status: \"UNDETERMINED\"\
      \n  currentStateMessage: \"Unexpected values in the field.\""
  - path: /ce/ca/aws/mq/broker-logging/test-data.json
    md5Hash: 6A079605CC2183F1238C0A8CFF6B736A
    content: |-
      [
          {
              "expectedResult": {
                  "status": "DISAPPEARED",
                  "conditionIndex": "99",
                  "conditionText": "isDisappeared(CA10__disappearanceTime__c)",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2026-01-14T11:34:06Z"
              },
              "CA10__disappearanceTime__c": "2026-01-14T11:34:06Z",
              "CA10__engineType__c": "ActiveMQ",
              "CA10__logsAudit__c": "Disabled",
              "Id": "test1"
          },
          {
              "expectedResult": {
                  "status": "INAPPLICABLE",
                  "conditionIndex": "199",
                  "conditionText": "extract('CA10__engineType__c') != 'ACTIVEMQ'",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2026-01-14T11:34:06Z"
              },
              "CA10__disappearanceTime__c": null,
              "CA10__engineType__c": "RabbitMQ",
              "CA10__logsAudit__c": "Disabled",
              "Id": "test2"
          },
          {
              "expectedResult": {
                  "status": "INCOMPLIANT",
                  "conditionIndex": "399",
                  "conditionText": "extract('CA10__logsAudit__c') == 'Disabled'",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2026-01-14T11:34:06Z"
              },
              "CA10__disappearanceTime__c": null,
              "CA10__engineType__c": "ActiveMQ",
              "CA10__logsAudit__c": "Disabled",
              "Id": "test3"
          },
          {
              "expectedResult": {
                  "status": "COMPLIANT",
                  "conditionIndex": "499",
                  "conditionText": "extract('CA10__logsAudit__c') == 'Enabled'",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2026-01-14T11:34:06Z"
              },
              "CA10__disappearanceTime__c": null,
              "CA10__engineType__c": "ActiveMQ",
              "CA10__logsAudit__c": "Enabled",
              "Id": "test4"
          }
      ]
  - path: /types/CA10__CaAwsMqBroker__c/object.extracts.yaml
    md5Hash: AF2B0A499B3C495C37E9FEF397E9DF46
    content: "---\nextracts:\n# Values: Enabled | Disabled. Nullable.\n  - name: \"\
      CA10__logsAudit__c\"\n    value: \n      FIELD:\n        path: \"CA10__logsAudit__c\"\
      \n# Values: ACTIVEMQ | RABBITMQ. Not nullable. \n  - name: \"CA10__engineType__c\"\
      \n    value: \n      FIELD:\n        path: \"CA10__engineType__c\"\n       \
      \ undeterminedIf:\n          noAccessDelegate:\n            path: \"CA10__engineType__c\"\
      \n            currentStateMessage: \"Broker Engine type cannot be empty. Possible\
      \ permission issue with mq:DescribeBroker.\"\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" : "INAPPLICABLE",
      "conditionIndex" : "199",
      "conditionText" : "extract('CA10__engineType__c') != 'ACTIVEMQ'",
      "runtimeError" : null
    }
  }, {
    "Id" : "test3",
    "expectedResult" : {
      "status" : "INCOMPLIANT",
      "conditionIndex" : "399",
      "conditionText" : "extract('CA10__logsAudit__c') == 'Disabled'",
      "runtimeError" : null
    }
  }, {
    "Id" : "test4",
    "expectedResult" : {
      "status" : "COMPLIANT",
      "conditionIndex" : "499",
      "conditionText" : "extract('CA10__logsAudit__c') == 'Enabled'",
      "runtimeError" : null
    }
  } ];
  """;

  CREATE TEMP FUNCTION mock_CA10__CaAwsMqBroker__c()
  RETURNS ARRAY<STRUCT<
      CA10__disappearanceTime__c TIMESTAMP,
      CA10__engineType__c STRING,
      CA10__logsAudit__c STRING,
      Id STRING,
      context STRUCT<
          snapshotTime TIMESTAMP
      >
  >>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
    return [ {
    "context" : {
      "snapshotTime" : new Date("2026-01-14T11:34:06Z")
    },
    "CA10__disappearanceTime__c" : new Date("2026-01-14T11:34:06Z"),
    "CA10__engineType__c" : "ActiveMQ",
    "CA10__logsAudit__c" : "Disabled",
    "Id" : "test1"
  }, {
    "context" : {
      "snapshotTime" : new Date("2026-01-14T11:34:06Z")
    },
    "CA10__engineType__c" : "RabbitMQ",
    "CA10__logsAudit__c" : "Disabled",
    "Id" : "test2"
  }, {
    "context" : {
      "snapshotTime" : new Date("2026-01-14T11:34:06Z")
    },
    "CA10__engineType__c" : "ActiveMQ",
    "CA10__logsAudit__c" : "Disabled",
    "Id" : "test3"
  }, {
    "context" : {
      "snapshotTime" : new Date("2026-01-14T11:34:06Z")
    },
    "CA10__engineType__c" : "ActiveMQ",
    "CA10__logsAudit__c" : "Enabled",
    "Id" : "test4"
  } ];
  """;

  CREATE TEMP FUNCTION process_CA10__CaAwsMqBroker__c(
      obj STRUCT<
          CA10__disappearanceTime__c TIMESTAMP,
          CA10__engineType__c STRING,
          CA10__logsAudit__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 fieldChecked4() {
          if (TextLib.isEmpty(obj.CA10__engineType__c)) {
              throw new Error("UNDETERMINED condition:101", {cause: {status: 'UNDETERMINED', conditionIndex: 101, conditionText: "CA10__engineType__c.delegatedTo(CA10__engineType__c).isEmpty()", currentStateMessage: "Broker Engine type cannot be empty. Possible permission issue with mq:DescribeBroker.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}});
          }
          return obj.CA10__engineType__c;
      }
      function extract3() { if (!this.out) { this.out = fieldChecked4(); } return this.out; };
      references1.push('Engine Type [obj.CA10__engineType__c]: ' + obj.CA10__engineType__c);
      try {
          if (TextLib.notEqual(extract3.call(extract3), 'ACTIVEMQ')) {
              return {status: 'INAPPLICABLE', conditionIndex: 199, conditionText: "extract('CA10__engineType__c') != 'ACTIVEMQ'", currentStateMessage: "Audit logging is only supported for ActiveMQ brokers.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
          }
      } catch (err) {
          if (err.cause && err.cause.status) { return err.cause; } else { throw err; }
      }
      // condition[2], conditionIndex:[200..299]
      function extract6() { if (!this.out) { this.out = obj.CA10__logsAudit__c; } return this.out; };
      references1.push('Logs: Audit [obj.CA10__logsAudit__c]: ' + obj.CA10__logsAudit__c);
      if (TextLib.isEmpty(extract6.call(extract6))) {
          return {status: 'UNDETERMINED', conditionIndex: 299, conditionText: "extract('CA10__logsAudit__c').isEmpty()", currentStateMessage: "Unable to determine audit logging status for this ActiveMQ broker.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
      }
      // condition[3], conditionIndex:[300..399]
      function extract9() { if (!this.out) { this.out = obj.CA10__logsAudit__c; } return this.out; };
      if (TextLib.equal(extract9.call(extract9), 'Disabled')) {
          return {status: 'INCOMPLIANT', conditionIndex: 399, conditionText: "extract('CA10__logsAudit__c') == 'Disabled'", currentStateMessage: "Audit logging is disabled for this ActiveMQ broker.", currentStateReferences: references1.join('\n'), remediation: "Enable audit logging in the broker's log configuration settings.", runtimeError: null};
      }
      // condition[4], conditionIndex:[400..499]
      function extract12() { if (!this.out) { this.out = obj.CA10__logsAudit__c; } return this.out; };
      if (TextLib.equal(extract12.call(extract12), 'Enabled')) {
          return {status: 'COMPLIANT', conditionIndex: 499, conditionText: "extract('CA10__logsAudit__c') == 'Enabled'", currentStateMessage: "Audit logging is enabled for the MQ broker.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
      }
      return {status: 'UNDETERMINED', conditionIndex: 500, conditionText: "otherwise", currentStateMessage: "Unexpected values in the field.", 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__engineType__c AS CA10__engineType__c,
          sObject.CA10__logsAudit__c AS CA10__logsAudit__c,
          sObject.Id AS Id,
          process_CA10__CaAwsMqBroker__c(
              STRUCT(
                  sObject.CA10__disappearanceTime__c AS CA10__disappearanceTime__c,
                  sObject.CA10__engineType__c AS CA10__engineType__c,
                  sObject.CA10__logsAudit__c AS CA10__logsAudit__c,
                  sObject.Id AS Id
              ),
              sObject.context.snapshotTime
          ) as result
      FROM UNNEST(mock_CA10__CaAwsMqBroker__c()) AS sObject
  ) sObject ON sObject.Id = expectedResult.Id;
