Writing a script to print duplicate servers
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-23-2024 10:41 AM
// Define the CI classes to search for duplicates
var ciClasses = ['cmdb_ci_win_server', 'cmdb_ci_linux_server'];
// Function to find and print duplicate CIs
function findDuplicates(ciClass) {
var gr = new GlideRecord(ciClass);
gr.addQuery('install_status', '1'); // Active CIs only (modify if needed)
gr.query();
var ciMap = {}; // Object to store unique CIs based on key attributes
while (gr.next()) {
// Combine fields to create a unique key for each CI
var uniqueKey = gr.name.toString() + '-' + gr.serial_number.toString() + '-' + gr.ip_address.toString();
if (ciMap[uniqueKey]) {
// Duplicate found, print the CI details
gs.print('Duplicate CI found:');
gs.print('CI Name: ' + gr.name);
gs.print('Class: ' + ciClass);
gs.print('Operational Status: ' + gr.operational_status.getDisplayValue());
gs.print('Sys ID: ' + gr.sys_id);
gs.print('Discovery Source: ' + gr.discovery_source.getDisplayValue());
gs.print('---');
} else {
// Store the unique key to check against future CIs
ciMap[uniqueKey] = true;
}
}
}
// Loop through each CI class and check for duplicates
for (var i = 0; i < ciClasses.length; i++) {
findDuplicates(ciClasses[i]);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-25-2024 07:41 AM - edited 09-25-2024 07:43 AM
Hi @JaganR ,
If I understood your code and question correctly, you would like to get the details of duplicate servers based on names across 3 cmdb classes. I mean may be same CI name can be in all 3 cmdb classes as well.
I have written a code for you as below, but I could not get chance to run in my PDI, You may try this if it works for you and let me know. If there is any syntactical error or silly mistake please excuse me.
If this address your question, please mark this response correct by clicking on Accept as Solution and/or Kudos.
You may mark this helpful as well if it helps you.
========================
If this address your question, please mark this response correct by clicking on Accept as Solution and/or Kudos.
You may mark this helpful as well if it helps you.
Thanks,
Animesh Das
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-26-2024 09:57 PM
Hi @JaganR ,
If you got chance to check my solution/code please let me know if that worked for you.
If this address your question, please mark this response correct by clicking on Accept as Solution and/or Kudos.
You may mark this helpful as well if it helps you.
Thanks,
Animesh Das