---
policy: /ce/ca/azure/postgresql-database/server-underutilized
logic: /ce/ca/azure/postgresql-database/server-underutilized/prod.logic.yaml
executionTime: 2025-10-01T12:46:55.565346148Z
generationMs: 95
executionMs: 787
rows:
  - id: '001'
    match: true
    status:
      expected: DISAPPEARED
      actual: DISAPPEARED
    conditionIndex:
      expected: 99
      actual: 99
    conditionText:
      expected: isDisappeared(CA10Z1__disappearanceTime__c)
      actual: isDisappeared(CA10Z1__disappearanceTime__c)
    runtimeError: {}
  - id: '002'
    match: true
    status:
      expected: INAPPLICABLE
      actual: INAPPLICABLE
    conditionIndex:
      expected: 199
      actual: 199
    conditionText:
      expected: extract('CA10Z1__state__c') != 'Ready'
      actual: extract('CA10Z1__state__c') != 'Ready'
    runtimeError: {}
  - id: '003'
    match: true
    status:
      expected: UNDETERMINED
      actual: UNDETERMINED
    conditionIndex:
      expected: 299
      actual: 299
    conditionText:
      expected: extract('CA10Z1__monitorCpuPercentAvg30Day__c').isEmpty() || extract('CA10Z1__monitorMemoryPercentAvg30Day__c').isEmpty()
        || extract('CA10Z1__monitorIoConsumptionPercentAvg30Day__c').isEmpty()
      actual: extract('CA10Z1__monitorCpuPercentAvg30Day__c').isEmpty() || extract('CA10Z1__monitorMemoryPercentAvg30Day__c').isEmpty()
        || extract('CA10Z1__monitorIoConsumptionPercentAvg30Day__c').isEmpty()
    runtimeError: {}
  - id: '004'
    match: true
    status:
      expected: INAPPLICABLE
      actual: INAPPLICABLE
    conditionIndex:
      expected: 399
      actual: 399
    conditionText:
      expected: extract('CA10Z1__monitorCpuPercentAvg30Day__c') < number(5.0) && extract('CA10Z1__monitorIoConsumptionPercentAvg30Day__c')
        == number(0.0)
      actual: extract('CA10Z1__monitorCpuPercentAvg30Day__c') < number(5.0) && extract('CA10Z1__monitorIoConsumptionPercentAvg30Day__c')
        == number(0.0)
    runtimeError: {}
  - id: '005'
    match: true
    status:
      expected: INCOMPLIANT
      actual: INCOMPLIANT
    conditionIndex:
      expected: 499
      actual: 499
    conditionText:
      expected: extract('CA10Z1__monitorCpuPercentAvg30Day__c') < number(20.0) &&
        extract('CA10Z1__monitorMemoryPercentAvg30Day__c') < number(40.0) && extract('CA10Z1__monitorIoConsumptionPercentAvg30Day__c')
        < number(20.0)
      actual: extract('CA10Z1__monitorCpuPercentAvg30Day__c') < number(20.0) && extract('CA10Z1__monitorMemoryPercentAvg30Day__c')
        < number(40.0) && extract('CA10Z1__monitorIoConsumptionPercentAvg30Day__c')
        < number(20.0)
    runtimeError: {}
  - id: '006'
    match: true
    status:
      expected: COMPLIANT
      actual: COMPLIANT
    conditionIndex:
      expected: 500
      actual: 500
    conditionText:
      expected: otherwise
      actual: otherwise
    runtimeError: {}
  - id: '007'
    match: true
    status:
      expected: COMPLIANT
      actual: COMPLIANT
    conditionIndex:
      expected: 500
      actual: 500
    conditionText:
      expected: otherwise
      actual: otherwise
    runtimeError: {}
