---
policy: /ce/ca/azure/monitor/diagnostic-setting-categories
logic: /ce/ca/azure/monitor/diagnostic-setting-categories/prod.logic.yaml
executionTime: 2025-04-24T23:45:33.087941012Z
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: RecordType.DeveloperName != 'caDiagnosticSettingOnAzureSubscription'
      actual: RecordType.DeveloperName != 'caDiagnosticSettingOnAzureSubscription'
    runtimeError: {}
  - id: test3
    match: true
    status:
      expected: INCOMPLIANT
      actual: INCOMPLIANT
    conditionIndex:
      expected: 299
      actual: 299
    conditionText:
      expected: "not(extract('caJsonFrom__logsJson__c').jsonQueryText('[? category\
        \ == `Administrative`].enabled | [0]') && extract('caJsonFrom__logsJson__c').jsonQueryText('[?\
        \ category == `Alert`].enabled | [0]') && extract('caJsonFrom__logsJson__c').jsonQueryText('[?\
        \ category == `Policy`].enabled | [0]') && extract('caJsonFrom__logsJson__c').jsonQueryText('[?\
        \ category == `Security`].enabled | [0]'))"
      actual: "not(extract('caJsonFrom__logsJson__c').jsonQueryText('[? category ==\
        \ `Administrative`].enabled | [0]') && extract('caJsonFrom__logsJson__c').jsonQueryText('[?\
        \ category == `Alert`].enabled | [0]') && extract('caJsonFrom__logsJson__c').jsonQueryText('[?\
        \ category == `Policy`].enabled | [0]') && extract('caJsonFrom__logsJson__c').jsonQueryText('[?\
        \ category == `Security`].enabled | [0]'))"
    runtimeError: {}
  - id: test4
    match: true
    status:
      expected: COMPLIANT
      actual: COMPLIANT
    conditionIndex:
      expected: 300
      actual: 300
    conditionText:
      expected: otherwise
      actual: otherwise
    runtimeError: {}
  - id: test5
    match: true
    status:
      expected: INCOMPLIANT
      actual: INCOMPLIANT
    conditionIndex:
      expected: 299
      actual: 299
    conditionText:
      expected: "not(extract('caJsonFrom__logsJson__c').jsonQueryText('[? category\
        \ == `Administrative`].enabled | [0]') && extract('caJsonFrom__logsJson__c').jsonQueryText('[?\
        \ category == `Alert`].enabled | [0]') && extract('caJsonFrom__logsJson__c').jsonQueryText('[?\
        \ category == `Policy`].enabled | [0]') && extract('caJsonFrom__logsJson__c').jsonQueryText('[?\
        \ category == `Security`].enabled | [0]'))"
      actual: "not(extract('caJsonFrom__logsJson__c').jsonQueryText('[? category ==\
        \ `Administrative`].enabled | [0]') && extract('caJsonFrom__logsJson__c').jsonQueryText('[?\
        \ category == `Alert`].enabled | [0]') && extract('caJsonFrom__logsJson__c').jsonQueryText('[?\
        \ category == `Policy`].enabled | [0]') && extract('caJsonFrom__logsJson__c').jsonQueryText('[?\
        \ category == `Security`].enabled | [0]'))"
    runtimeError: {}
