---
policy: /ce/ca/azure/subscription/activity-log-alert-for-service-health
logic: /ce/ca/azure/subscription/activity-log-alert-for-service-health/prod.logic.yaml
executionTime: 2025-07-21T17:39:14.384010318Z
rows:
  - id: '001'
    match: true
    status:
      expected: COMPLIANT
      actual: COMPLIANT
    conditionIndex:
      expected: 199
      actual: 199
    conditionText:
      expected: CA10__Azure_Activity_Log_Alerts__r.has(COMPLIANT)
      actual: CA10__Azure_Activity_Log_Alerts__r.has(COMPLIANT)
    runtimeError: {}
  - id: '002'
    match: true
    status:
      expected: INCOMPLIANT
      actual: INCOMPLIANT
    conditionIndex:
      expected: 200
      actual: 200
    conditionText:
      expected: otherwise
      actual: otherwise
    runtimeError: {}
  - id: '003'
    match: true
    status:
      expected: INCOMPLIANT
      actual: INCOMPLIANT
    conditionIndex:
      expected: 200
      actual: 200
    conditionText:
      expected: otherwise
      actual: otherwise
    runtimeError: {}
usedFiles:
  - path: /ce/ca/azure/subscription/activity-log-alert-for-service-health/policy.yaml
    md5Hash: 421C32035346A55B5A34F4B8F4582048
    content: |
      ---
      names:
        full: Azure Subscription Activity Log Alert for Service Health does not
          exist
        contextual: Activity Log Alert for Service Health does not exist
      description: Create an activity log alert for Service Health.
      type: COMPLIANCE_POLICY
      categories:
        - SECURITY
      frameworkMappings:
        - "/frameworks/cis-azure-v4.0.0/07/01/02/11"
        - "/frameworks/cloudaware/logging-and-monitoring/alerting-and-notification"
  - path: /ce/ca/azure/subscription/activity-log-alert-for-service-health/prod.logic.yaml
    md5Hash: 40C66BEE8E587459A02DB054003D7EFA
    content: "---\ninputType: \"CA10__CaAzureAccount__c\"\ntestData:\n  - file: \"\
      test-data.json\"\nconditions:\n  - status: \"COMPLIANT\"\n    currentStateMessage:\
      \ \"This subscription has an Activity Log Alert for Service Health.\"\n    check:\n\
      \      RELATED_LIST_HAS:\n        status: \"COMPLIANT\"\n        relationshipName:\
      \ \"CA10__Azure_Activity_Log_Alerts__r\"\notherwise:\n  status: \"INCOMPLIANT\"\
      \n  currentStateMessage: \"This subscription doesn't have an Activity Log Alert\
      \ for Service Health.\"\n  remediationMessage: \"Consider creating an Activity\
      \ Log Alert for Service Health.\"\nrelatedLists:\n  - relationshipName: \"CA10__Azure_Activity_Log_Alerts__r\"\
      \n    importExtracts:\n      - file: \"/types/CA10__CaAzureActivityLogAlert__c/object.extracts.yaml\"\
      \n    conditions:\n      - status: \"INAPPLICABLE\"\n        currentStateMessage:\
      \ \"This is a disabled Activity Log Alert.\"\n        check:\n          NOT_EQUAL:\n\
      \            left:\n              EXTRACT: \"CA10__enabledStatus__c\"\n    \
      \        right:\n              TEXT: \"Enabled\"\n      - status: \"COMPLIANT\"\
      \n        currentStateMessage: \"This is an Activity Log Alert for Service Health.\"\
      \n        check:\n          AND:\n            args:\n              - JSON_QUERY_BOOLEAN:\n\
      \                  arg: \n                    EXTRACT: \"caJsonFrom__conditionJson__c\"\
      \n                  expression: \"contains(allOf[*].equals, 'ServiceHealth')\"\
      \n                  undeterminedIf: \n                    evaluationError: \"\
      The JSON query has failed.\"\n                    resultTypeMismatch: \"The\
      \ JSON query did not return boolean type.\"\n              - CONTAINS:\n   \
      \               arg:\n                    EXTRACT: \"CA10__scopes__c\"\n   \
      \               search:\n                    TEXT: \"/subscriptions/\"\n   \
      \           - NOT:\n                  arg:\n                    CONTAINS:\n\
      \                      arg:\n                        EXTRACT: \"CA10__scopes__c\"\
      \n                      search:\n                        TEXT: \"/resourceGroups/\"\
      \n    otherwise:\n      status: \"INAPPLICABLE\"\n      currentStateMessage:\
      \ \"This is an unrelated Activity Log Alert.\""
  - path: /types/CA10__CaAzureActivityLogAlert__c/object.extracts.yaml
    md5Hash: 8A1FFCB1A6A450C933A1A1E63AD96EA2
    content: "---\nextracts:\n# Not nullable. Can't have no access, retrieved via\
      \ Microsoft.Insights/ActivityLogAlerts\n  - name: \"CA10__enabledStatus__c\"\
      \n    value: \n      FIELD:\n        path: \"CA10__enabledStatus__c\"\n    \
      \    undeterminedIf:\n          isEmpty: \"Corrupted data. Status cannot be\
      \ empty.\"\n# Not nullable. Can't have no access, retrieved via Microsoft.Insights/ActivityLogAlerts\n\
      \  - name: \"CA10__conditionJson__c\"\n    value: \n      FIELD:\n        path:\
      \ \"CA10__conditionJson__c\"\n        returnType: BYTES\n        undeterminedIf:\n\
      \          isEmpty: \"Corrupted data. Condition cannot be empty.\"\n  - name:\
      \ \"caJsonFrom__conditionJson__c\"\n    value: \n      JSON_FROM:\n        arg:\
      \ \n          EXTRACT: \"CA10__conditionJson__c\"\n        undeterminedIf:\n\
      \          isInvalid: \"Condition JSON is invalid.\"\n# Not nullable. Can't\
      \ have no access, retrieved via Microsoft.Insights/ActivityLogAlerts\n  - name:\
      \ \"CA10__scopes__c\"\n    value: \n      FIELD:\n        path: \"CA10__scopes__c\"\
      \n        undeterminedIf:\n          isEmpty: \"Corrupted data. Scopes cannot\
      \ be empty.\"\n"
  - path: /ce/ca/azure/subscription/activity-log-alert-for-service-health/test-data.json
    md5Hash: 147DD5B19B29C67C0649F7AF7E43494B
    content: |-
      [
        {
          "expectedResult": {
            "status": "COMPLIANT",
            "conditionIndex": "199",
            "conditionText": "CA10__Azure_Activity_Log_Alerts__r.has(COMPLIANT)",
            "runtimeError": null
          },
          "context": {
              "snapshotTime": "2025-07-16T03:42:29Z"
          },
          "Id": "001",
          "CA10__Azure_Activity_Log_Alerts__r": [
            {
              "Id": "111",
              "CA10__disappearanceTime__c": null,
              "CA10__enabledStatus__c": "Enabled",
              "CA10__conditionJson__c": "{\"allOf\":[{\"field\":\"category\",\"equals\":\"ServiceHealth\"}]}",
              "CA10__scopes__c": "/subscriptions/subscriptionId",
              "CA10__subscription__c": "001"
            }
          ]
          },
        {
          "expectedResult": {
            "status": "INCOMPLIANT",
            "conditionIndex": "200",
            "conditionText": "otherwise",
            "runtimeError": null
          },
          "context": {
            "snapshotTime": "2025-07-10T07:31:08Z"
          },
          "Id": "002",
          "CA10__Azure_Activity_Log_Alerts__r": [
            {
              "Id": "222",
              "CA10__disappearanceTime__c": null,
              "CA10__enabledStatus__c": "Enabled",
              "CA10__conditionJson__c": "{\"allOf\":[{\"field\":\"category\",\"equals\":\"ServiceHealth\"}]}",
              "CA10__subscription__c": "002",
              "CA10__scopes__c": "/subscriptions/subscriptionId/resourceGroups/resourceGroup"
            }
          ]
        },
        {
          "expectedResult": {
            "status": "INCOMPLIANT",
            "conditionIndex": "200",
            "conditionText": "otherwise",
            "runtimeError": null
          },
          "context": {
            "snapshotTime": "2025-07-10T07:31:08Z"
          },
          "Id": "003",
          "CA10__Azure_Activity_Log_Alerts__r": []
        }
      ]
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" : "001",
    "expectedResult" : {
      "status" : "COMPLIANT",
      "conditionIndex" : "199",
      "conditionText" : "CA10__Azure_Activity_Log_Alerts__r.has(COMPLIANT)",
      "runtimeError" : null
    }
  }, {
    "Id" : "002",
    "expectedResult" : {
      "status" : "INCOMPLIANT",
      "conditionIndex" : "200",
      "conditionText" : "otherwise",
      "runtimeError" : null
    }
  }, {
    "Id" : "003",
    "expectedResult" : {
      "status" : "INCOMPLIANT",
      "conditionIndex" : "200",
      "conditionText" : "otherwise",
      "runtimeError" : null
    }
  } ];
  """;

  CREATE TEMP FUNCTION mock_CA10__CaAzureAccount__c()
  RETURNS ARRAY<STRUCT<
      Id STRING,
      context STRUCT<
          snapshotTime TIMESTAMP
      >
  >>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
    return [ {
    "context" : {
      "snapshotTime" : new Date("2025-07-16T03:42:29Z")
    },
    "Id" : "001"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-07-10T07:31:08Z")
    },
    "Id" : "002"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-07-10T07:31:08Z")
    },
    "Id" : "003"
  } ];
  """;

  CREATE TEMP FUNCTION mock_CA10__CaAzureActivityLogAlert__c()
  RETURNS ARRAY<STRUCT<
      Id STRING,
      CA10__disappearanceTime__c TIMESTAMP,
      CA10__enabledStatus__c STRING,
      CA10__conditionJson__c STRING,
      CA10__scopes__c STRING,
      CA10__subscription__c STRING,
      context STRUCT<
          snapshotTime TIMESTAMP
      >
  >>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
    return [ {
    "context" : {
      "snapshotTime" : new Date("2025-07-16T03:42:29Z")
    },
    "Id" : "111",
    "CA10__enabledStatus__c" : "Enabled",
    "CA10__conditionJson__c" : "{\"allOf\":[{\"field\":\"category\",\"equals\":\"ServiceHealth\"}]}",
    "CA10__scopes__c" : "/subscriptions/subscriptionId",
    "CA10__subscription__c" : "001"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-07-10T07:31:08Z")
    },
    "Id" : "222",
    "CA10__enabledStatus__c" : "Enabled",
    "CA10__conditionJson__c" : "{\"allOf\":[{\"field\":\"category\",\"equals\":\"ServiceHealth\"}]}",
    "CA10__scopes__c" : "/subscriptions/subscriptionId/resourceGroups/resourceGroup",
    "CA10__subscription__c" : "002"
  } ];
  """;

  CREATE TEMP FUNCTION process_CA10__CaAzureAccount__c(
      obj STRUCT<
          Id STRING,
          CA10__Azure_Activity_Log_Alerts__r ARRAY<STRUCT<
              Id STRING,
              CA10__disappearanceTime__c TIMESTAMP,
              CA10__enabledStatus__c STRING,
              CA10__conditionJson__c STRING,
              CA10__scopes__c STRING,
              CA10__subscription__c STRING,
              result STRUCT<status STRING, conditionIndex DECIMAL, conditionText STRING, currentStateMessage STRING, currentStateReferences STRING, remediation STRING, runtimeError 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 references1 = [];
      // condition[0], conditionIndex:[0..99]
      if (false) {
          return {status: 'DISAPPEARED', conditionIndex: 99, conditionText: "isDisappeared()", currentStateMessage: "Object is deleted in the source", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
      }
      var count_CA10__Azure_Activity_Log_Alerts__r_COMPLIANT2 = 0;
      if (obj.CA10__Azure_Activity_Log_Alerts__r != null) {
          for (var i3 = 0; i3 < obj.CA10__Azure_Activity_Log_Alerts__r.length; i3++) {
              if (obj.CA10__Azure_Activity_Log_Alerts__r[i3].result.status == 'COMPLIANT') {
                  count_CA10__Azure_Activity_Log_Alerts__r_COMPLIANT2 += 1;
              }
          }
      }
      // condition[1], conditionIndex:[100..199]
      references1.push('Related list [CA10__Azure_Activity_Log_Alerts__r] ' + (count_CA10__Azure_Activity_Log_Alerts__r_COMPLIANT2 > 0 ? 'has' : 'does not have') + ' objects in COMPLIANT status');
      if (count_CA10__Azure_Activity_Log_Alerts__r_COMPLIANT2 > 0) {
          return {status: 'COMPLIANT', conditionIndex: 199, conditionText: "CA10__Azure_Activity_Log_Alerts__r.has(COMPLIANT)", currentStateMessage: "This subscription has an Activity Log Alert for Service Health.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
      }
      return {status: 'INCOMPLIANT', conditionIndex: 200, conditionText: "otherwise", currentStateMessage: "This subscription doesn't have an Activity Log Alert for Service Health.", currentStateReferences: references1.join('\n'), remediation: "Consider creating an Activity Log Alert for Service Health.", runtimeError: null};
  """;

  CREATE TEMP FUNCTION process_CA10__Azure_Activity_Log_Alerts__r(
      obj STRUCT<
          Id STRING,
          CA10__disappearanceTime__c TIMESTAMP,
          CA10__enabledStatus__c STRING,
          CA10__conditionJson__c STRING,
          CA10__scopes__c STRING,
          CA10__subscription__c STRING
      >,
      snapshotTime TIMESTAMP
  )
  RETURNS STRUCT<status STRING, conditionIndex DECIMAL, conditionText STRING, currentStateMessage STRING, currentStateReferences STRING, remediation STRING, runtimeError STRING>
  DETERMINISTIC
  LANGUAGE js
  OPTIONS (library=['gs://compliance-platform-public/jmespath.min.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 BytesLib = new function () {
          this.normalize = function(arg) {
              return arg == null ? '' : arg;
          };
          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 Azure [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__enabledStatus__c)) {
              throw new Error("UNDETERMINED condition:101", {cause: {status: 'UNDETERMINED', conditionIndex: 101, conditionText: "CA10__enabledStatus__c.isEmpty()", currentStateMessage: "Corrupted data. Status cannot be empty.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}});
          }
          return obj.CA10__enabledStatus__c;
      }
      function extract3() { if (!this.out) { this.out = fieldChecked4(); } return this.out; };
      references1.push('Enabled Status [obj.CA10__enabledStatus__c]: ' + obj.CA10__enabledStatus__c);
      try {
          if (TextLib.notEqual(extract3.call(extract3), 'Enabled')) {
              return {status: 'INAPPLICABLE', conditionIndex: 199, conditionText: "extract('CA10__enabledStatus__c') != 'Enabled'", currentStateMessage: "This is a disabled Activity Log Alert.", 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 jsonQueryChecked5() {
          var input = extract7.call(extract7);
          var out;
          try {
              out = jmespath.search(input, 'contains(allOf[*].equals, \'ServiceHealth\')');
          if (out != null && typeof out != 'boolean') {
              throw new Error("UNDETERMINED condition:203", {cause: {status: 'UNDETERMINED', conditionIndex: 203, conditionText: "extract('caJsonFrom__conditionJson__c').jsonQueryText('contains(allOf[*].equals, \\'ServiceHealth\\')').isResultTypeMismatch()", currentStateMessage: "The JSON query did not return boolean type.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}});
          }
          } catch (e) {
              throw new Error("UNDETERMINED condition:204", {cause: {status: 'UNDETERMINED', conditionIndex: 204, conditionText: "extract('caJsonFrom__conditionJson__c').jsonQueryText('contains(allOf[*].equals, \\'ServiceHealth\\')').isEvaluationFailed()", currentStateMessage: "The JSON query has failed.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: e.message}});
          }
          return out;
      }
      function jsonChecked8() {
          var input = extract10.call(extract10);
          input = TextLib.isEmpty(input) ? null : input;
          var out;
          try {
              out = JSON.parse(input);
          } catch (e) {
              throw new Error("UNDETERMINED condition:202", {cause: {status: 'UNDETERMINED', conditionIndex: 202, conditionText: "extract('CA10__conditionJson__c').asJson().isInvalid()", currentStateMessage: "Condition JSON is invalid.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: e.message}});
          }
          return out;
      }
      function fieldChecked11() {
          if (BytesLib.isEmpty(obj.CA10__conditionJson__c)) {
              throw new Error("UNDETERMINED condition:201", {cause: {status: 'UNDETERMINED', conditionIndex: 201, conditionText: "CA10__conditionJson__c.isEmpty()", currentStateMessage: "Corrupted data. Condition cannot be empty.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}});
          }
          return obj.CA10__conditionJson__c;
      }
      function extract10() { if (!this.out) { this.out = fieldChecked11(); } return this.out; };
      function extract7() { if (!this.out) { this.out = jsonChecked8(); } return this.out; };
      function fieldChecked14() {
          if (TextLib.isEmpty(obj.CA10__scopes__c)) {
              throw new Error("UNDETERMINED condition:205", {cause: {status: 'UNDETERMINED', conditionIndex: 205, conditionText: "CA10__scopes__c.isEmpty()", currentStateMessage: "Corrupted data. Scopes cannot be empty.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}});
          }
          return obj.CA10__scopes__c;
      }
      function extract13() { if (!this.out) { this.out = fieldChecked14(); } return this.out; };
      references1.push('Condition JSON [obj.CA10__conditionJson__c]: ' + obj.CA10__conditionJson__c);
      references1.push('Scopes [obj.CA10__scopes__c]: ' + obj.CA10__scopes__c);
      try {
          if (jsonQueryChecked5() && TextLib.contains(extract13.call(extract13), '/subscriptions/') && !TextLib.contains(extract13.call(extract13), '/resourceGroups/')) {
              return {status: 'COMPLIANT', conditionIndex: 299, conditionText: "extract('caJsonFrom__conditionJson__c').jsonQueryText('contains(allOf[*].equals, \\'ServiceHealth\\')') && extract('CA10__scopes__c').contains('/subscriptions/') && not(extract('CA10__scopes__c').contains('/resourceGroups/'))", currentStateMessage: "This is an Activity Log Alert for Service Health.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
          }
      } catch (err) {
          if (err.cause && err.cause.status) { return err.cause; } else { throw err; }
      }
      return {status: 'INAPPLICABLE', conditionIndex: 300, conditionText: "otherwise", currentStateMessage: "This is an unrelated Activity Log Alert.", 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.Id AS Id,
          `CA10__Azure_Activity_Log_Alerts__r`.arr AS CA10__Azure_Activity_Log_Alerts__r,
          process_CA10__CaAzureAccount__c(
              STRUCT(
                  sObject.Id AS Id,
                  `CA10__Azure_Activity_Log_Alerts__r`.arr AS CA10__Azure_Activity_Log_Alerts__r
              ),
              sObject.context.snapshotTime
          ) as result
      FROM UNNEST(mock_CA10__CaAzureAccount__c()) AS sObject
      LEFT JOIN (
          SELECT
              sObject.CA10__subscription__c,
              ARRAY_AGG(
                  STRUCT(
                      sObject.Id AS Id,
                      sObject.CA10__disappearanceTime__c AS CA10__disappearanceTime__c,
                      sObject.CA10__enabledStatus__c AS CA10__enabledStatus__c,
                      sObject.CA10__conditionJson__c AS CA10__conditionJson__c,
                      sObject.CA10__scopes__c AS CA10__scopes__c,
                      sObject.CA10__subscription__c AS CA10__subscription__c,
                      process_CA10__Azure_Activity_Log_Alerts__r(
                          STRUCT(
                              sObject.Id AS Id,
                              sObject.CA10__disappearanceTime__c AS CA10__disappearanceTime__c,
                              sObject.CA10__enabledStatus__c AS CA10__enabledStatus__c,
                              sObject.CA10__conditionJson__c AS CA10__conditionJson__c,
                              sObject.CA10__scopes__c AS CA10__scopes__c,
                              sObject.CA10__subscription__c AS CA10__subscription__c
                          ),
                          sObject.context.snapshotTime
                      ) as result
                  )
              ) AS arr
          FROM UNNEST(mock_CA10__CaAzureActivityLogAlert__c()) AS sObject
          GROUP BY sObject.CA10__subscription__c
      ) AS `CA10__Azure_Activity_Log_Alerts__r`
          ON sObject.Id = `CA10__Azure_Activity_Log_Alerts__r`.CA10__subscription__c
  ) sObject ON sObject.Id = expectedResult.Id;