usedFiles:
  - path: /ce/ca/azure/postgresql-database/server-underutilized/policy.yaml
    md5Hash: BAEBE48A00BA0BAAACD3F856776915BB
    content: "---\nnames:\n  full: Azure PostgreSQL Server is underutilized\n  contextual:\
      \ Server is underutilized\ndescription: >\n  Identify underutilized Azure PostgreSQL\
      \ Servers to optimize costs and improve efficiency. \n  Servers are considered\
      \ underutilized if their average CPU and I/O utilization are \n  consistently\
      \ below 20% and memory is below 40% over a 30-day period.\ntype: \"COMPLIANCE_POLICY\"\
      \ncategories:\n  - \"COST\"\n  - \"PERFORMANCE\"\nframeworkMappings:\n  - \"\
      /frameworks/cloudaware/cost-efficiency-and-optimization/resource-right-sizing\"\
      \n  - \"/frameworks/cloudaware/resource-performance/workload-efficiency\"  "
  - path: /ce/ca/azure/postgresql-database/server-underutilized/prod.logic.yaml
    md5Hash: A17B10D7AD0B121EA9E8652C0F5CAF21
    content: |-
      ---
      inputType: "CA10Z1__CaAzurePostgreSqlServer__c"
      importExtracts:
        - file: "/types/CA10Z1__CaAzurePostgreSqlServer__c/object.extracts.yaml"
      testData:
        - file: 'test-data.json'
      conditions:
        - status: "INAPPLICABLE"
          currentStateMessage: "The server is not ready."
          check:
            NOT_EQUAL:
              left:
                EXTRACT: "CA10Z1__state__c"
              right:
                TEXT: "Ready"
        - status: UNDETERMINED
          currentStateMessage: "There is not enough data in the CMDB to identify if the server is underutilized."
          check:
            OR:
              args:
                - IS_EMPTY:
                    arg:
                      EXTRACT: "CA10Z1__monitorCpuPercentAvg30Day__c"
                - IS_EMPTY:
                    arg:
                      EXTRACT: "CA10Z1__monitorMemoryPercentAvg30Day__c"
                - IS_EMPTY:
                    arg:
                      EXTRACT: "CA10Z1__monitorIoConsumptionPercentAvg30Day__c"
        - status: INAPPLICABLE
          currentStateMessage: "The server is idle and considered by the 'Azure PostgreSQL Server is Idle' policy."
          check:
            AND:
              args:
                - LESS_THAN:
                    left:
                      EXTRACT: "CA10Z1__monitorCpuPercentAvg30Day__c"
                    right:
                      NUMBER: 5.0
                - IS_EQUAL:
                    left:
                      EXTRACT: "CA10Z1__monitorIoConsumptionPercentAvg30Day__c"
                    right:
                      NUMBER: 0.0
        - status: "INCOMPLIANT"
          currentStateMessage: "The server is underutilized with Average CPU and IO < 20%, and Memory < 40%."
          remediationMessage: "Consider rightsizing, the server."
          check:
            AND:
              args:
                - LESS_THAN:
                    left:
                      EXTRACT: "CA10Z1__monitorCpuPercentAvg30Day__c"
                    right:
                      NUMBER: 20.0
                - LESS_THAN:
                    left:
                      EXTRACT: "CA10Z1__monitorMemoryPercentAvg30Day__c"
                    right:
                      NUMBER: 40.0
                - LESS_THAN:
                    left:
                      EXTRACT: "CA10Z1__monitorIoConsumptionPercentAvg30Day__c"
                    right:
                      NUMBER: 20.0
      otherwise:
        status: "COMPLIANT"
        currentStateMessage: "The server is not underutilized."
  - path: /ce/ca/azure/postgresql-database/server-underutilized/test-data.json
    md5Hash: 5982F4642492CED352DEF1DB0D3E2137
    content: |-
      [
          {
              "expectedResult": {
                  "status": "DISAPPEARED",
                  "conditionIndex": "99",
                  "conditionText": "isDisappeared(CA10Z1__disappearanceTime__c)",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2025-09-17T01:22:29Z"
              },
              "Id": "001",
              "CA10Z1__disappearanceTime__c": "2025-09-17T01:22:29Z",
              "CA10Z1__state__c": "Ready",
              "CA10Z1__monitorCpuPercentAvg30Day__c": 10,
              "CA10Z1__monitorMemoryPercentAvg30Day__c": 10,
              "CA10Z1__monitorIoConsumptionPercentAvg30Day__c": 10
          },
          {
              "expectedResult": {
                  "status": "INAPPLICABLE",
                  "conditionIndex": "199",
                  "conditionText": "extract('CA10Z1__state__c') != 'Ready'",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2025-09-17T01:22:29Z"
              },
              "Id": "002",
              "CA10Z1__disappearanceTime__c": null,
              "CA10Z1__state__c": "Error",
              "CA10Z1__monitorCpuPercentAvg30Day__c": 10,
              "CA10Z1__monitorMemoryPercentAvg30Day__c": 10,
              "CA10Z1__monitorIoConsumptionPercentAvg30Day__c": 10
          },
          {
              "expectedResult": {
                  "status": "UNDETERMINED",
                  "conditionIndex": "299",
                  "conditionText": "extract('CA10Z1__monitorCpuPercentAvg30Day__c').isEmpty() || extract('CA10Z1__monitorMemoryPercentAvg30Day__c').isEmpty() || extract('CA10Z1__monitorIoConsumptionPercentAvg30Day__c').isEmpty()",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2025-09-17T01:22:29Z"
              },
              "Id": "003",
              "CA10Z1__disappearanceTime__c": null,
              "CA10Z1__state__c": "Ready",
              "CA10Z1__monitorCpuPercentAvg30Day__c": null,
              "CA10Z1__monitorMemoryPercentAvg30Day__c": null,
              "CA10Z1__monitorIoConsumptionPercentAvg30Day__c": null
          },
          {
              "expectedResult": {
                  "status": "INAPPLICABLE",
                  "conditionIndex": "399",
                  "conditionText": "extract('CA10Z1__monitorCpuPercentAvg30Day__c') < number(5.0) && extract('CA10Z1__monitorIoConsumptionPercentAvg30Day__c') == number(0.0)",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2025-09-17T01:22:29Z"
              },
              "Id": "004",
              "CA10Z1__disappearanceTime__c": null,
              "CA10Z1__state__c": "Ready",
              "CA10Z1__monitorCpuPercentAvg30Day__c": 4.0,
              "CA10Z1__monitorMemoryPercentAvg30Day__c": 0.0,
              "CA10Z1__monitorIoConsumptionPercentAvg30Day__c": 0.0
          },
          {
              "expectedResult": {
                  "status": "INCOMPLIANT",
                  "conditionIndex": "499",
                  "conditionText": "extract('CA10Z1__monitorCpuPercentAvg30Day__c') < number(20.0) && extract('CA10Z1__monitorMemoryPercentAvg30Day__c') < number(40.0) && extract('CA10Z1__monitorIoConsumptionPercentAvg30Day__c') < number(20.0)",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2025-09-17T01:22:29Z"
              },
              "Id": "005",
              "CA10Z1__disappearanceTime__c": null,
              "CA10Z1__state__c": "Ready",
              "CA10Z1__monitorCpuPercentAvg30Day__c": 19,
              "CA10Z1__monitorMemoryPercentAvg30Day__c": 39,
              "CA10Z1__monitorIoConsumptionPercentAvg30Day__c": 19
          },
          {
              "expectedResult": {
                  "status": "COMPLIANT",
                  "conditionIndex": "500",
                  "conditionText": "otherwise",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2025-09-17T01:22:29Z"
              },
              "Id": "006",
              "CA10Z1__disappearanceTime__c": null,
              "CA10Z1__state__c": "Ready",
              "CA10Z1__monitorCpuPercentAvg30Day__c": 20,
              "CA10Z1__monitorMemoryPercentAvg30Day__c": 40,
              "CA10Z1__monitorIoConsumptionPercentAvg30Day__c": 20
          },
          {
              "expectedResult": {
                  "status": "COMPLIANT",
                  "conditionIndex": "500",
                  "conditionText": "otherwise",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2025-09-17T01:22:29Z"
              },
              "Id": "007",
              "CA10Z1__disappearanceTime__c": null,
              "CA10Z1__state__c": "Ready",
              "CA10Z1__monitorCpuPercentAvg30Day__c": 50,
              "CA10Z1__monitorMemoryPercentAvg30Day__c": 50,
              "CA10Z1__monitorIoConsumptionPercentAvg30Day__c": 50
          }
      ]
  - path: /types/CA10Z1__CaAzurePostgreSqlServer__c/object.extracts.yaml
    md5Hash: 57EE11B2A1C370B47B2D4FE4AF22C8D0
    content: "---\nextracts:\n# Values: Enabled, Disabled. Not Nullable. Can't have\
      \ no access, retrieved via Microsoft.DBforPostgreSQL/servers/read\n  - name:\
      \ \"CA10Z1__sslEnforcement__c\"\n    value: \n      FIELD:\n        path: \"\
      CA10Z1__sslEnforcement__c\"\n        undeterminedIf:\n          isEmpty: \"\
      Corrupted Data. PostgreSQL Server SSL Enforcement cannot be empty.\"\n# Values:\
      \ Enabled, Disabled. Not Nullable. Can't have no access, retrieved via Microsoft.DBforPostgreSQL/servers/read\n\
      \  - name: \"CA10Z1__infrastructureEncryption__c\"\n    value: \n      FIELD:\n\
      \        path: \"CA10Z1__infrastructureEncryption__c\"\n        undeterminedIf:\n\
      \          isEmpty: \"Corrupted Data. PostgreSQL Server Infrastructure Encryption\
      \ cannot be empty.\"\n# Not nullable\n  - name: \"CA10Z1__configurations__c\"\
      \n    value:\n      FIELD:\n        path: \"CA10Z1__configurations__c\"\n  \
      \      returnType: BYTES\n        undeterminedIf:\n          noAccessDelegate:\n\
      \            path: \"CA10Z1__configurations__c\"\n            currentStateMessage:\
      \ \"Unable to determine Server Configurations. Possible permission issue with\
      \ Microsoft.DBforPostgreSQL/servers/configurations/read\"\n  - name: \"caJsonFrom__configurations__c\"\
      \n    value: \n      JSON_FROM:\n        arg: \n          EXTRACT: \"CA10Z1__configurations__c\"\
      \n        undeterminedIf:\n          isInvalid: \"Configurations JSON is invalid.\"\
      \n  - name: \"CA10Z1__firewallRules__c\"\n    value: \n      FIELD:\n      \
      \  path: \"CA10Z1__firewallRules__c\"\n        returnType: BYTES\n        undeterminedIf:\n\
      \          noAccessDelegate:\n            path: \"CA10Z1__firewallRules__c\"\
      \n            currentStateMessage: \"Unable to determine Firewall Rules. Possible\
      \ permission issue with Microsoft.Sql/servers/firewallRules/read\"\n  - name:\
      \ \"caJsonFrom__firewallRules__c\"\n    value: \n      JSON_FROM:\n        arg:\
      \ \n          EXTRACT: \"CA10Z1__firewallRules__c\"\n        undeterminedIf:\n\
      \          isInvalid: \"Firewall Rules JSON is invalid.\"\n  - name: \"CA10Z1__deploymentMode__c\"\
      \n    value: \n      FIELD:\n        path: \"CA10Z1__deploymentMode__c\"\n \
      \       undeterminedIf:\n          isEmpty: \"Corrupted Data. PostgreSQL Deployment\
      \ Mode cannot be empty.\"\n# Not nullable \n  - name: \"CA10Z1__state__c\"\n\
      \    value: \n      FIELD:\n        path: \"CA10Z1__state__c\"\n# Nullable \n\
      \  - name: \"CA10Z1__monitorCpuPercentAvg30Day__c\"\n    value: \n      FIELD:\n\
      \        path: \"CA10Z1__monitorCpuPercentAvg30Day__c\"\n# Nullable \n  - name:\
      \ \"CA10Z1__monitorMemoryPercentAvg30Day__c\"\n    value: \n      FIELD:\n \
      \       path: \"CA10Z1__monitorMemoryPercentAvg30Day__c\"\n# Nullable \n  -\
      \ name: \"CA10Z1__monitorIoConsumptionPercentAvg30Day__c\"\n    value: \n  \
      \    FIELD:\n        path: \"CA10Z1__monitorIoConsumptionPercentAvg30Day__c\"\
      \n  - name: \"CA10Z1__locationName__c\"\n    value: \n      FIELD:\n       \
      \ path: \"CA10Z1__locationName__c\"\n\n\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" : "001",
    "expectedResult" : {
      "status" : "DISAPPEARED",
      "conditionIndex" : "99",
      "conditionText" : "isDisappeared(CA10Z1__disappearanceTime__c)",
      "runtimeError" : null
    }
  }, {
    "Id" : "002",
    "expectedResult" : {
      "status" : "INAPPLICABLE",
      "conditionIndex" : "199",
      "conditionText" : "extract('CA10Z1__state__c') != 'Ready'",
      "runtimeError" : null
    }
  }, {
    "Id" : "003",
    "expectedResult" : {
      "status" : "UNDETERMINED",
      "conditionIndex" : "299",
      "conditionText" : "extract('CA10Z1__monitorCpuPercentAvg30Day__c').isEmpty() || extract('CA10Z1__monitorMemoryPercentAvg30Day__c').isEmpty() || extract('CA10Z1__monitorIoConsumptionPercentAvg30Day__c').isEmpty()",
      "runtimeError" : null
    }
  }, {
    "Id" : "004",
    "expectedResult" : {
      "status" : "INAPPLICABLE",
      "conditionIndex" : "399",
      "conditionText" : "extract('CA10Z1__monitorCpuPercentAvg30Day__c') < number(5.0) && extract('CA10Z1__monitorIoConsumptionPercentAvg30Day__c') == number(0.0)",
      "runtimeError" : null
    }
  }, {
    "Id" : "005",
    "expectedResult" : {
      "status" : "INCOMPLIANT",
      "conditionIndex" : "499",
      "conditionText" : "extract('CA10Z1__monitorCpuPercentAvg30Day__c') < number(20.0) && extract('CA10Z1__monitorMemoryPercentAvg30Day__c') < number(40.0) && extract('CA10Z1__monitorIoConsumptionPercentAvg30Day__c') < number(20.0)",
      "runtimeError" : null
    }
  }, {
    "Id" : "006",
    "expectedResult" : {
      "status" : "COMPLIANT",
      "conditionIndex" : "500",
      "conditionText" : "otherwise",
      "runtimeError" : null
    }
  }, {
    "Id" : "007",
    "expectedResult" : {
      "status" : "COMPLIANT",
      "conditionIndex" : "500",
      "conditionText" : "otherwise",
      "runtimeError" : null
    }
  } ];
  """;

  CREATE TEMP FUNCTION mock_CA10Z1__CaAzurePostgreSqlServer__c()
  RETURNS ARRAY<STRUCT<
      Id STRING,
      CA10Z1__disappearanceTime__c TIMESTAMP,
      CA10Z1__state__c STRING,
      CA10Z1__monitorCpuPercentAvg30Day__c FLOAT64,
      CA10Z1__monitorMemoryPercentAvg30Day__c FLOAT64,
      CA10Z1__monitorIoConsumptionPercentAvg30Day__c FLOAT64,
      context STRUCT<
          snapshotTime TIMESTAMP
      >
  >>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
    return [ {
    "context" : {
      "snapshotTime" : new Date("2025-09-17T01:22:29Z")
    },
    "Id" : "001",
    "CA10Z1__disappearanceTime__c" : new Date("2025-09-17T01:22:29Z"),
    "CA10Z1__state__c" : "Ready",
    "CA10Z1__monitorCpuPercentAvg30Day__c" : 10,
    "CA10Z1__monitorMemoryPercentAvg30Day__c" : 10,
    "CA10Z1__monitorIoConsumptionPercentAvg30Day__c" : 10
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-09-17T01:22:29Z")
    },
    "Id" : "002",
    "CA10Z1__state__c" : "Error",
    "CA10Z1__monitorCpuPercentAvg30Day__c" : 10,
    "CA10Z1__monitorMemoryPercentAvg30Day__c" : 10,
    "CA10Z1__monitorIoConsumptionPercentAvg30Day__c" : 10
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-09-17T01:22:29Z")
    },
    "Id" : "003",
    "CA10Z1__state__c" : "Ready",
    "CA10Z1__monitorCpuPercentAvg30Day__c" : null,
    "CA10Z1__monitorMemoryPercentAvg30Day__c" : null,
    "CA10Z1__monitorIoConsumptionPercentAvg30Day__c" : null
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-09-17T01:22:29Z")
    },
    "Id" : "004",
    "CA10Z1__state__c" : "Ready",
    "CA10Z1__monitorCpuPercentAvg30Day__c" : 4.0,
    "CA10Z1__monitorMemoryPercentAvg30Day__c" : 0.0,
    "CA10Z1__monitorIoConsumptionPercentAvg30Day__c" : 0.0
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-09-17T01:22:29Z")
    },
    "Id" : "005",
    "CA10Z1__state__c" : "Ready",
    "CA10Z1__monitorCpuPercentAvg30Day__c" : 19,
    "CA10Z1__monitorMemoryPercentAvg30Day__c" : 39,
    "CA10Z1__monitorIoConsumptionPercentAvg30Day__c" : 19
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-09-17T01:22:29Z")
    },
    "Id" : "006",
    "CA10Z1__state__c" : "Ready",
    "CA10Z1__monitorCpuPercentAvg30Day__c" : 20,
    "CA10Z1__monitorMemoryPercentAvg30Day__c" : 40,
    "CA10Z1__monitorIoConsumptionPercentAvg30Day__c" : 20
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-09-17T01:22:29Z")
    },
    "Id" : "007",
    "CA10Z1__state__c" : "Ready",
    "CA10Z1__monitorCpuPercentAvg30Day__c" : 50,
    "CA10Z1__monitorMemoryPercentAvg30Day__c" : 50,
    "CA10Z1__monitorIoConsumptionPercentAvg30Day__c" : 50
  } ];
  """;

  CREATE TEMP FUNCTION process_CA10Z1__CaAzurePostgreSqlServer__c(
      obj STRUCT<
          Id STRING,
          CA10Z1__disappearanceTime__c TIMESTAMP,
          CA10Z1__state__c STRING,
          CA10Z1__monitorCpuPercentAvg30Day__c FLOAT64,
          CA10Z1__monitorMemoryPercentAvg30Day__c FLOAT64,
          CA10Z1__monitorIoConsumptionPercentAvg30Day__c FLOAT64
      >,
      snapshotTime TIMESTAMP
  )
  RETURNS STRUCT<status STRING, conditionIndex DECIMAL, conditionText STRING, currentStateMessage STRING, currentStateReferences STRING, remediation STRING, runtimeError STRING>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
      var TextLib = new function () {
          this.normalize = function(arg) {
              return arg == null ? '' : arg.replace(/\s+/g, ' ').trim().toLowerCase();
          };
          this.isEmpty = function(arg) {
              return this.normalize(arg) == '';
          };
          this.isNotEmpty = function(arg) {
              return this.normalize(arg) != '';
          };
          this.equal = function(left, right) {
              return this.normalize(left) == this.normalize(right);
          };
          this.notEqual = function(left, right) {
              return this.normalize(left) != this.normalize(right);
          };
          this.startsWith = function(arg, substring) {
              return this.normalize(arg).startsWith(this.normalize(substring));
          };
          this.endsWith = function(arg, substring) {
              return this.normalize(arg).endsWith(this.normalize(substring));
          };
          this.contains = function(arg, substring) {
              return this.normalize(arg).includes(this.normalize(substring));
          };
          this.containsAll = function(arg, substrings) {
              if (substrings == null || substrings.length === 0) return false;
              let normalizedArg = this.normalize(arg);
              return substrings.every(sub => normalizedArg.includes(this.normalize(sub)));
          };
          this.containsAny = function(arg, substrings) {
              if (substrings == null || substrings.length === 0) return false;
              let normalizedArg = this.normalize(arg);
              return substrings.some(sub => normalizedArg.includes(this.normalize(sub)));
          };
      }();
      var IsEmptyLib = new function () {
          this.simpleIsEmpty = function(arg) {
              return arg == null;
          };
          this.simpleIsNotEmpty = function(arg) {
              return arg != null;
          };
      }();
      var references1 = [];
      // condition[0], conditionIndex:[0..99]
      references1.push('Deleted From Azure [CA10Z1__disappearanceTime__c]: ' + obj.CA10Z1__disappearanceTime__c);
      if (obj.CA10Z1__disappearanceTime__c != null) {
          return {status: 'DISAPPEARED', conditionIndex: 99, conditionText: "isDisappeared(CA10Z1__disappearanceTime__c)", currentStateMessage: "Object is deleted in the source", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
      }
      // condition[1], conditionIndex:[100..199]
      function extract3() { if (!this.out) { this.out = obj.CA10Z1__state__c; } return this.out; };
      references1.push('State [obj.CA10Z1__state__c]: ' + obj.CA10Z1__state__c);
      if (TextLib.notEqual(extract3.call(extract3), 'Ready')) {
          return {status: 'INAPPLICABLE', conditionIndex: 199, conditionText: "extract('CA10Z1__state__c') != 'Ready'", currentStateMessage: "The server is not ready.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
      }
      // condition[2], conditionIndex:[200..299]
      function extract6() { if (!this.out) { this.out = obj.CA10Z1__monitorCpuPercentAvg30Day__c; } return this.out; };
      function extract9() { if (!this.out) { this.out = obj.CA10Z1__monitorMemoryPercentAvg30Day__c; } return this.out; };
      function extract12() { if (!this.out) { this.out = obj.CA10Z1__monitorIoConsumptionPercentAvg30Day__c; } return this.out; };
      references1.push('Monitor: CPU Percent, 30-Day [obj.CA10Z1__monitorCpuPercentAvg30Day__c]: ' + obj.CA10Z1__monitorCpuPercentAvg30Day__c);
      references1.push('Monitor: Memory Percent, 30-Day [obj.CA10Z1__monitorMemoryPercentAvg30Day__c]: ' + obj.CA10Z1__monitorMemoryPercentAvg30Day__c);
      references1.push('Monitor: IO Consumption Percent, 30-Day [obj.CA10Z1__monitorIoConsumptionPercentAvg30Day__c]: ' + obj.CA10Z1__monitorIoConsumptionPercentAvg30Day__c);
      if (IsEmptyLib.simpleIsEmpty(extract6.call(extract6)) || IsEmptyLib.simpleIsEmpty(extract9.call(extract9)) || IsEmptyLib.simpleIsEmpty(extract12.call(extract12))) {
          return {status: 'UNDETERMINED', conditionIndex: 299, conditionText: "extract('CA10Z1__monitorCpuPercentAvg30Day__c').isEmpty() || extract('CA10Z1__monitorMemoryPercentAvg30Day__c').isEmpty() || extract('CA10Z1__monitorIoConsumptionPercentAvg30Day__c').isEmpty()", currentStateMessage: "There is not enough data in the CMDB to identify if the server is underutilized.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
      }
      // condition[3], conditionIndex:[300..399]
      function extract16() { if (!this.out) { this.out = obj.CA10Z1__monitorCpuPercentAvg30Day__c; } return this.out; };
      function extract19() { if (!this.out) { this.out = obj.CA10Z1__monitorIoConsumptionPercentAvg30Day__c; } return this.out; };
      if ((extract16.call(extract16) != null && 5.0 != null && extract16.call(extract16) < 5.0) && extract19.call(extract19) == 0.0) {
          return {status: 'INAPPLICABLE', conditionIndex: 399, conditionText: "extract('CA10Z1__monitorCpuPercentAvg30Day__c') < number(5.0) && extract('CA10Z1__monitorIoConsumptionPercentAvg30Day__c') == number(0.0)", currentStateMessage: "The server is idle and considered by the 'Azure PostgreSQL Server is Idle' policy.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
      }
      // condition[4], conditionIndex:[400..499]
      function extract23() { if (!this.out) { this.out = obj.CA10Z1__monitorCpuPercentAvg30Day__c; } return this.out; };
      function extract27() { if (!this.out) { this.out = obj.CA10Z1__monitorMemoryPercentAvg30Day__c; } return this.out; };
      function extract31() { if (!this.out) { this.out = obj.CA10Z1__monitorIoConsumptionPercentAvg30Day__c; } return this.out; };
      if ((extract23.call(extract23) != null && 20.0 != null && extract23.call(extract23) < 20.0) && (extract27.call(extract27) != null && 40.0 != null && extract27.call(extract27) < 40.0) && (extract31.call(extract31) != null && 20.0 != null && extract31.call(extract31) < 20.0)) {
          return {status: 'INCOMPLIANT', conditionIndex: 499, conditionText: "extract('CA10Z1__monitorCpuPercentAvg30Day__c') < number(20.0) && extract('CA10Z1__monitorMemoryPercentAvg30Day__c') < number(40.0) && extract('CA10Z1__monitorIoConsumptionPercentAvg30Day__c') < number(20.0)", currentStateMessage: "The server is underutilized with Average CPU and IO < 20%, and Memory < 40%.", currentStateReferences: references1.join('\n'), remediation: "Consider rightsizing, the server.", runtimeError: null};
      }
      return {status: 'COMPLIANT', conditionIndex: 500, conditionText: "otherwise", currentStateMessage: "The server is not underutilized.", 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.CA10Z1__disappearanceTime__c AS CA10Z1__disappearanceTime__c,
          sObject.CA10Z1__state__c AS CA10Z1__state__c,
          sObject.CA10Z1__monitorCpuPercentAvg30Day__c AS CA10Z1__monitorCpuPercentAvg30Day__c,
          sObject.CA10Z1__monitorMemoryPercentAvg30Day__c AS CA10Z1__monitorMemoryPercentAvg30Day__c,
          sObject.CA10Z1__monitorIoConsumptionPercentAvg30Day__c AS CA10Z1__monitorIoConsumptionPercentAvg30Day__c,
          process_CA10Z1__CaAzurePostgreSqlServer__c(
              STRUCT(
                  sObject.Id AS Id,
                  sObject.CA10Z1__disappearanceTime__c AS CA10Z1__disappearanceTime__c,
                  sObject.CA10Z1__state__c AS CA10Z1__state__c,
                  sObject.CA10Z1__monitorCpuPercentAvg30Day__c AS CA10Z1__monitorCpuPercentAvg30Day__c,
                  sObject.CA10Z1__monitorMemoryPercentAvg30Day__c AS CA10Z1__monitorMemoryPercentAvg30Day__c,
                  sObject.CA10Z1__monitorIoConsumptionPercentAvg30Day__c AS CA10Z1__monitorIoConsumptionPercentAvg30Day__c
              ),
              sObject.context.snapshotTime
          ) as result
      FROM UNNEST(mock_CA10Z1__CaAzurePostgreSqlServer__c()) AS sObject
  ) sObject ON sObject.Id = expectedResult.Id;
