---
policy: /ce/ca/azure/subscription/activity-log-alert-for-delete-public-ip-address-rule
logic: /ce/ca/azure/subscription/activity-log-alert-for-delete-public-ip-address-rule/prod.logic.yaml
executionTime: 2025-04-24T23:46:10.455572719Z
rows:
  - id: test1
    match: true
    status:
      expected: INCOMPLIANT
      actual: INCOMPLIANT
    conditionIndex:
      expected: 200
      actual: 200
    conditionText:
      expected: otherwise
      actual: otherwise
    runtimeError: {}
  - id: test2
    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: test3
    match: true
    status:
      expected: INCOMPLIANT
      actual: INCOMPLIANT
    conditionIndex:
      expected: 200
      actual: 200
    conditionText:
      expected: otherwise
      actual: otherwise
    runtimeError: {}
  - id: test4
    match: true
    status:
      expected: INCOMPLIANT
      actual: INCOMPLIANT
    conditionIndex:
      expected: 200
      actual: 200
    conditionText:
      expected: otherwise
      actual: otherwise
    runtimeError: {}
  - id: test5
    match: true
    status:
      expected: INCOMPLIANT
      actual: INCOMPLIANT
    conditionIndex:
      expected: 200
      actual: 200
    conditionText:
      expected: otherwise
      actual: otherwise
    runtimeError: {}
  - id: test6
    match: true
    status:
      expected: INCOMPLIANT
      actual: INCOMPLIANT
    conditionIndex:
      expected: 200
      actual: 200
    conditionText:
      expected: otherwise
      actual: otherwise
    runtimeError: {}
  - id: test7
    match: true
    status:
      expected: INCOMPLIANT
      actual: INCOMPLIANT
    conditionIndex:
      expected: 200
      actual: 200
    conditionText:
      expected: otherwise
      actual: otherwise
    runtimeError: {}
  - id: test8
    match: true
    status:
      expected: INCOMPLIANT
      actual: INCOMPLIANT
    conditionIndex:
      expected: 200
      actual: 200
    conditionText:
      expected: otherwise
      actual: otherwise
    runtimeError: {}
  - id: test9
    match: true
    status:
      expected: INCOMPLIANT
      actual: INCOMPLIANT
    conditionIndex:
      expected: 200
      actual: 200
    conditionText:
      expected: otherwise
      actual: otherwise
    runtimeError: {}
  - id: test10
    match: true
    status:
      expected: INCOMPLIANT
      actual: INCOMPLIANT
    conditionIndex:
      expected: 200
      actual: 200
    conditionText:
      expected: otherwise
      actual: otherwise
    runtimeError: {}
  - id: test11
    match: true
    status:
      expected: INCOMPLIANT
      actual: INCOMPLIANT
    conditionIndex:
      expected: 200
      actual: 200
    conditionText:
      expected: otherwise
      actual: otherwise
    runtimeError: {}
  - id: test12
    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-delete-public-ip-address-rule/policy.yaml
    md5Hash: E3AA0503FB20B3BD6C45554F27C97853
    content: |
      ---
      names:
        full: Azure Subscription Activity Log Alert for Delete Public IP Address Rule does
          not exist
        contextual: Activity Log Alert for Delete Public IP Address Rule does not exist
      description: Create an activity log alert for the Delete Public IP Address rule.
      type: COMPLIANCE_POLICY
      categories:
        - SECURITY
      frameworkMappings:
        - "/frameworks/cis-azure-v2.1.0/05/02/10"
        - "/frameworks/cis-azure-v3.0.0/06/02/10"
        - "/frameworks/cloudaware/logging-and-monitoring/alerting-and-notification"
      similarPolicies:
        cloudConformity:
          - url: https://www.trendmicro.com/cloudoneconformity/knowledge-base/azure/ActivityLog/delete-public-ip-alert.html
            name: Create Alert for 'Delete Public IP Address' Events
  - path: /ce/ca/azure/subscription/activity-log-alert-for-delete-public-ip-address-rule/prod.logic.yaml
    md5Hash: 426E71B84D77008E45A30954F31FC0A7
    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 Delete Public IP Address\
      \ rule.\"\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 Delete Public IP Address rule.\"\n  remediationMessage:\
      \ \"Consider creating an Activity Log Alert for Delete Public IP Address rule.\"\
      \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 Delete Public\
      \ IP Address rule.\"\n        check:\n          IS_EQUAL:\n            left:\n\
      \              JSON_QUERY_BOOLEAN:\n                  arg: \n              \
      \      EXTRACT: \"caJsonFrom__conditionJson__c\"\n                  expression:\
      \ \"contains(allOf[*].equals, 'Microsoft.Network/publicIPAddresses/delete')\"\
      \n                  undeterminedIf: \n                    evaluationError: \"\
      The JSON query has failed.\"\n                    resultTypeMismatch: \"The\
      \ JSON query did not return boolean type.\"\n            right:\n          \
      \    BOOLEAN: true\n    otherwise:\n      status: \"INAPPLICABLE\"\n      currentStateMessage:\
      \ \"This is an unrelated Activity Log Alert.\""
  - path: /ce/ca/azure/subscription/activity-log-alert-for-delete-public-ip-address-rule/test-data.json
    md5Hash: F50C5F332615230ACB0F5A671F7DE078
    content: "[\n    {\n        \"expectedResult\": {\n            \"status\": \"\
      INCOMPLIANT\",\n            \"conditionIndex\": \"200\",\n            \"conditionText\"\
      : \"otherwise\",\n            \"runtimeError\": null\n        },\n        \"\
      context\": {\n            \"snapshotTime\": \"2024-06-14T06:19:32Z\"\n     \
      \   },\n        \"Id\": \"test1\",\n        \"CA10__Azure_Activity_Log_Alerts__r\"\
      : []\n    },\n    {\n        \"expectedResult\": {\n            \"status\":\
      \ \"COMPLIANT\",\n            \"conditionIndex\": \"199\",\n            \"conditionText\"\
      : \"CA10__Azure_Activity_Log_Alerts__r.has(COMPLIANT)\",\n            \"runtimeError\"\
      : null\n        },\n        \"context\": {\n            \"snapshotTime\": \"\
      2024-06-14T06:19:32Z\"\n        },\n        \"Id\": \"test2\",\n        \"CA10__Azure_Activity_Log_Alerts__r\"\
      : [\n            {\n                \"Id\": \"test2_1\",\n                \"\
      CA10__disappearanceTime__c\": null,\n                \"CA10__enabledStatus__c\"\
      : \"Enabled\",\n                \"CA10__conditionJson__c\": \"{\\\"allOf\\\"\
      :[{\\\"field\\\":\\\"operationName\\\",\\\"equals\\\":\\\"Microsoft.Network/publicIPAddresses/delete\\\
      \"}]}\",\n                \"CA10__subscription__c\": \"test2\"        \n   \
      \         }\n        ]\n    },\n    {\n        \"expectedResult\": {\n     \
      \       \"status\": \"INCOMPLIANT\",\n            \"conditionIndex\": \"200\"\
      ,\n            \"conditionText\": \"otherwise\",\n            \"runtimeError\"\
      : null\n        },\n        \"context\": {\n            \"snapshotTime\": \"\
      2024-06-14T06:19:32Z\"\n        },\n        \"Id\": \"test3\",\n        \"CA10__Azure_Activity_Log_Alerts__r\"\
      : [\n            {\n                \"Id\": \"test3_1\",\n                \"\
      CA10__disappearanceTime__c\": \"2024-06-14T06:19:32Z\",\n                \"\
      CA10__enabledStatus__c\": \"Enabled\",\n                \"CA10__conditionJson__c\"\
      : \"{\\\"allOf\\\":[{\\\"field\\\":\\\"operationName\\\",\\\"equals\\\":\\\"\
      Microsoft.Network/publicIPAddresses/delete\\\"}]}\",\n                \"CA10__subscription__c\"\
      : \"test3\"        \n            }\n        ]\n    },\n    {\n        \"expectedResult\"\
      : {\n            \"status\": \"INCOMPLIANT\",\n            \"conditionIndex\"\
      : \"200\",\n            \"conditionText\": \"otherwise\",\n            \"runtimeError\"\
      : null\n        },\n        \"context\": {\n            \"snapshotTime\": \"\
      2024-06-14T06:19:32Z\"\n        },\n        \"Id\": \"test4\",\n        \"CA10__Azure_Activity_Log_Alerts__r\"\
      : [\n            {\n                \"Id\": \"test4_1\",\n                \"\
      CA10__disappearanceTime__c\": null,\n                \"CA10__enabledStatus__c\"\
      : \"Disabled\",\n                \"CA10__conditionJson__c\": \"{\\\"allOf\\\"\
      :[{\\\"field\\\":\\\"operationName\\\",\\\"equals\\\":\\\"Microsoft.Network/publicIPAddresses/delete\\\
      \"}]}\",\n                \"CA10__subscription__c\": \"test4\"        \n   \
      \         }\n        ]\n    },\n    {\n        \"expectedResult\": {\n     \
      \       \"status\": \"INCOMPLIANT\",\n            \"conditionIndex\": \"200\"\
      ,\n            \"conditionText\": \"otherwise\",\n            \"runtimeError\"\
      : null\n        },\n        \"context\": {\n            \"snapshotTime\": \"\
      2024-06-14T06:19:32Z\"\n        },\n        \"Id\": \"test5\",\n        \"CA10__Azure_Activity_Log_Alerts__r\"\
      : [\n            {\n                \"Id\": \"test5_1\",\n                \"\
      CA10__disappearanceTime__c\": null,\n                \"CA10__enabledStatus__c\"\
      : \"Enabled\",\n                \"CA10__conditionJson__c\": \"{\\\"allOf\\\"\
      :[{\\\"field\\\":\\\"operationName\\\",\\\"equals\\\":\\\"Microsoft.Network/publicIPAddresses/read\\\
      \"}]}\",\n                \"CA10__subscription__c\": \"test5\"        \n   \
      \         }\n        ]\n    },\n    {\n        \"expectedResult\": {\n     \
      \       \"status\": \"INCOMPLIANT\",\n            \"conditionIndex\": \"200\"\
      ,\n            \"conditionText\": \"otherwise\",\n            \"runtimeError\"\
      : null\n        },\n        \"context\": {\n            \"snapshotTime\": \"\
      2024-06-14T06:19:32Z\"\n        },\n        \"Id\": \"test6\",\n        \"CA10__Azure_Activity_Log_Alerts__r\"\
      : [\n            {\n                \"Id\": \"test6_1\",\n                \"\
      CA10__disappearanceTime__c\": null,\n                \"CA10__enabledStatus__c\"\
      : \"Enabled\",\n                \"CA10__conditionJson__c\": \"{\\\"allOf\\\"\
      :[{\\\"field\\\":\\\"operationName\\\",\\\"equals\\\":\\\"\\\"}]}\",\n     \
      \           \"CA10__subscription__c\": \"test6\"        \n            }\n  \
      \      ]\n    },\n    {\n        \"expectedResult\": {\n            \"status\"\
      : \"INCOMPLIANT\",\n            \"conditionIndex\": \"200\",\n            \"\
      conditionText\": \"otherwise\",\n            \"runtimeError\": null\n      \
      \  },\n        \"context\": {\n            \"snapshotTime\": \"2024-06-14T06:19:32Z\"\
      \n        },\n        \"Id\": \"test7\",\n        \"CA10__Azure_Activity_Log_Alerts__r\"\
      : [\n            {\n                \"Id\": \"test7_1\",\n                \"\
      CA10__disappearanceTime__c\": null,\n                \"CA10__enabledStatus__c\"\
      : \"Enabled\",\n                \"CA10__conditionJson__c\": \"{\\\"allOf\\\"\
      :[{}]}\",\n                \"CA10__subscription__c\": \"test7\"        \n  \
      \          }\n        ]\n    },\n    {\n        \"expectedResult\": {\n    \
      \        \"status\": \"INCOMPLIANT\",\n            \"conditionIndex\": \"200\"\
      ,\n            \"conditionText\": \"otherwise\",\n            \"runtimeError\"\
      : null\n        },\n        \"context\": {\n            \"snapshotTime\": \"\
      2024-06-14T06:19:32Z\"\n        },\n        \"Id\": \"test8\",\n        \"CA10__Azure_Activity_Log_Alerts__r\"\
      : [\n            {\n                \"Id\": \"test8_1\",\n                \"\
      CA10__disappearanceTime__c\": null,\n                \"CA10__enabledStatus__c\"\
      : \"Enabled\",\n                \"CA10__conditionJson__c\": \"{\\\"allOf\\\"\
      :[]}\",\n                \"CA10__subscription__c\": \"test8\"        \n    \
      \        }\n        ]\n    },\n    {\n        \"expectedResult\": {\n      \
      \      \"status\": \"INCOMPLIANT\",\n            \"conditionIndex\": \"200\"\
      ,\n            \"conditionText\": \"otherwise\",\n            \"runtimeError\"\
      : null\n        },\n        \"context\": {\n            \"snapshotTime\": \"\
      2024-06-14T06:19:32Z\"\n        },\n        \"Id\": \"test9\",\n        \"CA10__Azure_Activity_Log_Alerts__r\"\
      : [\n            {\n                \"Id\": \"test9_1\",\n                \"\
      CA10__disappearanceTime__c\": null,\n                \"CA10__enabledStatus__c\"\
      : \"Enabled\",\n                \"CA10__conditionJson__c\": \"{}\",\n      \
      \          \"CA10__subscription__c\": \"test9\"        \n            }\n   \
      \     ]\n    },\n    {\n        \"expectedResult\": {\n            \"status\"\
      : \"INCOMPLIANT\",\n            \"conditionIndex\": \"200\",\n            \"\
      conditionText\": \"otherwise\",\n            \"runtimeError\": null\n      \
      \  },\n        \"context\": {\n            \"snapshotTime\": \"2024-06-14T06:19:32Z\"\
      \n        },\n        \"Id\": \"test10\",\n        \"CA10__Azure_Activity_Log_Alerts__r\"\
      : [\n            {\n                \"Id\": \"test10_1\",\n                \"\
      CA10__disappearanceTime__c\": null,\n                \"CA10__enabledStatus__c\"\
      : \"Enabled\",\n                \"CA10__conditionJson__c\": \"\",\n        \
      \        \"CA10__subscription__c\": \"test10\"        \n            }\n    \
      \    ]\n    },\n    {\n        \"expectedResult\": {\n            \"status\"\
      : \"INCOMPLIANT\",\n            \"conditionIndex\": \"200\",\n            \"\
      conditionText\": \"otherwise\",\n            \"runtimeError\": null\n      \
      \  },\n        \"context\": {\n            \"snapshotTime\": \"2024-06-14T06:19:32Z\"\
      \n        },\n        \"Id\": \"test11\",\n        \"CA10__Azure_Activity_Log_Alerts__r\"\
      : [\n            {\n                \"Id\": \"test11_1\",\n                \"\
      CA10__disappearanceTime__c\": null,\n                \"CA10__enabledStatus__c\"\
      : \"Enabled\",\n                \"CA10__conditionJson__c\": null,\n        \
      \        \"CA10__subscription__c\": \"test11\"       \n            }\n     \
      \   ]\n    },\n    {\n        \"expectedResult\": {\n            \"status\"\
      : \"INCOMPLIANT\",\n            \"conditionIndex\": \"200\",\n            \"\
      conditionText\": \"otherwise\",\n            \"runtimeError\": null\n      \
      \  },\n        \"context\": {\n            \"snapshotTime\": \"2024-06-14T06:19:32Z\"\
      \n        },\n        \"Id\": \"test12\",\n        \"CA10__Azure_Activity_Log_Alerts__r\"\
      : [\n            {\n                \"Id\": \"test12_1\",\n                \"\
      CA10__disappearanceTime__c\": null,\n                \"CA10__enabledStatus__c\"\
      : \"Enabled\",\n                \"CA10__conditionJson__c\": \"{\\\"anyOf\\\"\
      :[]}\",\n                \"CA10__subscription__c\": \"test12\"        \n   \
      \         }\n        ]\n    }\n]"
  - path: /types/CA10__CaAzureActivityLogAlert__c/object.extracts.yaml
    md5Hash: 79B153D6511F943B6AB929697CE0452E
    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.\""
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" : "200",
      "conditionText" : "otherwise",
      "runtimeError" : null
    }
  }, {
    "Id" : "test2",
    "expectedResult" : {
      "status" : "COMPLIANT",
      "conditionIndex" : "199",
      "conditionText" : "CA10__Azure_Activity_Log_Alerts__r.has(COMPLIANT)",
      "runtimeError" : null
    }
  }, {
    "Id" : "test3",
    "expectedResult" : {
      "status" : "INCOMPLIANT",
      "conditionIndex" : "200",
      "conditionText" : "otherwise",
      "runtimeError" : null
    }
  }, {
    "Id" : "test4",
    "expectedResult" : {
      "status" : "INCOMPLIANT",
      "conditionIndex" : "200",
      "conditionText" : "otherwise",
      "runtimeError" : null
    }
  }, {
    "Id" : "test5",
    "expectedResult" : {
      "status" : "INCOMPLIANT",
      "conditionIndex" : "200",
      "conditionText" : "otherwise",
      "runtimeError" : null
    }
  }, {
    "Id" : "test6",
    "expectedResult" : {
      "status" : "INCOMPLIANT",
      "conditionIndex" : "200",
      "conditionText" : "otherwise",
      "runtimeError" : null
    }
  }, {
    "Id" : "test7",
    "expectedResult" : {
      "status" : "INCOMPLIANT",
      "conditionIndex" : "200",
      "conditionText" : "otherwise",
      "runtimeError" : null
    }
  }, {
    "Id" : "test8",
    "expectedResult" : {
      "status" : "INCOMPLIANT",
      "conditionIndex" : "200",
      "conditionText" : "otherwise",
      "runtimeError" : null
    }
  }, {
    "Id" : "test9",
    "expectedResult" : {
      "status" : "INCOMPLIANT",
      "conditionIndex" : "200",
      "conditionText" : "otherwise",
      "runtimeError" : null
    }
  }, {
    "Id" : "test10",
    "expectedResult" : {
      "status" : "INCOMPLIANT",
      "conditionIndex" : "200",
      "conditionText" : "otherwise",
      "runtimeError" : null
    }
  }, {
    "Id" : "test11",
    "expectedResult" : {
      "status" : "INCOMPLIANT",
      "conditionIndex" : "200",
      "conditionText" : "otherwise",
      "runtimeError" : null
    }
  }, {
    "Id" : "test12",
    "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("2024-06-14T06:19:32Z")
    },
    "Id" : "test1"
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-06-14T06:19:32Z")
    },
    "Id" : "test2"
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-06-14T06:19:32Z")
    },
    "Id" : "test3"
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-06-14T06:19:32Z")
    },
    "Id" : "test4"
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-06-14T06:19:32Z")
    },
    "Id" : "test5"
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-06-14T06:19:32Z")
    },
    "Id" : "test6"
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-06-14T06:19:32Z")
    },
    "Id" : "test7"
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-06-14T06:19:32Z")
    },
    "Id" : "test8"
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-06-14T06:19:32Z")
    },
    "Id" : "test9"
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-06-14T06:19:32Z")
    },
    "Id" : "test10"
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-06-14T06:19:32Z")
    },
    "Id" : "test11"
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-06-14T06:19:32Z")
    },
    "Id" : "test12"
  } ];
  """;

  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__subscription__c STRING,
      context STRUCT<
          snapshotTime TIMESTAMP
      >
  >>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
    return [ {
    "context" : {
      "snapshotTime" : new Date("2024-06-14T06:19:32Z")
    },
    "Id" : "test2_1",
    "CA10__enabledStatus__c" : "Enabled",
    "CA10__conditionJson__c" : "{\"allOf\":[{\"field\":\"operationName\",\"equals\":\"Microsoft.Network/publicIPAddresses/delete\"}]}",
    "CA10__subscription__c" : "test2"
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-06-14T06:19:32Z")
    },
    "Id" : "test3_1",
    "CA10__disappearanceTime__c" : new Date("2024-06-14T06:19:32Z"),
    "CA10__enabledStatus__c" : "Enabled",
    "CA10__conditionJson__c" : "{\"allOf\":[{\"field\":\"operationName\",\"equals\":\"Microsoft.Network/publicIPAddresses/delete\"}]}",
    "CA10__subscription__c" : "test3"
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-06-14T06:19:32Z")
    },
    "Id" : "test4_1",
    "CA10__enabledStatus__c" : "Disabled",
    "CA10__conditionJson__c" : "{\"allOf\":[{\"field\":\"operationName\",\"equals\":\"Microsoft.Network/publicIPAddresses/delete\"}]}",
    "CA10__subscription__c" : "test4"
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-06-14T06:19:32Z")
    },
    "Id" : "test5_1",
    "CA10__enabledStatus__c" : "Enabled",
    "CA10__conditionJson__c" : "{\"allOf\":[{\"field\":\"operationName\",\"equals\":\"Microsoft.Network/publicIPAddresses/read\"}]}",
    "CA10__subscription__c" : "test5"
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-06-14T06:19:32Z")
    },
    "Id" : "test6_1",
    "CA10__enabledStatus__c" : "Enabled",
    "CA10__conditionJson__c" : "{\"allOf\":[{\"field\":\"operationName\",\"equals\":\"\"}]}",
    "CA10__subscription__c" : "test6"
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-06-14T06:19:32Z")
    },
    "Id" : "test7_1",
    "CA10__enabledStatus__c" : "Enabled",
    "CA10__conditionJson__c" : "{\"allOf\":[{}]}",
    "CA10__subscription__c" : "test7"
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-06-14T06:19:32Z")
    },
    "Id" : "test8_1",
    "CA10__enabledStatus__c" : "Enabled",
    "CA10__conditionJson__c" : "{\"allOf\":[]}",
    "CA10__subscription__c" : "test8"
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-06-14T06:19:32Z")
    },
    "Id" : "test9_1",
    "CA10__enabledStatus__c" : "Enabled",
    "CA10__conditionJson__c" : "{}",
    "CA10__subscription__c" : "test9"
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-06-14T06:19:32Z")
    },
    "Id" : "test10_1",
    "CA10__enabledStatus__c" : "Enabled",
    "CA10__conditionJson__c" : "",
    "CA10__subscription__c" : "test10"
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-06-14T06:19:32Z")
    },
    "Id" : "test11_1",
    "CA10__enabledStatus__c" : "Enabled",
    "CA10__conditionJson__c" : null,
    "CA10__subscription__c" : "test11"
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-06-14T06:19:32Z")
    },
    "Id" : "test12_1",
    "CA10__enabledStatus__c" : "Enabled",
    "CA10__conditionJson__c" : "{\"anyOf\":[]}",
    "CA10__subscription__c" : "test12"
  } ];
  """;

  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__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 Delete Public IP Address rule.", 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 Delete Public IP Address rule.", currentStateReferences: references1.join('\n'), remediation: "Consider creating an Activity Log Alert for Delete Public IP Address rule.", 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__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));
          };
      }();
      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, \'Microsoft.Network/publicIPAddresses/delete\')');
          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, \\'Microsoft.Network/publicIPAddresses/delete\\')').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, \\'Microsoft.Network/publicIPAddresses/delete\\')').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 ((obj.CA10__conditionJson__c == null || 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; };
      references1.push('Condition JSON [obj.CA10__conditionJson__c]: ' + obj.CA10__conditionJson__c);
      try {
          if (jsonQueryChecked5() == true) {
              return {status: 'COMPLIANT', conditionIndex: 299, conditionText: "extract('caJsonFrom__conditionJson__c').jsonQueryText('contains(allOf[*].equals, \\'Microsoft.Network/publicIPAddresses/delete\\')') == true", currentStateMessage: "This is an Activity Log Alert for Delete Public IP Address rule.", 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__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__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;
