Skip to content

Commit acb9282

Browse files
CMDB Utility scripts added to improve the effectiveness and precision of CMDB management (#1473)
* Created unUsedCIs.js to detect stale CIs This script is used to identify unused Configuration Items (CIs) in the CMDB that have not been updated within a specified number of days. * Create populateMissingManufacturers.js This script is used in ServiceNow to automatically populate the manufacturer field for CIs (Configuration Items) in the CMDB (Configuration Management Database) . * Create detectDuplicateCIs.js This script is designed to detect duplicate Configuration Items (CIs) in the CMDB (Configuration Management Database) in ServiceNow. * Create readme.md Created readme.md file which contains the detailed description for the three CMDB Utility scripts. Three CMDB utility scripts improve the effectiveness and precision of CMDB management.
1 parent e218791 commit acb9282

File tree

4 files changed

+51
-0
lines changed

4 files changed

+51
-0
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
var gr = new GlideAggregate('cmdb_ci');
2+
gr.addAggregate('COUNT', 'name');
3+
gr.groupBy('name'); // You can change this to 'serial_number' or 'asset_tag'
4+
gr.query();
5+
6+
while (gr.next()) {
7+
if (gr.getAggregate('COUNT', 'name') > 1) {
8+
gs.info('Duplicate CI found for: ' + gr.name + ', Count: ' + gr.getAggregate('COUNT', 'name'));
9+
}
10+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
var modelToManufacturer = {
2+
'HP Model X': 'HP',
3+
'Dell Model Y': 'Dell'
4+
// Add more model to manufacturer mappings
5+
};
6+
7+
var gr = new GlideRecord('cmdb_ci');
8+
//I am finding CIs where Manufacturer field is null
9+
gr.addNullQuery('manufacturer');
10+
//You can modify the query to further filter the CIs, for example, to target only active CIs or those belonging
11+
//to a specific CI class (e.g., servers or routers):
12+
//gr.addQuery('install_status', '=', '1'); // Only query active CIs
13+
//gr.addQuery('sys_class_name', '=', 'cmdb_ci_server'); // Only query server CIs
14+
gr.query();
15+
16+
while (gr.next()) {
17+
var model = gr.model_id.name;
18+
if (modelToManufacturer[model]) {
19+
gr.manufacturer = modelToManufacturer[model];
20+
gr.update();
21+
gs.info('Updated manufacturer for CI: ' + gr.name);
22+
}
23+
}

CMDB/CMDB Utility Scripts/readme.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
The CMDVB Utility Scripts:
2+
1. unused CIs: This script is used to identify unused Configuration Items (CIs) in the CMDB that have not been updated within a specified number of days. The primary goal is to flag CIs that may be outdated or not maintained. In the script one can provide for the number of days to check for the
3+
CIs that haven't been be used for 'd' days.
4+
5+
2. detectDuplicates.js: This script is designed to detect duplicate Configuration Items (CIs) in the CMDB (Configuration Management Database) in ServiceNow. Duplicate CIs can cause data quality issues and interfere with processes such as asset management, incident management, and change management. By identifying CIs with the same values in specific fields (like name, serial number, or asset tag), the script helps maintain the integrity of the CMDB.
6+
7+
3. populateMissingManufacturers.js: This script is used in ServiceNow to automatically populate the manufacturer field for CIs (Configuration Items) in the CMDB (Configuration Management Database) when the manufacturer field is missing (null). It uses a predefined mapping between models and their respective manufacturers, and updates the CIs accordingly.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
var grCI = new GlideRecord('cmdb_ci');
2+
//Specify the threshold days
3+
var daysThreshold = 30;
4+
var dateThreshold = gs.daysAgo(daysThreshold);
5+
6+
grCI.addQuery('sys_updated_on', '<', dateThreshold);
7+
grCI.query();
8+
9+
while (grCI.next()) {
10+
gs.info('Unused CI: ' + grCI.name + ', Last Updated: ' + grCI.sys_updated_on);
11+
}

0 commit comments

Comments
 (0)