---
policy: /ce/ca/aws/rds/instance-overutilized
logic: /ce/ca/aws/rds/instance-overutilized/prod.logic.yaml
executionTime: 2025-10-01T12:45:52.166447332Z
generationMs: 71
executionMs: 794
rows:
  - id: '001'
    match: true
    status:
      expected: DISAPPEARED
      actual: DISAPPEARED
    conditionIndex:
      expected: 99
      actual: 99
    conditionText:
      expected: isDisappeared(CA10__disappearanceTime__c)
      actual: isDisappeared(CA10__disappearanceTime__c)
    runtimeError: {}
  - id: '002'
    match: true
    status:
      expected: INAPPLICABLE
      actual: INAPPLICABLE
    conditionIndex:
      expected: 199
      actual: 199
    conditionText:
      expected: extract('CA10__status__c') != 'available'
      actual: extract('CA10__status__c') != 'available'
    runtimeError: {}
  - id: '003'
    match: true
    status:
      expected: INAPPLICABLE
      actual: INAPPLICABLE
    conditionIndex:
      expected: 299
      actual: 299
    conditionText:
      expected: not(extract('CA10__createTime__c').beyondLastDays(30))
      actual: not(extract('CA10__createTime__c').beyondLastDays(30))
    runtimeError: {}
  - id: '004'
    match: true
    status:
      expected: UNDETERMINED
      actual: UNDETERMINED
    conditionIndex:
      expected: 399
      actual: 399
    conditionText:
      expected: extract('CA10__averageCpuOneMonth__c').isEmpty()
      actual: extract('CA10__averageCpuOneMonth__c').isEmpty()
    runtimeError: {}
  - id: '005'
    match: true
    status:
      expected: INCOMPLIANT
      actual: INCOMPLIANT
    conditionIndex:
      expected: 499
      actual: 499
    conditionText:
      expected: not(extract('CA10__averageCpuOneMonth__c') < number(90.0))
      actual: not(extract('CA10__averageCpuOneMonth__c') < number(90.0))
    runtimeError: {}
  - id: '006'
    match: true
    status:
      expected: COMPLIANT
      actual: COMPLIANT
    conditionIndex:
      expected: 500
      actual: 500
    conditionText:
      expected: otherwise
      actual: otherwise
    runtimeError: {}
