diff --git a/Specialized Areas/ITOM/Track Discovery Status/CheckDiscoveryStatus.js b/Specialized Areas/ITOM/Track Discovery Status/CheckDiscoveryStatus.js new file mode 100644 index 0000000000..13780ae83c --- /dev/null +++ b/Specialized Areas/ITOM/Track Discovery Status/CheckDiscoveryStatus.js @@ -0,0 +1,74 @@ +// Configuration // +// Define the list of IP addresses to check +var ipList = [ + '192.168.1.35', + '192.168.1.27', + '192.168.1.15' +]; + +// Main Script // +var results = []; + +ipList.forEach(function(ip) { + var result = { + ip_address: ip, + discovery_status_number: '' + }; + + //Find CI (Computer) with matching IP + var ciGR = new GlideRecord('cmdb_ci_computer'); + ciGR.addQuery('ip_address', ip); + ciGR.query(); + + if (ciGR.next()) { + var ciSysId = ciGR.getUniqueValue(); + + //Check if CI has an entry in discovery_device_history + var historyGR = new GlideRecord('discovery_device_history'); + historyGR.addQuery('ci', ciSysId); + historyGR.orderByDesc('sys_created_on'); + historyGR.query(); + + if (historyGR.next()) { + + //Get discovery status number (e.g., DIS123456) + var statusGR = new GlideRecord('discovery_status'); + if (statusGR.get(historyGR.discovery_status.toString())) { + result.discovery_status_number = statusGR.number.toString(); + } else { + result.discovery_status_number = 'Discovery status record not found'; + } + } else { + result.discovery_status_number = 'No discovery record found'; + } + } else { + result.discovery_status_number = 'No CI found with this IP'; + } + + results.push(result); +}); + +// Output results to system log in JSON format + +gs.info('IP to Discovery Status Mapping:\n' + JSON.stringify(results, null, 2)); + + + + +//Output// + +[ + { + "ip_address": "192.168.1.35", + "discovery_status_number": "DIS123145" + }, + { + "ip_address": "192.168.1.27", + "discovery_status_number": "DIS123189" + }, + { + "ip_address": "192.168.1.15", + "discovery_status_number": "No discovery record found" + } +] + diff --git a/Specialized Areas/ITOM/Track Discovery Status/ReadME.md b/Specialized Areas/ITOM/Track Discovery Status/ReadME.md new file mode 100644 index 0000000000..bfde3dbbc8 --- /dev/null +++ b/Specialized Areas/ITOM/Track Discovery Status/ReadME.md @@ -0,0 +1,10 @@ +Defines a list of IP addresses to check (hardcoded in the script). +Example IPs: 192.168.1.35, 192.168.1.27, 192.168.1.15. +For each IP address in the list: +It looks up the CI (Configuration Item) in the cmdb_ci_computer table with a matching IP. +If a CI is found: +It checks the discovery_device_history table to see if that CI was discovered by ServiceNow Discovery. +If discovery history exists, it finds the related Discovery Status record (discovery_status table) and gets its number (like DIS123456). +If no CI or discovery record is found, it notes the reason in the result. +Compiles all results (IP + discovery status or error message) into a list. +Prints the results in a clear JSON format in the system logs, making it easy to read and review.