diff --git a/Specialized Areas/CMDB/Class-Based Attribute Completeness Report/README.md b/Specialized Areas/CMDB/Class-Based Attribute Completeness Report/README.md new file mode 100644 index 0000000000..3872d001b0 --- /dev/null +++ b/Specialized Areas/CMDB/Class-Based Attribute Completeness Report/README.md @@ -0,0 +1 @@ +This script checks data completeness in the CMDB by identifying missing key fields (like `os` and `location`) across selected CI classes (e.g., servers, applications). It counts how many CIs exist per class and how many are missing each field, helping administrators quickly spot and address data quality issues. This supports CMDB health, audit readiness, and overall data reliability. diff --git a/Specialized Areas/CMDB/Class-Based Attribute Completeness Report/script.js b/Specialized Areas/CMDB/Class-Based Attribute Completeness Report/script.js new file mode 100644 index 0000000000..5618dffc54 --- /dev/null +++ b/Specialized Areas/CMDB/Class-Based Attribute Completeness Report/script.js @@ -0,0 +1,19 @@ +var classes = ['cmdb_ci_win_server', 'cmdb_ci_appl', 'cmdb_ci_computer']; +var fields = ['os', 'location']; + +classes.forEach(function(className) { + var total = new GlideAggregate(className); + total.addAggregate('COUNT'); + total.query(); + var totalCount = total.next() ? total.getAggregate('COUNT') : 0; + + fields.forEach(function(field) { + var missing = new GlideAggregate(className); + missing.addNullQuery(field); + missing.addAggregate('COUNT'); + missing.query(); + var missingCount = missing.next() ? missing.getAggregate('COUNT') : 0; + + gs.print(className + ' | Missing ' + field + ': ' + missingCount + ' / ' + totalCount); + }); +}); diff --git a/Specialized Areas/CMDB/Detect Configuration Drift Compare to Baseline/BusinessRule.js b/Specialized Areas/CMDB/Detect Configuration Drift Compare to Baseline/BusinessRule.js new file mode 100644 index 0000000000..04a6edf5ae --- /dev/null +++ b/Specialized Areas/CMDB/Detect Configuration Drift Compare to Baseline/BusinessRule.js @@ -0,0 +1,34 @@ +(function executeRule(current, previous) { + var baseline = new GlideRecord('cmdb_baseline'); + baseline.addQuery('ci', current.sys_id); + baseline.orderByDesc('sys_created_on'); + baseline.query(); + + if (baseline.next()) { + var drift = false; + var changes = []; + + if (baseline.ram != current.ram) { + drift = true; changes.push('RAM'); + } + + if (baseline.cpu_count != current.cpu_count) { + drift = true; changes.push('CPU'); + } + + if (baseline.os != current.os) { + drift = true; changes.push('OS'); + } + + if (drift) { + var log = new GlideRecord('u_drift_log'); + log.initialize(); + log.u_ci = current.sys_id; + log.u_detected_on = new GlideDateTime(); + log.u_drift_fields = changes.join(', '); + log.insert(); + + gs.eventQueue('ci.drift_detected', current, changes.join(', ')); + } + } +})(current, previous); diff --git a/Specialized Areas/CMDB/Detect Configuration Drift Compare to Baseline/README.md b/Specialized Areas/CMDB/Detect Configuration Drift Compare to Baseline/README.md new file mode 100644 index 0000000000..d451e1a8d8 --- /dev/null +++ b/Specialized Areas/CMDB/Detect Configuration Drift Compare to Baseline/README.md @@ -0,0 +1,9 @@ +This ServiceNow business rule script is designed to detect configuration drift in a Configuration Item (CI) by comparing its current state to the most recent baseline record stored in the cmdb_baseline table. + +What it Does – In Simple Terms: + +Gets the latest baseline for the current CI. +Compares key fields (ram, cpu_count, os) between the current CI and the baseline. +If differences (a "drift") are found: +It logs the drift in a custom table (u_drift_log). +It triggers an event (ci.drift_detected) to possibly notify or take further action.