usedFiles:
  - path: /ce/ca/azure/monitor/diagnostic-setting-categories/policy.yaml
    md5Hash: 04D060897D5FE668A60F2C537F6F9A85
    content: |
      ---
      names:
        full: "Azure Diagnostic Setting captures Administrative, Alert, Policy, and Security\
          \ categories"
        contextual: "Diagnostic Setting captures Administrative, Alert, Policy, and Security\
          \ categories"
      description: The diagnostic setting should be configured to log the appropriate activities
        from the control/management plane.
      type: COMPLIANCE_POLICY
      categories:
        - SECURITY
        - RELIABILITY
      frameworkMappings:
        - "/frameworks/cis-azure-v2.1.0/05/01/02"
        - "/frameworks/cis-azure-v3.0.0/06/01/02"
        - "/frameworks/cloudaware/logging-and-monitoring/logging-and-monitoring-configuration"
      similarPolicies:
        internal:
          - dec-x-a193b20f
  - path: /ce/ca/azure/monitor/diagnostic-setting-categories/prod.logic.yaml
    md5Hash: 24539B2CC16F8161AF4400D4F12AC3D1
    content: "inputType: \"CA10__CaAzureDiagnosticSetting__c\"\nimportExtracts:\n\
      \  - file: \"/types/CA10__CaAzureDiagnosticSetting__c/object.extracts.yaml\"\
      \ntestData:\n  - file: \"test-data.json\"\nconditions:\n  - status: \"INAPPLICABLE\"\
      \n    currentStateMessage: \"This is not a subscription Diagnostic Setting.\"\
      \n    check:\n      NOT_EQUAL:\n        left:\n          FIELD: \n         \
      \   path: \"RecordType.DeveloperName\"\n        right:\n          TEXT: \"caDiagnosticSettingOnAzureSubscription\"\
      \n  - status: \"INCOMPLIANT\"\n    currentStateMessage: \"The diagnostic setting\
      \ does not capture the appropriate activities from the management plane.\"\n\
      \    remediationMessage: \"Consider configuring the diagnostic setting to capture\
      \ Administrative, Alert, Policy, and Security log categories.\"\n    check:\n\
      \      NOT:\n        arg:\n          AND:\n            args:\n             \
      \ - JSON_QUERY_BOOLEAN:\n                  arg: \n                    EXTRACT:\
      \ \"caJsonFrom__logsJson__c\"\n                  expression: \"[? category ==\
      \ `Administrative`].enabled | [0]\"\n                  undeterminedIf: \n  \
      \                  evaluationError: \"The JSON query has failed.\"\n       \
      \             resultTypeMismatch: \"The JSON query did not return boolean type.\"\
      \n              - JSON_QUERY_BOOLEAN:\n                  arg: \n           \
      \         EXTRACT: \"caJsonFrom__logsJson__c\"\n                  expression:\
      \ \"[? category == `Alert`].enabled | [0]\"\n                  undeterminedIf:\
      \ \n                    evaluationError: \"The JSON query has failed.\"\n  \
      \                  resultTypeMismatch: \"The JSON query did not return boolean\
      \ type.\"\n              - JSON_QUERY_BOOLEAN:\n                  arg: \n  \
      \                  EXTRACT: \"caJsonFrom__logsJson__c\"\n                  expression:\
      \ \"[? category == `Policy`].enabled | [0]\"\n                  undeterminedIf:\
      \ \n                    evaluationError: \"The JSON query has failed.\"\n  \
      \                  resultTypeMismatch: \"The JSON query did not return boolean\
      \ type.\"\n              - JSON_QUERY_BOOLEAN:\n                  arg: \n  \
      \                  EXTRACT: \"caJsonFrom__logsJson__c\"\n                  expression:\
      \ \"[? category == `Security`].enabled | [0]\"\n                  undeterminedIf:\
      \ \n                    evaluationError: \"The JSON query has failed.\"\n  \
      \                  resultTypeMismatch: \"The JSON query did not return boolean\
      \ type.\"\notherwise:\n  status: \"COMPLIANT\"\n  currentStateMessage: \"The\
      \ diagnostic setting captures the appropriate activities from the management\
      \ plane.\""
  - path: /ce/ca/azure/monitor/diagnostic-setting-categories/test-data.json
    md5Hash: 7C5C255C035DF0312BE934B2B2729D36
    content: |-
      [
          {
              "expectedResult": {
                  "status": "DISAPPEARED",
                  "conditionIndex": "99",
                  "conditionText": "isDisappeared(CA10__disappearanceTime__c)",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2024-05-29T03:06:28Z"
              },
              "Id": "test1",
              "RecordTypeId": "RecordTypeId1",
              "CA10__disappearanceTime__c": "2024-05-28T19:31:51Z",
              "RecordType": {
                  "DeveloperName": "caDiagnosticSettingOnAzureSubscription",
                  "Id": "RecordTypeId1"
              },
              "CA10__logsJson__c": "[{\"category\": \"Security\",\"enabled\": true},{\"category\": \"Alert\",\"enabled\": true},{\"category\": \"Administrative\",\"enabled\": true},{\"category\": \"Policy\",\"enabled\": true}]"
          },
          {
              "expectedResult": {
                  "status": "INAPPLICABLE",
                  "conditionIndex": "199",
                  "conditionText": "RecordType.DeveloperName != 'caDiagnosticSettingOnAzureSubscription'",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2024-05-29T03:06:28Z"
              },
              "Id": "test2",
              "RecordTypeId": "RecordTypeId2",
              "CA10__disappearanceTime__c": null,
              "RecordType": {
                  "DeveloperName": "caDiagnosticSettingOnAzureResource",
                  "Id": "RecordTypeId2"
              },
              "CA10__logsJson__c": "[{\"category\": \"Security\",\"enabled\": true},{\"category\": \"Alert\",\"enabled\": true},{\"category\": \"Administrative\",\"enabled\": true},{\"category\": \"Policy\",\"enabled\": true}]"
          },
          {
              "expectedResult": {
                  "status": "INCOMPLIANT",
                  "conditionIndex": "299",
                  "conditionText": "not(extract('caJsonFrom__logsJson__c').jsonQueryText('[? category == `Administrative`].enabled | [0]') && extract('caJsonFrom__logsJson__c').jsonQueryText('[? category == `Alert`].enabled | [0]') && extract('caJsonFrom__logsJson__c').jsonQueryText('[? category == `Policy`].enabled | [0]') && extract('caJsonFrom__logsJson__c').jsonQueryText('[? category == `Security`].enabled | [0]'))",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2024-05-29T03:06:28Z"
              },
              "Id": "test3",
              "RecordTypeId": "RecordTypeId3",
              "CA10__disappearanceTime__c": null,
              "RecordType": {
                  "DeveloperName": "caDiagnosticSettingOnAzureSubscription",
                  "Id": "RecordTypeId3"
              },
              "CA10__logsJson__c": "[{\"category\": \"Security\",\"enabled\": false},{\"category\": \"Alert\",\"enabled\": false},{\"category\": \"Administrative\",\"enabled\": false},{\"category\": \"Policy\",\"enabled\": false}]"
          },
          {
              "expectedResult": {
                  "status": "COMPLIANT",
                  "conditionIndex": "300",
                  "conditionText": "otherwise",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2024-05-29T03:06:28Z"
              },
              "Id": "test4",
              "RecordTypeId": "RecordTypeId4",
              "CA10__disappearanceTime__c": null,
              "RecordType": {
                  "DeveloperName": "caDiagnosticSettingOnAzureSubscription",
                  "Id": "RecordTypeId4"
              },
              "CA10__logsJson__c": "[{\"category\": \"Security\",\"enabled\": true},{\"category\": \"Alert\",\"enabled\": true},{\"category\": \"Administrative\",\"enabled\": true},{\"category\": \"Policy\",\"enabled\": true}]"
          },
          {
              "expectedResult": {
                  "status": "INCOMPLIANT",
                  "conditionIndex": "299",
                  "conditionText": "not(extract('caJsonFrom__logsJson__c').jsonQueryText('[? category == `Administrative`].enabled | [0]') && extract('caJsonFrom__logsJson__c').jsonQueryText('[? category == `Alert`].enabled | [0]') && extract('caJsonFrom__logsJson__c').jsonQueryText('[? category == `Policy`].enabled | [0]') && extract('caJsonFrom__logsJson__c').jsonQueryText('[? category == `Security`].enabled | [0]'))",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2024-05-29T03:06:28Z"
              },
              "Id": "test5",
              "RecordTypeId": "RecordTypeId5",
              "CA10__disappearanceTime__c": null,
              "RecordType": {
                  "DeveloperName": "caDiagnosticSettingOnAzureSubscription",
                  "Id": "RecordTypeId5"
              },
              "CA10__logsJson__c": "[{\"category\": \"Security\",\"enabled\": false},{\"category\": \"Alert\",\"enabled\": true},{\"category\": \"Administrative\",\"enabled\": true},{\"category\": \"Policy\",\"enabled\": true}]"
          }
      ]
  - path: /types/CA10__CaAzureDiagnosticSetting__c/object.extracts.yaml
    md5Hash: 1A315A8ECC027A42193366B24979B007
    content: "---\nextracts:\n# Not Nullable. Can't have no access, retrieved via\
      \ Microsoft.Insights/diagnosticSettings/read\n  - name: \"CA10__logsJson__c\"\
      \n    value: \n      FIELD:\n        path: \"CA10__logsJson__c\"\n        returnType:\
      \ BYTES\n        undeterminedIf:\n          isEmpty: \"Corrupted Data. Diagnostic\
      \ Setting Logs JSON cannot be empty.\"\n  - name: \"caJsonFrom__logsJson__c\"\
      \n    value: \n      JSON_FROM:\n        arg: \n          EXTRACT: \"CA10__logsJson__c\"\
      \n        undeterminedIf:\n          isInvalid: \"Logs JSON is invalid.\"\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" : "RecordType.DeveloperName != 'caDiagnosticSettingOnAzureSubscription'",
      "runtimeError" : null
    }
  }, {
    "Id" : "test3",
    "expectedResult" : {
      "status" : "INCOMPLIANT",
      "conditionIndex" : "299",
      "conditionText" : "not(extract('caJsonFrom__logsJson__c').jsonQueryText('[? category == `Administrative`].enabled | [0]') && extract('caJsonFrom__logsJson__c').jsonQueryText('[? category == `Alert`].enabled | [0]') && extract('caJsonFrom__logsJson__c').jsonQueryText('[? category == `Policy`].enabled | [0]') && extract('caJsonFrom__logsJson__c').jsonQueryText('[? category == `Security`].enabled | [0]'))",
      "runtimeError" : null
    }
  }, {
    "Id" : "test4",
    "expectedResult" : {
      "status" : "COMPLIANT",
      "conditionIndex" : "300",
      "conditionText" : "otherwise",
      "runtimeError" : null
    }
  }, {
    "Id" : "test5",
    "expectedResult" : {
      "status" : "INCOMPLIANT",
      "conditionIndex" : "299",
      "conditionText" : "not(extract('caJsonFrom__logsJson__c').jsonQueryText('[? category == `Administrative`].enabled | [0]') && extract('caJsonFrom__logsJson__c').jsonQueryText('[? category == `Alert`].enabled | [0]') && extract('caJsonFrom__logsJson__c').jsonQueryText('[? category == `Policy`].enabled | [0]') && extract('caJsonFrom__logsJson__c').jsonQueryText('[? category == `Security`].enabled | [0]'))",
      "runtimeError" : null
    }
  } ];
  """;

  CREATE TEMP FUNCTION mock_CA10__CaAzureDiagnosticSetting__c()
  RETURNS ARRAY<STRUCT<
      Id STRING,
      RecordTypeId STRING,
      CA10__disappearanceTime__c TIMESTAMP,
      CA10__logsJson__c STRING,
      context STRUCT<
          snapshotTime TIMESTAMP
      >
  >>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
    return [ {
    "context" : {
      "snapshotTime" : new Date("2024-05-29T03:06:28Z")
    },
    "Id" : "test1",
    "RecordTypeId" : "RecordTypeId1",
    "CA10__disappearanceTime__c" : new Date("2024-05-28T19:31:51Z"),
    "CA10__logsJson__c" : "[{\"category\": \"Security\",\"enabled\": true},{\"category\": \"Alert\",\"enabled\": true},{\"category\": \"Administrative\",\"enabled\": true},{\"category\": \"Policy\",\"enabled\": true}]"
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-05-29T03:06:28Z")
    },
    "Id" : "test2",
    "RecordTypeId" : "RecordTypeId2",
    "CA10__logsJson__c" : "[{\"category\": \"Security\",\"enabled\": true},{\"category\": \"Alert\",\"enabled\": true},{\"category\": \"Administrative\",\"enabled\": true},{\"category\": \"Policy\",\"enabled\": true}]"
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-05-29T03:06:28Z")
    },
    "Id" : "test3",
    "RecordTypeId" : "RecordTypeId3",
    "CA10__logsJson__c" : "[{\"category\": \"Security\",\"enabled\": false},{\"category\": \"Alert\",\"enabled\": false},{\"category\": \"Administrative\",\"enabled\": false},{\"category\": \"Policy\",\"enabled\": false}]"
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-05-29T03:06:28Z")
    },
    "Id" : "test4",
    "RecordTypeId" : "RecordTypeId4",
    "CA10__logsJson__c" : "[{\"category\": \"Security\",\"enabled\": true},{\"category\": \"Alert\",\"enabled\": true},{\"category\": \"Administrative\",\"enabled\": true},{\"category\": \"Policy\",\"enabled\": true}]"
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-05-29T03:06:28Z")
    },
    "Id" : "test5",
    "RecordTypeId" : "RecordTypeId5",
    "CA10__logsJson__c" : "[{\"category\": \"Security\",\"enabled\": false},{\"category\": \"Alert\",\"enabled\": true},{\"category\": \"Administrative\",\"enabled\": true},{\"category\": \"Policy\",\"enabled\": true}]"
  } ];
  """;

  CREATE TEMP FUNCTION mock_RecordType()
  RETURNS ARRAY<STRUCT<
      DeveloperName STRING,
      Id STRING,
      context STRUCT<
          snapshotTime TIMESTAMP
      >
  >>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
    return [ {
    "context" : {
      "snapshotTime" : new Date("2024-05-29T03:06:28Z")
    },
    "DeveloperName" : "caDiagnosticSettingOnAzureSubscription",
    "Id" : "RecordTypeId1"
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-05-29T03:06:28Z")
    },
    "DeveloperName" : "caDiagnosticSettingOnAzureResource",
    "Id" : "RecordTypeId2"
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-05-29T03:06:28Z")
    },
    "DeveloperName" : "caDiagnosticSettingOnAzureSubscription",
    "Id" : "RecordTypeId3"
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-05-29T03:06:28Z")
    },
    "DeveloperName" : "caDiagnosticSettingOnAzureSubscription",
    "Id" : "RecordTypeId4"
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-05-29T03:06:28Z")
    },
    "DeveloperName" : "caDiagnosticSettingOnAzureSubscription",
    "Id" : "RecordTypeId5"
  } ];
  """;

  CREATE TEMP FUNCTION process_CA10__CaAzureDiagnosticSetting__c(
      obj STRUCT<
          Id STRING,
          RecordTypeId STRING,
          CA10__disappearanceTime__c TIMESTAMP,
          CA10__logsJson__c STRING,
          RecordType STRUCT<
              DeveloperName STRING,
              Id 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));
          };
      }();
      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]
      references1.push('Record Type Name [obj.RecordType.DeveloperName]: ' + obj.RecordType.DeveloperName);
      if (TextLib.notEqual(obj.RecordType.DeveloperName, 'caDiagnosticSettingOnAzureSubscription')) {
          return {status: 'INAPPLICABLE', conditionIndex: 199, conditionText: "RecordType.DeveloperName != 'caDiagnosticSettingOnAzureSubscription'", currentStateMessage: "This is not a subscription Diagnostic Setting.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
      }
      // condition[2], conditionIndex:[200..299]
      function jsonQueryChecked3() {
          var input = extract5.call(extract5);
          var out;
          try {
              out = jmespath.search(input, '[? category == `Administrative`].enabled | [0]');
          if (out != null && typeof out != 'boolean') {
              throw new Error("UNDETERMINED condition:203", {cause: {status: 'UNDETERMINED', conditionIndex: 203, conditionText: "extract('caJsonFrom__logsJson__c').jsonQueryText('[? category == `Administrative`].enabled | [0]').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__logsJson__c').jsonQueryText('[? category == `Administrative`].enabled | [0]').isEvaluationFailed()", currentStateMessage: "The JSON query has failed.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: e.message}});
          }
          return out;
      }
      function jsonChecked6() {
          var input = extract8.call(extract8);
          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__logsJson__c').asJson().isInvalid()", currentStateMessage: "Logs JSON is invalid.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: e.message}});
          }
          return out;
      }
      function fieldChecked9() {
          if ((obj.CA10__logsJson__c == null || obj.CA10__logsJson__c == '')) {
              throw new Error("UNDETERMINED condition:201", {cause: {status: 'UNDETERMINED', conditionIndex: 201, conditionText: "CA10__logsJson__c.isEmpty()", currentStateMessage: "Corrupted Data. Diagnostic Setting Logs JSON cannot be empty.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}});
          }
          return obj.CA10__logsJson__c;
      }
      function extract8() { if (!this.out) { this.out = fieldChecked9(); } return this.out; };
      function extract5() { if (!this.out) { this.out = jsonChecked6(); } return this.out; };
      function jsonQueryChecked11() {
          var input = extract5.call(extract5);
          var out;
          try {
              out = jmespath.search(input, '[? category == `Alert`].enabled | [0]');
          if (out != null && typeof out != 'boolean') {
              throw new Error("UNDETERMINED condition:205", {cause: {status: 'UNDETERMINED', conditionIndex: 205, conditionText: "extract('caJsonFrom__logsJson__c').jsonQueryText('[? category == `Alert`].enabled | [0]').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:206", {cause: {status: 'UNDETERMINED', conditionIndex: 206, conditionText: "extract('caJsonFrom__logsJson__c').jsonQueryText('[? category == `Alert`].enabled | [0]').isEvaluationFailed()", currentStateMessage: "The JSON query has failed.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: e.message}});
          }
          return out;
      }
      function jsonQueryChecked13() {
          var input = extract5.call(extract5);
          var out;
          try {
              out = jmespath.search(input, '[? category == `Policy`].enabled | [0]');
          if (out != null && typeof out != 'boolean') {
              throw new Error("UNDETERMINED condition:207", {cause: {status: 'UNDETERMINED', conditionIndex: 207, conditionText: "extract('caJsonFrom__logsJson__c').jsonQueryText('[? category == `Policy`].enabled | [0]').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:208", {cause: {status: 'UNDETERMINED', conditionIndex: 208, conditionText: "extract('caJsonFrom__logsJson__c').jsonQueryText('[? category == `Policy`].enabled | [0]').isEvaluationFailed()", currentStateMessage: "The JSON query has failed.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: e.message}});
          }
          return out;
      }
      function jsonQueryChecked15() {
          var input = extract5.call(extract5);
          var out;
          try {
              out = jmespath.search(input, '[? category == `Security`].enabled | [0]');
          if (out != null && typeof out != 'boolean') {
              throw new Error("UNDETERMINED condition:209", {cause: {status: 'UNDETERMINED', conditionIndex: 209, conditionText: "extract('caJsonFrom__logsJson__c').jsonQueryText('[? category == `Security`].enabled | [0]').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:210", {cause: {status: 'UNDETERMINED', conditionIndex: 210, conditionText: "extract('caJsonFrom__logsJson__c').jsonQueryText('[? category == `Security`].enabled | [0]').isEvaluationFailed()", currentStateMessage: "The JSON query has failed.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: e.message}});
          }
          return out;
      }
      references1.push('Logs JSON [obj.CA10__logsJson__c]: ' + obj.CA10__logsJson__c);
      try {
          if (!(jsonQueryChecked3() && jsonQueryChecked11() && jsonQueryChecked13() && jsonQueryChecked15())) {
              return {status: 'INCOMPLIANT', conditionIndex: 299, conditionText: "not(extract('caJsonFrom__logsJson__c').jsonQueryText('[? category == `Administrative`].enabled | [0]') && extract('caJsonFrom__logsJson__c').jsonQueryText('[? category == `Alert`].enabled | [0]') && extract('caJsonFrom__logsJson__c').jsonQueryText('[? category == `Policy`].enabled | [0]') && extract('caJsonFrom__logsJson__c').jsonQueryText('[? category == `Security`].enabled | [0]'))", currentStateMessage: "The diagnostic setting does not capture the appropriate activities from the management plane.", currentStateReferences: references1.join('\n'), remediation: "Consider configuring the diagnostic setting to capture Administrative, Alert, Policy, and Security log categories.", runtimeError: null};
          }
      } catch (err) {
          if (err.cause && err.cause.status) { return err.cause; } else { throw err; }
      }
      return {status: 'COMPLIANT', conditionIndex: 300, conditionText: "otherwise", currentStateMessage: "The diagnostic setting captures the appropriate activities from the management plane.", 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,
          sObject.RecordTypeId AS RecordTypeId,
          sObject.CA10__disappearanceTime__c AS CA10__disappearanceTime__c,
          sObject.CA10__logsJson__c AS CA10__logsJson__c,
          STRUCT (
              `RecordType`.DeveloperName AS DeveloperName,
              `RecordType`.Id AS Id
          ) AS RecordType,
          process_CA10__CaAzureDiagnosticSetting__c(
              STRUCT(
                  sObject.Id AS Id,
                  sObject.RecordTypeId AS RecordTypeId,
                  sObject.CA10__disappearanceTime__c AS CA10__disappearanceTime__c,
                  sObject.CA10__logsJson__c AS CA10__logsJson__c,
                  STRUCT (
                      `RecordType`.DeveloperName AS DeveloperName,
                      `RecordType`.Id AS Id
                  ) AS RecordType
              ),
              sObject.context.snapshotTime
          ) as result
      FROM UNNEST(mock_CA10__CaAzureDiagnosticSetting__c()) AS sObject
      LEFT JOIN UNNEST(mock_RecordType()) AS `RecordType`
          ON sObject.RecordTypeId = `RecordType`.Id
  ) sObject ON sObject.Id = expectedResult.Id;
