---
policy: /ce/ca/azure/subscription/security-alert-notifications-for-alerts-with-high-severity
logic: /ce/ca/azure/subscription/security-alert-notifications-for-alerts-with-high-severity/prod.logic.yaml
executionTime: 2025-04-24T23:46:26.905041085Z
rows:
  - id: test1
    match: true
    status:
      expected: INCOMPLIANT
      actual: INCOMPLIANT
    conditionIndex:
      expected: 199
      actual: 199
    conditionText:
      expected: extract('caJsonQueryText__securityCenterContacts_default_alert_notifications__c').isEmpty()
      actual: extract('caJsonQueryText__securityCenterContacts_default_alert_notifications__c').isEmpty()
    runtimeError: {}
  - id: test2
    match: true
    status:
      expected: INCOMPLIANT
      actual: INCOMPLIANT
    conditionIndex:
      expected: 299
      actual: 299
    conditionText:
      expected: extract('caJsonQueryText__securityCenterContacts_default_alert_notifications__c')
        != 'On'
      actual: extract('caJsonQueryText__securityCenterContacts_default_alert_notifications__c')
        != 'On'
    runtimeError: {}
  - id: test3
    match: true
    status:
      expected: COMPLIANT
      actual: COMPLIANT
    conditionIndex:
      expected: 499
      actual: 499
    conditionText:
      expected: extract('caJsonQueryText__securityCenterContacts_default_alert_notifications_severity__c')
        == 'High' && extract('caJsonQueryText__securityCenterContacts_default_alert_notifications__c')
        == 'On'
      actual: extract('caJsonQueryText__securityCenterContacts_default_alert_notifications_severity__c')
        == 'High' && extract('caJsonQueryText__securityCenterContacts_default_alert_notifications__c')
        == 'On'
    runtimeError: {}
  - id: test4
    match: true
    status:
      expected: UNDETERMINED
      actual: UNDETERMINED
    conditionIndex:
      expected: 101
      actual: 101
    conditionText:
      expected: CA10__securityCenterContacts__c.delegatedTo(CA10__securityCenterContacts__c).isEmpty()
      actual: CA10__securityCenterContacts__c.delegatedTo(CA10__securityCenterContacts__c).isEmpty()
    runtimeError: {}
  - id: test5
    match: true
    status:
      expected: UNDETERMINED
      actual: UNDETERMINED
    conditionIndex:
      expected: 103
      actual: 103
    conditionText:
      expected: extract('CA10__securityCenterContacts__c').asJson().isInvalid()
      actual: extract('CA10__securityCenterContacts__c').asJson().isInvalid()
    runtimeError:
      expected: "Expected property name or '}' in JSON at position 1 (line 1 column\
        \ 2)"
      actual: "Expected property name or '}' in JSON at position 1 (line 1 column\
        \ 2)"
  - id: test6
    match: true
    status:
      expected: INCOMPLIANT
      actual: INCOMPLIANT
    conditionIndex:
      expected: 199
      actual: 199
    conditionText:
      expected: extract('caJsonQueryText__securityCenterContacts_default_alert_notifications__c').isEmpty()
      actual: extract('caJsonQueryText__securityCenterContacts_default_alert_notifications__c').isEmpty()
    runtimeError: {}
  - id: test7
    match: true
    status:
      expected: INCOMPLIANT
      actual: INCOMPLIANT
    conditionIndex:
      expected: 199
      actual: 199
    conditionText:
      expected: extract('caJsonQueryText__securityCenterContacts_default_alert_notifications__c').isEmpty()
      actual: extract('caJsonQueryText__securityCenterContacts_default_alert_notifications__c').isEmpty()
    runtimeError: {}
  - id: test8
    match: true
    status:
      expected: INCOMPLIANT
      actual: INCOMPLIANT
    conditionIndex:
      expected: 399
      actual: 399
    conditionText:
      expected: extract('caJsonQueryText__securityCenterContacts_default_alert_notifications_severity__c')
        != 'High'
      actual: extract('caJsonQueryText__securityCenterContacts_default_alert_notifications_severity__c')
        != 'High'
    runtimeError: {}