usedFiles:
  - path: /ce/ca/aws/rds/instance-overutilized/policy.yaml
    md5Hash: 0416EC8388A241E1A8C9A30E3888F122
    content: "---\nnames:\n  full: \"AWS RDS Instance is overutilized\"\n  contextual:\
      \ \"Instance is overutilized\"\ndescription: \"Identify any AWS RDS Instances\
      \ that appear to be overutilized.\\\n  \\ Instances are considered overutilized\
      \ if its average\\\n  \\ CPU utilization is consistently above 90% 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\"\n\
      \  "
  - path: /ce/ca/aws/rds/instance-overutilized/prod.logic.yaml
    md5Hash: CCBB87B999B5B67AD7AF71CD11122253
    content: |-
      ---
      inputType: "CA10__CaAwsDbInstance__c"
      importExtracts:
        - file: "/types/CA10__CaAwsDbInstance__c/object.extracts.yaml"
      testData:
        - file: 'test-data.json'
      conditions:
        - status: "INAPPLICABLE"
          currentStateMessage: "The instance is not available."
          check:
            NOT_EQUAL:
              left:
                EXTRACT: "CA10__status__c"
              right:
                TEXT: "available"
        - status: "INAPPLICABLE"
          currentStateMessage: "The instance has been created less than 30 days ago."
          check:
            NOT:
              arg:
                IS_BEYOND_LAST_DAYS:
                  offsetDays: 30
                  arg:
                    EXTRACT: "CA10__createTime__c"
        - status: UNDETERMINED
          currentStateMessage: "There is not enough data in the CMDB to identify if the instance is overutilized."
          check:
            IS_EMPTY:
              arg:
                EXTRACT: "CA10__averageCpuOneMonth__c"
        - status: "INCOMPLIANT"
          currentStateMessage: "The instance is overutilized with Average CPU Utilization > 90%"
          remediationMessage: "Consider rightsizing the instance."
          check:
            NOT:
              arg:
                LESS_THAN:
                    left:
                      EXTRACT: "CA10__averageCpuOneMonth__c"
                    right:
                      NUMBER: 90.0
      otherwise:
        status: "COMPLIANT"
        currentStateMessage: "The instance is not overutilized."
  - path: /ce/ca/aws/rds/instance-overutilized/test-data.json
    md5Hash: B5CEDA0BB2CB7C25559EF9BE93FADA72
    content: |
      [
        {
          "expectedResult": {
            "status": "DISAPPEARED",
            "conditionIndex": "99",
            "conditionText": "isDisappeared(CA10__disappearanceTime__c)",
            "runtimeError": null
          },
          "context": { "snapshotTime": "2025-09-26T09:58:29Z" },
          "Id": "001",
          "CA10__disappearanceTime__c": "2025-09-25T08:10:08Z",
          "CA10__status__c": "deleting",
          "CA10__createTime__c": "2020-02-04T07:42:39Z",
          "CA10__averageCpuOneMonth__c": 4.887843966930509
        },
        {
          "expectedResult": {
            "status": "INAPPLICABLE",
            "conditionIndex": "199",
            "conditionText": "extract('CA10__status__c') != 'available'",
            "runtimeError": null
          },
          "context": { "snapshotTime": "2025-09-26T09:58:29Z" },
          "Id": "002",
          "CA10__disappearanceTime__c": null,
          "CA10__status__c": "upgrading",
          "CA10__createTime__c": "2020-10-23T02:12:49Z",
          "CA10__averageCpuOneMonth__c": 31.360004047631566
        },
        {
          "expectedResult": {
            "status": "INAPPLICABLE",
            "conditionIndex": "299",
            "conditionText": "not(extract('CA10__createTime__c').beyondLastDays(30))",
            "runtimeError": null
          },
          "context": { "snapshotTime": "2025-09-26T09:58:29Z" },
          "Id": "003",
          "CA10__disappearanceTime__c": null,
          "CA10__status__c": "available",
          "CA10__createTime__c": "2025-09-23T13:59:29Z",
          "CA10__averageCpuOneMonth__c": 16.5114094188521
        },
        {
          "expectedResult": {
            "status": "UNDETERMINED",
            "conditionIndex": "399",
            "conditionText": "extract('CA10__averageCpuOneMonth__c').isEmpty()",
            "runtimeError": null
          },
          "context": { "snapshotTime": "2025-09-26T09:58:29Z" },
          "Id": "004",
          "CA10__disappearanceTime__c": null,
          "CA10__status__c": "available",
          "CA10__createTime__c": "2017-02-10T11:14:06Z",
          "CA10__averageCpuOneMonth__c": null
        },
        {
          "expectedResult": {
            "status": "INCOMPLIANT",
            "conditionIndex": "499",
            "conditionText": "not(extract('CA10__averageCpuOneMonth__c') < number(90.0))",
            "runtimeError": null
          },
          "context": { "snapshotTime": "2025-09-26T09:58:29Z" },
          "Id": "005",
          "CA10__disappearanceTime__c": null,
          "CA10__status__c": "available",
          "CA10__createTime__c": "2017-02-10T11:14:06Z",
          "CA10__averageCpuOneMonth__c": 95.9032259406938214
        },
        {
          "expectedResult": {
            "status": "COMPLIANT",
            "conditionIndex": "500",
            "conditionText": "otherwise",
            "runtimeError": null
          },
          "context": { "snapshotTime": "2025-09-26T09:58:29Z" },
          "Id": "006",
          "CA10__disappearanceTime__c": null,
          "CA10__status__c": "available",
          "CA10__createTime__c": "2017-02-10T11:14:06Z",
          "CA10__averageCpuOneMonth__c": 5.9032259406938214
        }
      ]
  - path: /types/CA10__CaAwsDbInstance__c/object.extracts.yaml
    md5Hash: 0E769BD71AE72B63B1A02CBF1C462F5B
    content: "---\nextracts:\n# Not Nullable. Can't have no access, retrieved via\
      \ rds:DescribeDBInstances\n  - name: CA10__engine__c\n    value:\n      FIELD:\n\
      \        path: CA10__engine__c\n        undeterminedIf:\n          isEmpty:\
      \ \"Corrupted data. DB Instance Engine cannot be empty.\"\n# Not Nullable. Can't\
      \ have no access, retrieved via rds:DescribeDBInstances\n  - name: CA10__endpointPort__c\n\
      \    value:\n      FIELD:\n        path: CA10__endpointPort__c\n        undeterminedIf:\n\
      \          isEmpty: \"Corrupted data. DB Endpoint Port cannot be empty.\"\n\
      # Checkbox. Can't have no access, retrieved via rds:DescribeDBInstances\n  -\
      \ name: CA10__publiclyAccessible__c\n    value:\n      FIELD:\n        path:\
      \ CA10__publiclyAccessible__c\n# Checkbox. Can't have no access, retrieved via\
      \ rds:DescribeDBInstances\n  - name: CA10__storageEncrypted__c\n    value: \n\
      \      FIELD:\n        path: CA10__storageEncrypted__c\n# Checkbox. Can't have\
      \ no access, retrieved via rds:DescribeDBInstances\n  - name: CA10__autoMinorVersionUpgrade__c\n\
      \    value: \n      FIELD:\n        path: CA10__autoMinorVersionUpgrade__c\n\
      # Checkbox. Can't have no access, retrieved via rds:DescribeDBInstances\n  -\
      \ name: CA10__multiAz__c\n    value: \n      FIELD:\n        path: CA10__multiAz__c\n\
      # Nullable. Values: available, backing-up, creating ...\n  - name: \"CA10__status__c\"\
      \n    value:\n      FIELD:\n        path: \"CA10__status__c\"\n# Nullable.\n\
      \  - name: \"CA10__createTime__c\"\n    value:\n      FIELD:\n        path:\
      \ \"CA10__createTime__c\"\n# Nullable.\n  - name: \"CA10__averageCpuOneMonth__c\"\
      \n    value:\n      FIELD:\n        path: \"CA10__averageCpuOneMonth__c\"\n\
      # Nullable.\n  - name: \"CA10__regionName__c\"\n    value:\n      FIELD:\n \
      \       path: \"CA10__regionName__c\"\n# Nullable.\n  - name: \"CA10__diskReadIopsAvg30d__c\"\
      \n    value:\n      FIELD:\n        path: \"CA10__diskReadIopsAvg30d__c\"\n\
      # Nullable.\n  - name: \"CA10__diskWriteIopsAvg30d__c\"\n    value:\n      FIELD:\n\
      \        path: \"CA10__diskWriteIopsAvg30d__c\"\n# Nullable.\n  - name: \"CA10__databaseConnectionsAvg30d__c\"\
      \n    value:\n      FIELD:\n        path: \"CA10__databaseConnectionsAvg30d__c\""
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(CA10__disappearanceTime__c)",
      "runtimeError" : null
    }
  }, {
    "Id" : "002",
    "expectedResult" : {
      "status" : "INAPPLICABLE",
      "conditionIndex" : "199",
      "conditionText" : "extract('CA10__status__c') != 'available'",
      "runtimeError" : null
    }
  }, {
    "Id" : "003",
    "expectedResult" : {
      "status" : "INAPPLICABLE",
      "conditionIndex" : "299",
      "conditionText" : "not(extract('CA10__createTime__c').beyondLastDays(30))",
      "runtimeError" : null
    }
  }, {
    "Id" : "004",
    "expectedResult" : {
      "status" : "UNDETERMINED",
      "conditionIndex" : "399",
      "conditionText" : "extract('CA10__averageCpuOneMonth__c').isEmpty()",
      "runtimeError" : null
    }
  }, {
    "Id" : "005",
    "expectedResult" : {
      "status" : "INCOMPLIANT",
      "conditionIndex" : "499",
      "conditionText" : "not(extract('CA10__averageCpuOneMonth__c') < number(90.0))",
      "runtimeError" : null
    }
  }, {
    "Id" : "006",
    "expectedResult" : {
      "status" : "COMPLIANT",
      "conditionIndex" : "500",
      "conditionText" : "otherwise",
      "runtimeError" : null
    }
  } ];
  """;

  CREATE TEMP FUNCTION mock_CA10__CaAwsDbInstance__c()
  RETURNS ARRAY<STRUCT<
      Id STRING,
      CA10__disappearanceTime__c TIMESTAMP,
      CA10__status__c STRING,
      CA10__createTime__c TIMESTAMP,
      CA10__averageCpuOneMonth__c FLOAT64,
      context STRUCT<
          snapshotTime TIMESTAMP
      >
  >>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
    return [ {
    "context" : {
      "snapshotTime" : new Date("2025-09-26T09:58:29Z")
    },
    "Id" : "001",
    "CA10__disappearanceTime__c" : new Date("2025-09-25T08:10:08Z"),
    "CA10__status__c" : "deleting",
    "CA10__createTime__c" : new Date("2020-02-04T07:42:39Z"),
    "CA10__averageCpuOneMonth__c" : 4.887843966930509
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-09-26T09:58:29Z")
    },
    "Id" : "002",
    "CA10__status__c" : "upgrading",
    "CA10__createTime__c" : new Date("2020-10-23T02:12:49Z"),
    "CA10__averageCpuOneMonth__c" : 31.360004047631566
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-09-26T09:58:29Z")
    },
    "Id" : "003",
    "CA10__status__c" : "available",
    "CA10__createTime__c" : new Date("2025-09-23T13:59:29Z"),
    "CA10__averageCpuOneMonth__c" : 16.5114094188521
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-09-26T09:58:29Z")
    },
    "Id" : "004",
    "CA10__status__c" : "available",
    "CA10__createTime__c" : new Date("2017-02-10T11:14:06Z"),
    "CA10__averageCpuOneMonth__c" : null
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-09-26T09:58:29Z")
    },
    "Id" : "005",
    "CA10__status__c" : "available",
    "CA10__createTime__c" : new Date("2017-02-10T11:14:06Z"),
    "CA10__averageCpuOneMonth__c" : 95.90322594069382
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-09-26T09:58:29Z")
    },
    "Id" : "006",
    "CA10__status__c" : "available",
    "CA10__createTime__c" : new Date("2017-02-10T11:14:06Z"),
    "CA10__averageCpuOneMonth__c" : 5.9032259406938214
  } ];
  """;

  CREATE TEMP FUNCTION process_CA10__CaAwsDbInstance__c(
      obj STRUCT<
          Id STRING,
          CA10__disappearanceTime__c TIMESTAMP,
          CA10__status__c STRING,
          CA10__createTime__c TIMESTAMP,
          CA10__averageCpuOneMonth__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 todayMinus30Day = new Date(snapshotTime.toISOString().substr(0,10)+'T00:00:00.000Z').getTime() + (-30 * 86400000);
      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 AWS [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 extract3() { if (!this.out) { this.out = obj.CA10__status__c; } return this.out; };
      references1.push('Status [obj.CA10__status__c]: ' + obj.CA10__status__c);
      if (TextLib.notEqual(extract3.call(extract3), 'available')) {
          return {status: 'INAPPLICABLE', conditionIndex: 199, conditionText: "extract('CA10__status__c') != 'available'", currentStateMessage: "The instance is not available.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
      }
      // condition[2], conditionIndex:[200..299]
      function extract6() { if (!this.out) { this.out = obj.CA10__createTime__c; } return this.out; };
      references1.push('Create Time [obj.CA10__createTime__c]: ' + obj.CA10__createTime__c);
      if (!(extract6.call(extract6) != null && extract6.call(extract6).getTime() < todayMinus30Day)) {
          return {status: 'INAPPLICABLE', conditionIndex: 299, conditionText: "not(extract('CA10__createTime__c').beyondLastDays(30))", currentStateMessage: "The instance has been created less than 30 days ago.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
      }
      // condition[3], conditionIndex:[300..399]
      function extract10() { if (!this.out) { this.out = obj.CA10__averageCpuOneMonth__c; } return this.out; };
      references1.push('CloudWatch: CPU, 30-Day [obj.CA10__averageCpuOneMonth__c]: ' + obj.CA10__averageCpuOneMonth__c);
      if (IsEmptyLib.simpleIsEmpty(extract10.call(extract10))) {
          return {status: 'UNDETERMINED', conditionIndex: 399, conditionText: "extract('CA10__averageCpuOneMonth__c').isEmpty()", currentStateMessage: "There is not enough data in the CMDB to identify if the instance is overutilized.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
      }
      // condition[4], conditionIndex:[400..499]
      function extract14() { if (!this.out) { this.out = obj.CA10__averageCpuOneMonth__c; } return this.out; };
      if (!(extract14.call(extract14) != null && 90.0 != null && extract14.call(extract14) < 90.0)) {
          return {status: 'INCOMPLIANT', conditionIndex: 499, conditionText: "not(extract('CA10__averageCpuOneMonth__c') < number(90.0))", currentStateMessage: "The instance is overutilized with Average CPU Utilization > 90%", currentStateReferences: references1.join('\n'), remediation: "Consider rightsizing the instance.", runtimeError: null};
      }
      return {status: 'COMPLIANT', conditionIndex: 500, conditionText: "otherwise", currentStateMessage: "The instance is not overutilized.", 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__disappearanceTime__c AS CA10__disappearanceTime__c,
          sObject.CA10__status__c AS CA10__status__c,
          sObject.CA10__createTime__c AS CA10__createTime__c,
          sObject.CA10__averageCpuOneMonth__c AS CA10__averageCpuOneMonth__c,
          process_CA10__CaAwsDbInstance__c(
              STRUCT(
                  sObject.Id AS Id,
                  sObject.CA10__disappearanceTime__c AS CA10__disappearanceTime__c,
                  sObject.CA10__status__c AS CA10__status__c,
                  sObject.CA10__createTime__c AS CA10__createTime__c,
                  sObject.CA10__averageCpuOneMonth__c AS CA10__averageCpuOneMonth__c
              ),
              sObject.context.snapshotTime
          ) as result
      FROM UNNEST(mock_CA10__CaAwsDbInstance__c()) AS sObject
  ) sObject ON sObject.Id = expectedResult.Id;
