--- policy: /ce/ca/aws/elasticache/memcached-cluster-underutilized logic: /ce/ca/aws/elasticache/memcached-cluster-underutilized/prod.logic.yaml executionTime: 2026-06-06T12:02:53.413146Z generationMs: 49 executionMs: 884 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: 299 actual: 299 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: 399 actual: 399 conditionText: expected: not(extract('CA10__createTime__c').beyondLastDays(30)) actual: not(extract('CA10__createTime__c').beyondLastDays(30)) runtimeError: {} - id: '004' match: true status: expected: INCOMPLIANT actual: INCOMPLIANT conditionIndex: expected: 599 actual: 599 conditionText: expected: extract('CA10__cpuUtilizationAvg30d__c') < number(40.0) actual: extract('CA10__cpuUtilizationAvg30d__c') < number(40.0) runtimeError: {} - id: '005' match: true status: expected: COMPLIANT actual: COMPLIANT conditionIndex: expected: 600 actual: 600 conditionText: expected: otherwise actual: otherwise runtimeError: {} - id: '006' match: true status: expected: INAPPLICABLE actual: INAPPLICABLE conditionIndex: expected: 199 actual: 199 conditionText: expected: extract('CA10__engine__c') != 'memcached' actual: extract('CA10__engine__c') != 'memcached' runtimeError: {} usedFiles: - path: /ce/ca/aws/elasticache/memcached-cluster-underutilized/policy.yaml md5Hash: 3CBFAAC238A3793EC479B6438DFF7104 content: |- --- names: full: AWS ElastiCache Memcached Cluster is underutilized contextual: Memcached Cluster is underutilized description: "Memcached Clusters are considered underutilized if their average \ \ CPU utilization is consistently below 40% over a 30-day period. \ \ These clusters might be oversized for their workload." type: "COMPLIANCE_POLICY" categories: - "COST" - "PERFORMANCE" frameworkMappings: - "/frameworks/cloudaware/cost-efficiency-and-optimization/resource-right-sizing" - "/frameworks/cloudaware/resource-performance/workload-efficiency" - path: /ce/ca/aws/elasticache/memcached-cluster-underutilized/prod.logic.yaml md5Hash: 78329603BAB4A62232855124A6073DF6 content: | --- inputType: "CA10__CaAwsCacheCluster__c" importExtracts: - file: "/types/CA10__CaAwsCacheCluster__c/object.extracts.yaml" testData: - file: 'test-data.json' conditions: - status: "INAPPLICABLE" currentStateMessage: "This policy is only applicable to Memcached clusters." check: NOT_EQUAL: left: EXTRACT: "CA10__engine__c" right: TEXT: "memcached" - status: "INAPPLICABLE" currentStateMessage: "The cluster is not available." check: NOT_EQUAL: left: EXTRACT: "CA10__status__c" right: TEXT: "available" - status: "INAPPLICABLE" currentStateMessage: "The cluster was 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 determine whether the cluster is underutilized." check: IS_EMPTY: arg: EXTRACT: "CA10__cpuUtilizationAvg30d__c" - status: "INCOMPLIANT" currentStateMessage: "The cluster is underutilized with average CPU utilization below 40%." remediationMessage: "Rightsize, consolidate, or terminate the cluster." check: LESS_THAN: left: EXTRACT: CA10__cpuUtilizationAvg30d__c right: NUMBER: 40.0 otherwise: status: "COMPLIANT" currentStateMessage: "The cluster is not underutilized." - path: /ce/ca/aws/elasticache/memcached-cluster-underutilized/test-data.json md5Hash: 53609EFDECD2913716020AC396501827 content: |- [ { "expectedResult": { "status": "DISAPPEARED", "conditionIndex": "99", "conditionText": "isDisappeared(CA10__disappearanceTime__c)", "runtimeError": null }, "context": { "snapshotTime": "2025-07-30T08:52:21Z" }, "Id": "001", "CA10__disappearanceTime__c": "2025-07-24T18:40:10Z", "CA10__engine__c": "memcached", "CA10__status__c": "available", "CA10__createTime__c": "2025-07-24T16:53:38Z", "CA10__cpuUtilizationAvg30d__c": null }, { "expectedResult": { "status": "INAPPLICABLE", "conditionIndex": "299", "conditionText": "extract('CA10__status__c') != 'available'", "runtimeError": null }, "context": { "snapshotTime": "2025-07-30T08:52:21Z" }, "Id": "002", "CA10__disappearanceTime__c": null, "CA10__engine__c": "memcached", "CA10__status__c": "stopped", "CA10__createTime__c": "2025-07-15T10:39:29Z", "CA10__cpuUtilizationAvg30d__c": 2.0 }, { "expectedResult": { "status": "INAPPLICABLE", "conditionIndex": "399", "conditionText": "not(extract('CA10__createTime__c').beyondLastDays(30))", "runtimeError": null }, "context": { "snapshotTime": "2025-07-30T08:52:21Z" }, "Id": "003", "CA10__disappearanceTime__c": null, "CA10__engine__c": "memcached", "CA10__status__c": "available", "CA10__createTime__c": "2025-07-15T10:39:29Z", "CA10__cpuUtilizationAvg30d__c": 2.0 }, { "expectedResult": { "status": "INCOMPLIANT", "conditionIndex": "599", "conditionText": "extract('CA10__cpuUtilizationAvg30d__c') < number(40.0)", "runtimeError": null }, "context": { "snapshotTime": "2025-07-30T08:52:21Z" }, "Id": "004", "CA10__disappearanceTime__c": null, "CA10__engine__c": "memcached", "CA10__status__c": "available", "CA10__createTime__c": "2020-09-08T10:16:24Z", "CA10__cpuUtilizationAvg30d__c": 1.0 }, { "expectedResult": { "status": "COMPLIANT", "conditionIndex": "600", "conditionText": "otherwise", "runtimeError": null }, "context": { "snapshotTime": "2025-07-30T08:52:21Z" }, "Id": "005", "CA10__disappearanceTime__c": null, "CA10__engine__c": "memcached", "CA10__status__c": "available", "CA10__createTime__c": "2024-07-18T21:01:25Z", "CA10__cpuUtilizationAvg30d__c": 40.0 }, { "expectedResult": { "status": "INAPPLICABLE", "conditionIndex": "199", "conditionText": "extract('CA10__engine__c') != 'memcached'", "runtimeError": null }, "context": { "snapshotTime": "2025-07-30T08:52:21Z" }, "Id": "006", "CA10__disappearanceTime__c": null, "CA10__engine__c": "redis", "CA10__status__c": "stopped", "CA10__createTime__c": "2025-07-15T10:39:29Z", "CA10__cpuUtilizationAvg30d__c": 2.0 } ] - path: /types/CA10__CaAwsCacheCluster__c/object.extracts.yaml md5Hash: 149E948C3FC56157AFB5E33CEAD7558E content: "---\nextracts:\n# Values: available, creating, deleted, deleting, incompatible-network,\ \ modifying, \n# rebooting cluster nodes, restore-failed, snapshotting\n# Not\ \ nullable. Can't have no access, retrieved via elasticache:DescribeCacheClusters\n\ \ - name: \"CA10__status__c\"\n value:\n FIELD:\n path: \"CA10__status__c\"\ \n undeterminedIf:\n isEmpty: \"Corrupted data. Status cannot\ \ be empty.\" \n# Values: memcached | redis. Not nullable. Can't have no access,\ \ retrieved via elasticache:DescribeCacheClusters\n - name: \"CA10__engine__c\"\ \n value:\n FIELD:\n path: \"CA10__engine__c\"\n undeterminedIf:\n\ \ isEmpty: \"Corrupted data. Engine cannot be empty.\"\n# Date/Time\n\ \ - name: \"CA10__createTime__c\"\n value:\n FIELD:\n path:\ \ \"CA10__createTime__c\"\n# Percent\n - name: \"CA10__cpuUtilizationAvg30d__c\"\ \n value:\n FIELD:\n path: \"CA10__cpuUtilizationAvg30d__c\"\n\ # Checkbox. Can't have no access, retrieved via elasticache:DescribeCacheClusters\n\ \ - name: \"CA10__autoMinorVersionUpgrade__c\"\n value:\n FIELD:\n\ \ path: \"CA10__autoMinorVersionUpgrade__c\"\n# Not nullable. Can't have\ \ no access, retrieved via elasticache:DescribeCacheClusters\n - name: \"CA10__snapshotRetentionLimit__c\"\ \n value:\n FIELD:\n path: \"CA10__snapshotRetentionLimit__c\"\ \n undeterminedIf:\n isEmpty: \"Corrupted data. Snapshot Retention\ \ Limit cannot be empty.\"\n" script: |- CREATE TEMP FUNCTION mock_ExpectedResult() RETURNS ARRAY >> 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" : "299", "conditionText" : "extract('CA10__status__c') != 'available'", "runtimeError" : null } }, { "Id" : "003", "expectedResult" : { "status" : "INAPPLICABLE", "conditionIndex" : "399", "conditionText" : "not(extract('CA10__createTime__c').beyondLastDays(30))", "runtimeError" : null } }, { "Id" : "004", "expectedResult" : { "status" : "INCOMPLIANT", "conditionIndex" : "599", "conditionText" : "extract('CA10__cpuUtilizationAvg30d__c') < number(40.0)", "runtimeError" : null } }, { "Id" : "005", "expectedResult" : { "status" : "COMPLIANT", "conditionIndex" : "600", "conditionText" : "otherwise", "runtimeError" : null } }, { "Id" : "006", "expectedResult" : { "status" : "INAPPLICABLE", "conditionIndex" : "199", "conditionText" : "extract('CA10__engine__c') != 'memcached'", "runtimeError" : null } } ]; """; CREATE TEMP FUNCTION mock_CA10__CaAwsCacheCluster__c() RETURNS ARRAY >> DETERMINISTIC LANGUAGE js AS r""" return [ { "context" : { "snapshotTime" : new Date("2025-07-30T08:52:21Z") }, "CA10__disappearanceTime__c" : new Date("2025-07-24T18:40:10Z"), "CA10__engine__c" : "memcached", "CA10__status__c" : "available", "CA10__createTime__c" : new Date("2025-07-24T16:53:38Z"), "CA10__cpuUtilizationAvg30d__c" : null, "Id" : "001" }, { "context" : { "snapshotTime" : new Date("2025-07-30T08:52:21Z") }, "CA10__engine__c" : "memcached", "CA10__status__c" : "stopped", "CA10__createTime__c" : new Date("2025-07-15T10:39:29Z"), "CA10__cpuUtilizationAvg30d__c" : 2.0, "Id" : "002" }, { "context" : { "snapshotTime" : new Date("2025-07-30T08:52:21Z") }, "CA10__engine__c" : "memcached", "CA10__status__c" : "available", "CA10__createTime__c" : new Date("2025-07-15T10:39:29Z"), "CA10__cpuUtilizationAvg30d__c" : 2.0, "Id" : "003" }, { "context" : { "snapshotTime" : new Date("2025-07-30T08:52:21Z") }, "CA10__engine__c" : "memcached", "CA10__status__c" : "available", "CA10__createTime__c" : new Date("2020-09-08T10:16:24Z"), "CA10__cpuUtilizationAvg30d__c" : 1.0, "Id" : "004" }, { "context" : { "snapshotTime" : new Date("2025-07-30T08:52:21Z") }, "CA10__engine__c" : "memcached", "CA10__status__c" : "available", "CA10__createTime__c" : new Date("2024-07-18T21:01:25Z"), "CA10__cpuUtilizationAvg30d__c" : 40.0, "Id" : "005" }, { "context" : { "snapshotTime" : new Date("2025-07-30T08:52:21Z") }, "CA10__engine__c" : "redis", "CA10__status__c" : "stopped", "CA10__createTime__c" : new Date("2025-07-15T10:39:29Z"), "CA10__cpuUtilizationAvg30d__c" : 2.0, "Id" : "006" } ]; """; CREATE TEMP FUNCTION process_CA10__CaAwsCacheCluster__c( obj STRUCT< CA10__disappearanceTime__c TIMESTAMP, CA10__engine__c STRING, CA10__status__c STRING, CA10__createTime__c TIMESTAMP, CA10__cpuUtilizationAvg30d__c FLOAT64, Id STRING >, snapshotTime TIMESTAMP ) RETURNS STRUCT DETERMINISTIC LANGUAGE js AS r""" var IsEmptyLib = new function () { this.simpleIsEmpty = function(arg) { return arg == null; }; this.simpleIsNotEmpty = function(arg) { return arg != null; }; }(); 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 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 fieldChecked4() { if (TextLib.isEmpty(obj.CA10__engine__c)) { throw new Error("UNDETERMINED condition:101", {cause: {status: 'UNDETERMINED', conditionIndex: 101, conditionText: "CA10__engine__c.isEmpty()", currentStateMessage: "Corrupted data. Engine cannot be empty.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}}); } return obj.CA10__engine__c; } function extract3() { if (!this.out) { this.out = fieldChecked4(); } return this.out; }; references1.push('Engine [obj.CA10__engine__c]: ' + obj.CA10__engine__c); try { if (TextLib.notEqual(extract3.call(extract3), 'memcached')) { return {status: 'INAPPLICABLE', conditionIndex: 199, conditionText: "extract('CA10__engine__c') != 'memcached'", currentStateMessage: "This policy is only applicable to Memcached clusters.", 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 fieldChecked7() { if (TextLib.isEmpty(obj.CA10__status__c)) { throw new Error("UNDETERMINED condition:201", {cause: {status: 'UNDETERMINED', conditionIndex: 201, conditionText: "CA10__status__c.isEmpty()", currentStateMessage: "Corrupted data. Status cannot be empty.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}}); } return obj.CA10__status__c; } function extract6() { if (!this.out) { this.out = fieldChecked7(); } return this.out; }; references1.push('Status [obj.CA10__status__c]: ' + obj.CA10__status__c); try { if (TextLib.notEqual(extract6.call(extract6), 'available')) { return {status: 'INAPPLICABLE', conditionIndex: 299, conditionText: "extract('CA10__status__c') != 'available'", currentStateMessage: "The cluster is not available.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}; } } catch (err) { if (err.cause && err.cause.status) { return err.cause; } else { throw err; } } // condition[3], conditionIndex:[300..399] function extract9() { 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 (!(extract9.call(extract9) != null && extract9.call(extract9).getTime() < todayMinus30Day)) { return {status: 'INAPPLICABLE', conditionIndex: 399, conditionText: "not(extract('CA10__createTime__c').beyondLastDays(30))", currentStateMessage: "The cluster was created less than 30 days ago.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}; } // condition[4], conditionIndex:[400..499] function extract13() { if (!this.out) { this.out = obj.CA10__cpuUtilizationAvg30d__c; } return this.out; }; references1.push('CloudWatch: CPU, 30-Day [obj.CA10__cpuUtilizationAvg30d__c]: ' + obj.CA10__cpuUtilizationAvg30d__c); if (IsEmptyLib.simpleIsEmpty(extract13.call(extract13))) { return {status: 'UNDETERMINED', conditionIndex: 499, conditionText: "extract('CA10__cpuUtilizationAvg30d__c').isEmpty()", currentStateMessage: "There is not enough data in the CMDB to determine whether the cluster is underutilized.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}; } // condition[5], conditionIndex:[500..599] function extract17() { if (!this.out) { this.out = obj.CA10__cpuUtilizationAvg30d__c; } return this.out; }; if (extract17.call(extract17) != null && 40.0 != null && extract17.call(extract17) < 40.0) { return {status: 'INCOMPLIANT', conditionIndex: 599, conditionText: "extract('CA10__cpuUtilizationAvg30d__c') < number(40.0)", currentStateMessage: "The cluster is underutilized with average CPU utilization below 40%.", currentStateReferences: references1.join('\n'), remediation: "Rightsize, consolidate, or terminate the cluster.", runtimeError: null}; } return {status: 'COMPLIANT', conditionIndex: 600, conditionText: "otherwise", currentStateMessage: "The cluster 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.CA10__disappearanceTime__c AS CA10__disappearanceTime__c, sObject.CA10__engine__c AS CA10__engine__c, sObject.CA10__status__c AS CA10__status__c, sObject.CA10__createTime__c AS CA10__createTime__c, sObject.CA10__cpuUtilizationAvg30d__c AS CA10__cpuUtilizationAvg30d__c, sObject.Id AS Id, process_CA10__CaAwsCacheCluster__c( STRUCT( sObject.CA10__disappearanceTime__c AS CA10__disappearanceTime__c, sObject.CA10__engine__c AS CA10__engine__c, sObject.CA10__status__c AS CA10__status__c, sObject.CA10__createTime__c AS CA10__createTime__c, sObject.CA10__cpuUtilizationAvg30d__c AS CA10__cpuUtilizationAvg30d__c, sObject.Id AS Id ), sObject.context.snapshotTime ) as result FROM UNNEST(mock_CA10__CaAwsCacheCluster__c()) AS sObject ) sObject ON sObject.Id = expectedResult.Id;