usedFiles:
  - path: /ce/ca/azure/subscription/security-alert-notifications-for-alerts-with-high-severity/policy.yaml
    md5Hash: D35C1CE1B8DF71F90F90FDDC4024619C
    content: |
      ---
      names:
        full: Azure Subscription Security Alert Notifications for alerts with High severity
          are not configured
        contextual: Security Alert Notifications for alerts with High severity is not configured
      description: Enables emailing security alerts to the subscription owner or other designated
        security contact.
      type: COMPLIANCE_POLICY
      categories:
        - SECURITY
      frameworkMappings:
        - "/frameworks/cis-azure-v2.1.0/02/01/19"
        - "/frameworks/cis-azure-v3.0.0/03/01/14"
        - "/frameworks/cloudaware/resource-security/microsoft-defender-configuration"
      similarPolicies:
        internal:
          - dec-x-ba4c5b1c
        cloudConformity:
          - url: https://www.trendmicro.com/cloudoneconformity/knowledge-base/azure/SecurityCenter/email-notification-for-alerts.html
            name: Email Notification for Alerts
  - path: /ce/ca/azure/subscription/security-alert-notifications-for-alerts-with-high-severity/prod.logic.yaml
    md5Hash: 80023100CBFCD586D792966D318FC9CE
    content: "---\ninputType: \"CA10__CaAzureAccount__c\"\ntestData:\n  - file: \"\
      test-data.json\"\nimportExtracts:\n  - file: \"/types/CA10__CaAzureAccount__c/object.extracts.yaml\"\
      \nconditions:\n  - status: \"INCOMPLIANT\"\n    currentStateMessage: \"Security\
      \ notifications emailing is not enabled.\"\n    remediationMessage: \"Consider\
      \ enabling security notifications emailing to the subscription owner or other\
      \ designated security contact.\"\n# Extract only for the default contact\n \
      \   check:\n      IS_EMPTY:\n        arg:\n          EXTRACT: \"caJsonQueryText__securityCenterContacts_default_alert_notifications__c\"\
      \n  - status: \"INCOMPLIANT\"\n    currentStateMessage: \"Security notifications\
      \ emailing is not enabled.\"\n    remediationMessage: \"Consider enabling security\
      \ notifications emailing to the subscription owner or other designated security\
      \ contact.\"\n# Extract only for the default contact\n    check:\n      NOT_EQUAL:\n\
      \        left:\n          EXTRACT: \"caJsonQueryText__securityCenterContacts_default_alert_notifications__c\"\
      \n        right: \n          TEXT: \"On\"\n  - status: \"INCOMPLIANT\"\n   \
      \ currentStateMessage: \"Security notifications for alerts with High severity\
      \ is not set.\"\n    remediationMessage: \"Consider enabling security notifications\
      \ for alerts with High severity.\"\n# Extract only for the default contact\n\
      \    check:\n      NOT_EQUAL:\n        left:\n          EXTRACT: \"caJsonQueryText__securityCenterContacts_default_alert_notifications_severity__c\"\
      \n        right: \n          TEXT: \"High\"\n  - status: \"COMPLIANT\"\n   \
      \ currentStateMessage: \"Security alerts emailing is not enabled.\"\n# Extract\
      \ only for the default contact\n    check:\n      AND:\n        args:\n    \
      \      - IS_EQUAL:\n              left:\n                EXTRACT: \"caJsonQueryText__securityCenterContacts_default_alert_notifications_severity__c\"\
      \n              right: \n                TEXT: \"High\"\n          - IS_EQUAL:\n\
      \              left:\n                EXTRACT: \"caJsonQueryText__securityCenterContacts_default_alert_notifications__c\"\
      \n              right: \n                TEXT: \"On\"\notherwise:\n  status:\
      \ \"UNDETERMINED\"\n  currentStateMessage: \"Unexpected values in the fields.\"\
      \ "
  - path: /types/CA10__CaAzureAccount__c/object.extracts.yaml
    md5Hash: 9C78116D7D6EA5327842D3BC5DCF8980
    content: "---\nextracts:\n# Not Nullable.\n  - name: \"CA10__availableLocationNames__c\"\
      \n    value: \n      FIELD:\n        path: \"CA10__availableLocationNames__c\"\
      \n        undeterminedIf:\n          noAccessDelegate:\n            path: \"\
      CA10__availableLocationNames__c\"\n            currentStateMessage: \"Unable\
      \ to determine Subscription Available Locations. Possible permission issue withMicrosoft.Resources/subscriptions/locations/read\"\
      \n  - name: \"caJsonFrom_availableLocationNames__c\"\n    value:\n      JSON_FROM:\n\
      \        arg:\n          EXTRACT: \"CA10__availableLocationNames__c\"\n    \
      \    undeterminedIf:\n          isInvalid: \"Subscription Available Locations\
      \ JSON is invalid.\"\n  - name: \"CA10__subscriptionId__c\"\n    value: \n \
      \     FIELD:\n        path: \"CA10__subscriptionId__c\"\n        undeterminedIf:\n\
      \          isEmpty: \"Corrupted data. Subscription ID cannot be empty.\"\n#\
      \ Not Nullable\n  - name: \"CA10__securityCenterAutoProvisioning__c\"\n    value:\
      \ \n      FIELD:\n        path: \"CA10__securityCenterAutoProvisioning__c\"\n\
      \        returnType: BYTES\n        undeterminedIf:\n          noAccessDelegate:\n\
      \            path: \"CA10__securityCenterAutoProvisioning__c\"\n           \
      \ currentStateMessage: \"Unable to determine Auto Provisioning Settings. Possible\
      \ permission issue with Microsoft.Security/autoProvisioningSettings\" \n# Not\
      \ Nullable\n  - name: \"CA10__securityCenterContacts__c\"\n    value: \n   \
      \   FIELD:\n        path: \"CA10__securityCenterContacts__c\"\n        returnType:\
      \ BYTES\n        undeterminedIf:\n          noAccessDelegate:\n            path:\
      \ \"CA10__securityCenterContacts__c\"\n            currentStateMessage: \"Unable\
      \ to determine Security Contacts. Possible permission issue with Microsoft.Security/securityContacts\"\
      \ \n  - name: \"caJsonFrom__securityCenterContacts__c\"\n    value: \n     \
      \ JSON_FROM:\n        arg: \n          EXTRACT: \"CA10__securityCenterContacts__c\"\
      \n        undeterminedIf:\n          isInvalid: \"Security Center Contacts JSON\
      \ is invalid.\"\n          isEmpty: \"Unable to determine Security Contacts.\
      \ Possible permission issue with Microsoft.Security/securityContacts\"\n# Security\
      \ Center: Contacts properties.notificationsByRole roles for the default contact\n\
      # notificationsByRoleRoles is a string that contains roles separated by comma\n\
      # Values: AccountAdmin, Contributor, Owner, ServiceAdmin.\n  - name: \"caJsonQueryBoolean__securityCenterContacts_default_roles__c\"\
      \n    value: \n      JSON_QUERY_TEXT:\n        arg: \n          EXTRACT: \"\
      caJsonFrom__securityCenterContacts__c\"\n        expression: \"to_string([?\
      \ name == 'default'].notificationsByRoleRoles | [0])\"\n        undeterminedIf:\
      \ \n          evaluationError: \"The JSON query has failed.\"\n          resultTypeMismatch:\
      \ \"The JSON query did not return text type.\"\n# Security Center: Contacts\
      \ properties.notificationsByRole state for the default contact\n# Values: On,\
      \ Off.\n  - name: \"caJsonQueryText__securityCenterContacts_default_state__c\"\
      \n    value: \n      JSON_QUERY_TEXT:\n        arg: \n          EXTRACT: \"\
      caJsonFrom__securityCenterContacts__c\"\n        expression: \"[? name == 'default'].notificationsByRoleState\
      \ | [0]\"\n        undeterminedIf: \n          evaluationError: \"The JSON query\
      \ has failed.\"\n          resultTypeMismatch: \"The JSON query did not return\
      \ text type.\"\n# Security Center: Contacts email for the default contact\n\
      # email is a string that contains values separated by comma\n  - name: \"caJsonQueryText__securityCenterContacts_default_email__c\"\
      \n    value: \n      JSON_QUERY_TEXT:\n        arg: \n          EXTRACT: \"\
      caJsonFrom__securityCenterContacts__c\"\n        expression: \"[? name == 'default'\
      \ && email != ''].email | [0]\"\n        undeterminedIf: \n          evaluationError:\
      \ \"The JSON query has failed.\"\n          resultTypeMismatch: \"The JSON query\
      \ did not return text type.\"\n# Values: On, Off.\n  - name: \"caJsonQueryText__securityCenterContacts_default_alert_notifications__c\"\
      \n    value: \n      JSON_QUERY_TEXT:\n        arg: \n          EXTRACT: \"\
      caJsonFrom__securityCenterContacts__c\"\n        expression: \"[? name == 'default'].alertNotifications\
      \ | [0]\"\n        undeterminedIf: \n          evaluationError: \"The JSON query\
      \ has failed.\"\n          resultTypeMismatch: \"The JSON query did not return\
      \ text type.\"\n# Values: High, Medium, Low.\n  - name: \"caJsonQueryText__securityCenterContacts_default_alert_notifications_severity__c\"\
      \n    value: \n      JSON_QUERY_TEXT:\n        arg: \n          EXTRACT: \"\
      caJsonFrom__securityCenterContacts__c\"\n        expression: \"[? name == 'default'].alertNotificationsMinimalSeverity\
      \ | [0]\"\n        undeterminedIf: \n          evaluationError: \"The JSON query\
      \ has failed.\"\n          resultTypeMismatch: \"The JSON query did not return\
      \ text type.\"\n# Not Nullable\n  - name: \"CA10__defenderForCloudSettingsJson__c\"\
      \n    value: \n      FIELD:\n        path: \"CA10__defenderForCloudSettingsJson__c\"\
      \n        undeterminedIf:\n          noAccessDelegate:\n            path: \"\
      CA10__defenderForCloudSettingsJson__c\"\n            currentStateMessage: \"\
      Unable to determine Microsoft Defender for Cloud Settings. Possible permission\
      \ issue with Microsoft.Security/settings\" \n  - name: \"caJsonFrom__defenderForCloudSettings__c\"\
      \n    value: \n      JSON_FROM:\n        arg: \n          EXTRACT: \"CA10__defenderForCloudSettingsJson__c\"\
      \n        undeterminedIf:\n          isInvalid: \"Security Center Contacts JSON\
      \ is invalid.\"\n          isEmpty: \"Unable to determine Security Contacts.\
      \ Possible permission issue with Microsoft.Security/settings\""
  - path: /ce/ca/azure/subscription/security-alert-notifications-for-alerts-with-high-severity/test-data.json
    md5Hash: 5415B05C9EF8937453325A9070DB02E3
    content: |-
      [
          {
              "expectedResult": {
                  "status": "INCOMPLIANT",
                  "conditionIndex": "199",
                  "conditionText": "extract('caJsonQueryText__securityCenterContacts_default_alert_notifications__c').isEmpty()",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2024-06-25T20:34:10Z"
              },
              "Id": "test1",
              "CA10__securityCenterContacts__c": "[]"
          },
          {
              "expectedResult": {
                  "status": "INCOMPLIANT",
                  "conditionIndex": "299",
                  "conditionText": "extract('caJsonQueryText__securityCenterContacts_default_alert_notifications__c') != 'On'",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2024-06-25T20:34:10Z"
              },
              "Id": "test2",
              "CA10__securityCenterContacts__c": "[{\"name\":\"default\",\"email\":\"\",\"phone\":\"\",\"alertNotifications\":\"Off\",\"alertsToAdmins\":\"Off\",\"alertNotificationsMinimalSeverity\":\"High\",\"notificationsByRoleState\":\"Off\",\"notificationsByRoleRoles\":\"\"}]"
          },
          {
              "expectedResult": {
                  "status": "COMPLIANT",
                  "conditionIndex": "499",
                  "conditionText": "extract('caJsonQueryText__securityCenterContacts_default_alert_notifications_severity__c') == 'High' && extract('caJsonQueryText__securityCenterContacts_default_alert_notifications__c') == 'On'",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2024-06-25T20:34:10Z"
              },
              "Id": "test3",
              "CA10__securityCenterContacts__c": "[{\"name\":\"default\",\"email\":\"\",\"phone\":\"\",\"alertNotifications\":\"On\",\"alertsToAdmins\":\"Off\",\"alertNotificationsMinimalSeverity\":\"High\",\"notificationsByRoleState\":\"On\",\"notificationsByRoleRoles\":\"Owner\"}]"
          },
          {
              "expectedResult": {
                  "status": "UNDETERMINED",
                  "conditionIndex": "101",
                  "conditionText": "CA10__securityCenterContacts__c.delegatedTo(CA10__securityCenterContacts__c).isEmpty()",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2024-06-13T04:17:29Z"
              },
              "Id": "test4",
              "CA10__securityCenterContacts__c": null
          },
          {
              "expectedResult": {
                  "status": "UNDETERMINED",
                  "conditionIndex": "103",
                  "conditionText": "extract('CA10__securityCenterContacts__c').asJson().isInvalid()",
                  "runtimeError": "Expected property name or '}' in JSON at position 1 (line 1 column 2)"
              },
              "context": {
                  "snapshotTime": "2024-06-13T04:17:29Z"
              },
              "Id": "test5",
              "CA10__securityCenterContacts__c": "{"
          },
          {
              "expectedResult": {
                  "status": "INCOMPLIANT",
                  "conditionIndex": "199",
                  "conditionText": "extract('caJsonQueryText__securityCenterContacts_default_alert_notifications__c').isEmpty()",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2024-06-13T04:17:29Z"
              },
              "Id": "test6",
              "CA10__securityCenterContacts__c": "[{\"name\":\"default\"}]"
          },
          {
              "expectedResult": {
                  "status": "INCOMPLIANT",
                  "conditionIndex": "199",
                  "conditionText": "extract('caJsonQueryText__securityCenterContacts_default_alert_notifications__c').isEmpty()",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2024-06-13T04:17:29Z"
              },
              "Id": "test7",
              "CA10__securityCenterContacts__c": "[{\"name\":\"default\",\"alertNotifications\":\"\"}]"
          },
          {
              "expectedResult": {
                  "status": "INCOMPLIANT",
                  "conditionIndex": "399",
                  "conditionText": "extract('caJsonQueryText__securityCenterContacts_default_alert_notifications_severity__c') != 'High'",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2024-06-25T20:34:10Z"
              },
              "Id": "test8",
              "CA10__securityCenterContacts__c": "[{\"name\":\"default\",\"email\":\"\",\"phone\":\"\",\"alertNotifications\":\"On\",\"alertsToAdmins\":\"Off\",\"alertNotificationsMinimalSeverity\":\"Low\",\"notificationsByRoleState\":\"Off\",\"notificationsByRoleRoles\":\"\"}]"
          }
      ]
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" : "INCOMPLIANT",
      "conditionIndex" : "199",
      "conditionText" : "extract('caJsonQueryText__securityCenterContacts_default_alert_notifications__c').isEmpty()",
      "runtimeError" : null
    }
  }, {
    "Id" : "test2",
    "expectedResult" : {
      "status" : "INCOMPLIANT",
      "conditionIndex" : "299",
      "conditionText" : "extract('caJsonQueryText__securityCenterContacts_default_alert_notifications__c') != 'On'",
      "runtimeError" : null
    }
  }, {
    "Id" : "test3",
    "expectedResult" : {
      "status" : "COMPLIANT",
      "conditionIndex" : "499",
      "conditionText" : "extract('caJsonQueryText__securityCenterContacts_default_alert_notifications_severity__c') == 'High' && extract('caJsonQueryText__securityCenterContacts_default_alert_notifications__c') == 'On'",
      "runtimeError" : null
    }
  }, {
    "Id" : "test4",
    "expectedResult" : {
      "status" : "UNDETERMINED",
      "conditionIndex" : "101",
      "conditionText" : "CA10__securityCenterContacts__c.delegatedTo(CA10__securityCenterContacts__c).isEmpty()",
      "runtimeError" : null
    }
  }, {
    "Id" : "test5",
    "expectedResult" : {
      "status" : "UNDETERMINED",
      "conditionIndex" : "103",
      "conditionText" : "extract('CA10__securityCenterContacts__c').asJson().isInvalid()",
      "runtimeError" : "Expected property name or '}' in JSON at position 1 (line 1 column 2)"
    }
  }, {
    "Id" : "test6",
    "expectedResult" : {
      "status" : "INCOMPLIANT",
      "conditionIndex" : "199",
      "conditionText" : "extract('caJsonQueryText__securityCenterContacts_default_alert_notifications__c').isEmpty()",
      "runtimeError" : null
    }
  }, {
    "Id" : "test7",
    "expectedResult" : {
      "status" : "INCOMPLIANT",
      "conditionIndex" : "199",
      "conditionText" : "extract('caJsonQueryText__securityCenterContacts_default_alert_notifications__c').isEmpty()",
      "runtimeError" : null
    }
  }, {
    "Id" : "test8",
    "expectedResult" : {
      "status" : "INCOMPLIANT",
      "conditionIndex" : "399",
      "conditionText" : "extract('caJsonQueryText__securityCenterContacts_default_alert_notifications_severity__c') != 'High'",
      "runtimeError" : null
    }
  } ];
  """;

  CREATE TEMP FUNCTION mock_CA10__CaAzureAccount__c()
  RETURNS ARRAY<STRUCT<
      Id STRING,
      CA10__securityCenterContacts__c STRING,
      context STRUCT<
          snapshotTime TIMESTAMP
      >
  >>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
    return [ {
    "context" : {
      "snapshotTime" : new Date("2024-06-25T20:34:10Z")
    },
    "Id" : "test1",
    "CA10__securityCenterContacts__c" : "[]"
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-06-25T20:34:10Z")
    },
    "Id" : "test2",
    "CA10__securityCenterContacts__c" : "[{\"name\":\"default\",\"email\":\"\",\"phone\":\"\",\"alertNotifications\":\"Off\",\"alertsToAdmins\":\"Off\",\"alertNotificationsMinimalSeverity\":\"High\",\"notificationsByRoleState\":\"Off\",\"notificationsByRoleRoles\":\"\"}]"
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-06-25T20:34:10Z")
    },
    "Id" : "test3",
    "CA10__securityCenterContacts__c" : "[{\"name\":\"default\",\"email\":\"\",\"phone\":\"\",\"alertNotifications\":\"On\",\"alertsToAdmins\":\"Off\",\"alertNotificationsMinimalSeverity\":\"High\",\"notificationsByRoleState\":\"On\",\"notificationsByRoleRoles\":\"Owner\"}]"
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-06-13T04:17:29Z")
    },
    "Id" : "test4",
    "CA10__securityCenterContacts__c" : null
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-06-13T04:17:29Z")
    },
    "Id" : "test5",
    "CA10__securityCenterContacts__c" : "{"
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-06-13T04:17:29Z")
    },
    "Id" : "test6",
    "CA10__securityCenterContacts__c" : "[{\"name\":\"default\"}]"
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-06-13T04:17:29Z")
    },
    "Id" : "test7",
    "CA10__securityCenterContacts__c" : "[{\"name\":\"default\",\"alertNotifications\":\"\"}]"
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-06-25T20:34:10Z")
    },
    "Id" : "test8",
    "CA10__securityCenterContacts__c" : "[{\"name\":\"default\",\"email\":\"\",\"phone\":\"\",\"alertNotifications\":\"On\",\"alertsToAdmins\":\"Off\",\"alertNotificationsMinimalSeverity\":\"Low\",\"notificationsByRoleState\":\"Off\",\"notificationsByRoleRoles\":\"\"}]"
  } ];
  """;

  CREATE TEMP FUNCTION process_CA10__CaAzureAccount__c(
      obj STRUCT<
          Id STRING,
          CA10__securityCenterContacts__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));
          };
      }();
      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};
      }
      // condition[1], conditionIndex:[100..199]
      function jsonQueryChecked4() {
          var input = extract6.call(extract6);
          var out;
          try {
              out = jmespath.search(input, '[? name == \'default\'].alertNotifications | [0]');
          if (out != null && typeof out != 'string') {
              throw new Error("UNDETERMINED condition:104", {cause: {status: 'UNDETERMINED', conditionIndex: 104, conditionText: "extract('caJsonFrom__securityCenterContacts__c').jsonQueryText('[? name == \\'default\\'].alertNotifications | [0]').isResultTypeMismatch()", currentStateMessage: "The JSON query did not return text type.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}});
          }
          } catch (e) {
              throw new Error("UNDETERMINED condition:105", {cause: {status: 'UNDETERMINED', conditionIndex: 105, conditionText: "extract('caJsonFrom__securityCenterContacts__c').jsonQueryText('[? name == \\'default\\'].alertNotifications | [0]').isEvaluationFailed()", currentStateMessage: "The JSON query has failed.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: e.message}});
          }
          return out;
      }
      function jsonChecked7() {
          var input = extract9.call(extract9);
          if (TextLib.isEmpty(input)) {
              throw new Error("UNDETERMINED condition:102", {cause: {status: 'UNDETERMINED', conditionIndex: 102, conditionText: "extract('CA10__securityCenterContacts__c').asJson().isEmpty()", currentStateMessage: "Unable to determine Security Contacts. Possible permission issue with Microsoft.Security/securityContacts", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}});
          }
          var out;
          try {
              out = JSON.parse(input);
          } catch (e) {
              throw new Error("UNDETERMINED condition:103", {cause: {status: 'UNDETERMINED', conditionIndex: 103, conditionText: "extract('CA10__securityCenterContacts__c').asJson().isInvalid()", currentStateMessage: "Security Center Contacts JSON is invalid.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: e.message}});
          }
          return out;
      }
      function fieldChecked10() {
          if ((obj.CA10__securityCenterContacts__c == null || obj.CA10__securityCenterContacts__c == '')) {
              throw new Error("UNDETERMINED condition:101", {cause: {status: 'UNDETERMINED', conditionIndex: 101, conditionText: "CA10__securityCenterContacts__c.delegatedTo(CA10__securityCenterContacts__c).isEmpty()", currentStateMessage: "Unable to determine Security Contacts. Possible permission issue with Microsoft.Security/securityContacts", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}});
          }
          return obj.CA10__securityCenterContacts__c;
      }
      function extract9() { if (!this.out) { this.out = fieldChecked10(); } return this.out; };
      function extract6() { if (!this.out) { this.out = jsonChecked7(); } return this.out; };
      function extract3() { if (!this.out) { this.out = jsonQueryChecked4(); } return this.out; };
      references1.push('Security Center: Contacts [obj.CA10__securityCenterContacts__c]: ' + obj.CA10__securityCenterContacts__c);
      try {
          if (TextLib.isEmpty(extract3.call(extract3))) {
              return {status: 'INCOMPLIANT', conditionIndex: 199, conditionText: "extract('caJsonQueryText__securityCenterContacts_default_alert_notifications__c').isEmpty()", currentStateMessage: "Security notifications emailing is not enabled.", currentStateReferences: references1.join('\n'), remediation: "Consider enabling security notifications emailing to the subscription owner or other designated security contact.", runtimeError: null};
          }
      } catch (err) {
          if (err.cause && err.cause.status) { return err.cause; } else { throw err; }
      }
      // condition[2], conditionIndex:[200..299]
      function jsonQueryChecked14() {
          var input = extract16.call(extract16);
          var out;
          try {
              out = jmespath.search(input, '[? name == \'default\'].alertNotifications | [0]');
          if (out != null && typeof out != 'string') {
              throw new Error("UNDETERMINED condition:204", {cause: {status: 'UNDETERMINED', conditionIndex: 204, conditionText: "extract('caJsonFrom__securityCenterContacts__c').jsonQueryText('[? name == \\'default\\'].alertNotifications | [0]').isResultTypeMismatch()", currentStateMessage: "The JSON query did not return text type.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}});
          }
          } catch (e) {
              throw new Error("UNDETERMINED condition:205", {cause: {status: 'UNDETERMINED', conditionIndex: 205, conditionText: "extract('caJsonFrom__securityCenterContacts__c').jsonQueryText('[? name == \\'default\\'].alertNotifications | [0]').isEvaluationFailed()", currentStateMessage: "The JSON query has failed.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: e.message}});
          }
          return out;
      }
      function jsonChecked17() {
          var input = extract19.call(extract19);
          if (TextLib.isEmpty(input)) {
              throw new Error("UNDETERMINED condition:202", {cause: {status: 'UNDETERMINED', conditionIndex: 202, conditionText: "extract('CA10__securityCenterContacts__c').asJson().isEmpty()", currentStateMessage: "Unable to determine Security Contacts. Possible permission issue with Microsoft.Security/securityContacts", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}});
          }
          var out;
          try {
              out = JSON.parse(input);
          } catch (e) {
              throw new Error("UNDETERMINED condition:203", {cause: {status: 'UNDETERMINED', conditionIndex: 203, conditionText: "extract('CA10__securityCenterContacts__c').asJson().isInvalid()", currentStateMessage: "Security Center Contacts JSON is invalid.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: e.message}});
          }
          return out;
      }
      function fieldChecked20() {
          if ((obj.CA10__securityCenterContacts__c == null || obj.CA10__securityCenterContacts__c == '')) {
              throw new Error("UNDETERMINED condition:201", {cause: {status: 'UNDETERMINED', conditionIndex: 201, conditionText: "CA10__securityCenterContacts__c.delegatedTo(CA10__securityCenterContacts__c).isEmpty()", currentStateMessage: "Unable to determine Security Contacts. Possible permission issue with Microsoft.Security/securityContacts", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}});
          }
          return obj.CA10__securityCenterContacts__c;
      }
      function extract19() { if (!this.out) { this.out = fieldChecked20(); } return this.out; };
      function extract16() { if (!this.out) { this.out = jsonChecked17(); } return this.out; };
      function extract13() { if (!this.out) { this.out = jsonQueryChecked14(); } return this.out; };
      try {
          if (TextLib.notEqual(extract13.call(extract13), 'On')) {
              return {status: 'INCOMPLIANT', conditionIndex: 299, conditionText: "extract('caJsonQueryText__securityCenterContacts_default_alert_notifications__c') != 'On'", currentStateMessage: "Security notifications emailing is not enabled.", currentStateReferences: references1.join('\n'), remediation: "Consider enabling security notifications emailing to the subscription owner or other designated security contact.", runtimeError: null};
          }
      } catch (err) {
          if (err.cause && err.cause.status) { return err.cause; } else { throw err; }
      }
      // condition[3], conditionIndex:[300..399]
      function jsonQueryChecked24() {
          var input = extract26.call(extract26);
          var out;
          try {
              out = jmespath.search(input, '[? name == \'default\'].alertNotificationsMinimalSeverity | [0]');
          if (out != null && typeof out != 'string') {
              throw new Error("UNDETERMINED condition:304", {cause: {status: 'UNDETERMINED', conditionIndex: 304, conditionText: "extract('caJsonFrom__securityCenterContacts__c').jsonQueryText('[? name == \\'default\\'].alertNotificationsMinimalSeverity | [0]').isResultTypeMismatch()", currentStateMessage: "The JSON query did not return text type.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}});
          }
          } catch (e) {
              throw new Error("UNDETERMINED condition:305", {cause: {status: 'UNDETERMINED', conditionIndex: 305, conditionText: "extract('caJsonFrom__securityCenterContacts__c').jsonQueryText('[? name == \\'default\\'].alertNotificationsMinimalSeverity | [0]').isEvaluationFailed()", currentStateMessage: "The JSON query has failed.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: e.message}});
          }
          return out;
      }
      function jsonChecked27() {
          var input = extract29.call(extract29);
          if (TextLib.isEmpty(input)) {
              throw new Error("UNDETERMINED condition:302", {cause: {status: 'UNDETERMINED', conditionIndex: 302, conditionText: "extract('CA10__securityCenterContacts__c').asJson().isEmpty()", currentStateMessage: "Unable to determine Security Contacts. Possible permission issue with Microsoft.Security/securityContacts", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}});
          }
          var out;
          try {
              out = JSON.parse(input);
          } catch (e) {
              throw new Error("UNDETERMINED condition:303", {cause: {status: 'UNDETERMINED', conditionIndex: 303, conditionText: "extract('CA10__securityCenterContacts__c').asJson().isInvalid()", currentStateMessage: "Security Center Contacts JSON is invalid.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: e.message}});
          }
          return out;
      }
      function fieldChecked30() {
          if ((obj.CA10__securityCenterContacts__c == null || obj.CA10__securityCenterContacts__c == '')) {
              throw new Error("UNDETERMINED condition:301", {cause: {status: 'UNDETERMINED', conditionIndex: 301, conditionText: "CA10__securityCenterContacts__c.delegatedTo(CA10__securityCenterContacts__c).isEmpty()", currentStateMessage: "Unable to determine Security Contacts. Possible permission issue with Microsoft.Security/securityContacts", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}});
          }
          return obj.CA10__securityCenterContacts__c;
      }
      function extract29() { if (!this.out) { this.out = fieldChecked30(); } return this.out; };
      function extract26() { if (!this.out) { this.out = jsonChecked27(); } return this.out; };
      function extract23() { if (!this.out) { this.out = jsonQueryChecked24(); } return this.out; };
      try {
          if (TextLib.notEqual(extract23.call(extract23), 'High')) {
              return {status: 'INCOMPLIANT', conditionIndex: 399, conditionText: "extract('caJsonQueryText__securityCenterContacts_default_alert_notifications_severity__c') != 'High'", currentStateMessage: "Security notifications for alerts with High severity is not set.", currentStateReferences: references1.join('\n'), remediation: "Consider enabling security notifications for alerts with High severity.", runtimeError: null};
          }
      } catch (err) {
          if (err.cause && err.cause.status) { return err.cause; } else { throw err; }
      }
      // condition[4], conditionIndex:[400..499]
      function jsonQueryChecked34() {
          var input = extract36.call(extract36);
          var out;
          try {
              out = jmespath.search(input, '[? name == \'default\'].alertNotificationsMinimalSeverity | [0]');
          if (out != null && typeof out != 'string') {
              throw new Error("UNDETERMINED condition:404", {cause: {status: 'UNDETERMINED', conditionIndex: 404, conditionText: "extract('caJsonFrom__securityCenterContacts__c').jsonQueryText('[? name == \\'default\\'].alertNotificationsMinimalSeverity | [0]').isResultTypeMismatch()", currentStateMessage: "The JSON query did not return text type.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}});
          }
          } catch (e) {
              throw new Error("UNDETERMINED condition:405", {cause: {status: 'UNDETERMINED', conditionIndex: 405, conditionText: "extract('caJsonFrom__securityCenterContacts__c').jsonQueryText('[? name == \\'default\\'].alertNotificationsMinimalSeverity | [0]').isEvaluationFailed()", currentStateMessage: "The JSON query has failed.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: e.message}});
          }
          return out;
      }
      function jsonChecked37() {
          var input = extract39.call(extract39);
          if (TextLib.isEmpty(input)) {
              throw new Error("UNDETERMINED condition:402", {cause: {status: 'UNDETERMINED', conditionIndex: 402, conditionText: "extract('CA10__securityCenterContacts__c').asJson().isEmpty()", currentStateMessage: "Unable to determine Security Contacts. Possible permission issue with Microsoft.Security/securityContacts", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}});
          }
          var out;
          try {
              out = JSON.parse(input);
          } catch (e) {
              throw new Error("UNDETERMINED condition:403", {cause: {status: 'UNDETERMINED', conditionIndex: 403, conditionText: "extract('CA10__securityCenterContacts__c').asJson().isInvalid()", currentStateMessage: "Security Center Contacts JSON is invalid.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: e.message}});
          }
          return out;
      }
      function fieldChecked40() {
          if ((obj.CA10__securityCenterContacts__c == null || obj.CA10__securityCenterContacts__c == '')) {
              throw new Error("UNDETERMINED condition:401", {cause: {status: 'UNDETERMINED', conditionIndex: 401, conditionText: "CA10__securityCenterContacts__c.delegatedTo(CA10__securityCenterContacts__c).isEmpty()", currentStateMessage: "Unable to determine Security Contacts. Possible permission issue with Microsoft.Security/securityContacts", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}});
          }
          return obj.CA10__securityCenterContacts__c;
      }
      function extract39() { if (!this.out) { this.out = fieldChecked40(); } return this.out; };
      function extract36() { if (!this.out) { this.out = jsonChecked37(); } return this.out; };
      function extract33() { if (!this.out) { this.out = jsonQueryChecked34(); } return this.out; };
      function jsonQueryChecked44() {
          var input = extract36.call(extract36);
          var out;
          try {
              out = jmespath.search(input, '[? name == \'default\'].alertNotifications | [0]');
          if (out != null && typeof out != 'string') {
              throw new Error("UNDETERMINED condition:406", {cause: {status: 'UNDETERMINED', conditionIndex: 406, conditionText: "extract('caJsonFrom__securityCenterContacts__c').jsonQueryText('[? name == \\'default\\'].alertNotifications | [0]').isResultTypeMismatch()", currentStateMessage: "The JSON query did not return text type.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}});
          }
          } catch (e) {
              throw new Error("UNDETERMINED condition:407", {cause: {status: 'UNDETERMINED', conditionIndex: 407, conditionText: "extract('caJsonFrom__securityCenterContacts__c').jsonQueryText('[? name == \\'default\\'].alertNotifications | [0]').isEvaluationFailed()", currentStateMessage: "The JSON query has failed.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: e.message}});
          }
          return out;
      }
      function extract43() { if (!this.out) { this.out = jsonQueryChecked44(); } return this.out; };
      try {
          if (TextLib.equal(extract33.call(extract33), 'High') && TextLib.equal(extract43.call(extract43), 'On')) {
              return {status: 'COMPLIANT', conditionIndex: 499, conditionText: "extract('caJsonQueryText__securityCenterContacts_default_alert_notifications_severity__c') == 'High' && extract('caJsonQueryText__securityCenterContacts_default_alert_notifications__c') == 'On'", currentStateMessage: "Security alerts emailing is not enabled.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
          }
      } catch (err) {
          if (err.cause && err.cause.status) { return err.cause; } else { throw err; }
      }
      return {status: 'UNDETERMINED', conditionIndex: 500, conditionText: "otherwise", currentStateMessage: "Unexpected values in the fields.", 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.CA10__securityCenterContacts__c AS CA10__securityCenterContacts__c,
          process_CA10__CaAzureAccount__c(
              STRUCT(
                  sObject.Id AS Id,
                  sObject.CA10__securityCenterContacts__c AS CA10__securityCenterContacts__c
              ),
              sObject.context.snapshotTime
          ) as result
      FROM UNNEST(mock_CA10__CaAzureAccount__c()) AS sObject
  ) sObject ON sObject.Id = expectedResult.Id;
