From 4f6b9c699409b66198abf2d90f0b7ece80575461 Mon Sep 17 00:00:00 2001 From: Chetna Sharma <146471211+chetnadev@users.noreply.github.com> Date: Thu, 9 Oct 2025 12:09:17 +0530 Subject: [PATCH 1/3] Create code.js --- .../code.js | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 Specialized Areas/CMDB/Detect Configuration Drift Compare to Baseline/code.js diff --git a/Specialized Areas/CMDB/Detect Configuration Drift Compare to Baseline/code.js b/Specialized Areas/CMDB/Detect Configuration Drift Compare to Baseline/code.js new file mode 100644 index 0000000000..04a6edf5ae --- /dev/null +++ b/Specialized Areas/CMDB/Detect Configuration Drift Compare to Baseline/code.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); From da4533a30d17753c7f8e8ef5869e6dbcbfd64ba7 Mon Sep 17 00:00:00 2001 From: Chetna Sharma <146471211+chetnadev@users.noreply.github.com> Date: Thu, 9 Oct 2025 12:11:39 +0530 Subject: [PATCH 2/3] Create README.md --- .../README.md | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 Specialized Areas/CMDB/Detect Configuration Drift Compare to Baseline/README.md 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..050f6ff12f --- /dev/null +++ b/Specialized Areas/CMDB/Detect Configuration Drift Compare to Baseline/README.md @@ -0,0 +1,8 @@ +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. From cae9179f88cc0732d178153d59a43666cba3b8a2 Mon Sep 17 00:00:00 2001 From: Chetna Sharma <146471211+chetnadev@users.noreply.github.com> Date: Thu, 9 Oct 2025 12:13:03 +0530 Subject: [PATCH 3/3] Update README.md --- .../Detect Configuration Drift Compare to Baseline/README.md | 1 + 1 file changed, 1 insertion(+) 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 index 050f6ff12f..25b8764c0a 100644 --- a/Specialized Areas/CMDB/Detect Configuration Drift Compare to Baseline/README.md +++ b/Specialized Areas/CMDB/Detect Configuration Drift Compare to Baseline/README.md @@ -6,3 +6,4 @@ 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. +.