From e977bed172a2e435d6ba42b423e7e84a096b2e75 Mon Sep 17 00:00:00 2001 From: Mahesh Khatal <112764461+maheshkhatal27@users.noreply.github.com> Date: Mon, 6 Oct 2025 01:39:18 +0530 Subject: [PATCH 1/2] Create readme.md This script helps identify whether specific IP addresses were successfully discovered after migration and shows which discovery status each IP belongs to. It enables quick troubleshooting and significantly reduces investigation time. --- .../ITOM/Track Discovery Status/readme.md | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 Specialized Areas/ITOM/Track Discovery Status/readme.md 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..ff8b97ca91 --- /dev/null +++ b/Specialized Areas/ITOM/Track Discovery Status/readme.md @@ -0,0 +1,43 @@ +After a recent migration, the client wanted a quick and reliable way to verify whether specific IP addresses were being discovered by ServiceNow Discovery, and if so, determine which Discovery Status records they were associated with. + +This requirement was critical to help the client: + +Identify IPs that were discovered successfully. + +Find those that were not rediscovered after migration. + +Diagnose potential discovery or configuration issues efficiently. + +The script provided below serves as a powerful troubleshooting utility. It allows administrators to instantly check which discovery job (status) a given IP address belongs to, enabling faster debugging and drastically reducing resolution time. + +What the Script Does + +The script performs the following steps: + +Takes a list of IP addresses as input. + +Looks up each IP in the cmdb_ci_computer table(It could be Linux, AIX,etc.) to find its corresponding Configuration Item (CI). + +Queries the Discovery Device History (discovery_device_history) to determine whether the CI was created or updated by a discovery process. + +Builds a JSON array mapping each IP address to its respective discovery status number (e.g., DIS123145). + +Prints the result in the system logs for quick review and validation. + +Example 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"} +] + +Benefits + +Saves significant debugging and analysis time. + +Helps identify why certain CIs stopped being discovered after migration. + +Provides clear mapping between IP addresses and their last discovery statuses. + +Enables faster root cause analysis and improves operational efficiency. From f2f0a2ce5a332b0252899b2ffba0c23c3c034ccf Mon Sep 17 00:00:00 2001 From: Mahesh Khatal <112764461+maheshkhatal27@users.noreply.github.com> Date: Mon, 6 Oct 2025 01:41:57 +0530 Subject: [PATCH 2/2] Create discovery_ip_status.js This script maps a list of IP addresses to their corresponding Discovery Status in ServiceNow. It checks each IP in the CMDB for a matching CI record, retrieves the related discovery status from the discovery_device_history table, and returns a structured list showing which discovery status each IP belongs to. --- .../discovery_ip_status.js | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 Specialized Areas/ITOM/Track Discovery Status/discovery_ip_status.js diff --git a/Specialized Areas/ITOM/Track Discovery Status/discovery_ip_status.js b/Specialized Areas/ITOM/Track Discovery Status/discovery_ip_status.js new file mode 100644 index 0000000000..0f1fad2338 --- /dev/null +++ b/Specialized Areas/ITOM/Track Discovery Status/discovery_ip_status.js @@ -0,0 +1,57 @@ +// Array of IP addresses to check +var ipAddressLists = ['192.168.1.35', '192.168.1.27', '192.168.1.15']; + +// CMDB table where CI records are stored(Could be Linux/Unix,AIX server,etc) +var ciTableName = 'cmdb_ci_computer'; + +// Array to hold the final output objects +var ipDiscoveryMapping = []; + +// Loop through each IP address in the list +for (var i = 0; i < ipAddressLists.length; i++) { + var ip = ipAddressLists[i]; + + // Query the CMDB to find the CI record with the given IP address + var ciRecord = new GlideRecord(ciTableName); + ciRecord.addEncodedQuery('ip_address=' + ip); + ciRecord.query(); + + // Proceed only if a CI record is found for this IP + if (ciRecord.next()) { + + // Query discovery_device_history to find the related discovery status + var deviceHistoryGr = new GlideRecord('discovery_device_history'); + deviceHistoryGr.addEncodedQuery( + 'cmdb_ci=' + ciRecord.getUniqueValue() + + '^last_state=Created CI^ORlast_state=Updated CI' + ); + deviceHistoryGr.query(); + + // If discovery history exists, capture its status number + if (deviceHistoryGr.next()) { + // Create an object with IP and discovery status number + var recordObj = { + ip_address: ip, + discovery_status_number: deviceHistoryGr.getDisplayValue('status') + }; + ipDiscoveryMapping.push(recordObj); + } else { + // Optional: handle case where no discovery status found + var noStatusObj = { + ip_address: ip, + discovery_status_number: 'No discovery record found' + }; + ipDiscoveryMapping.push(noStatusObj); + } + } else { + // Optional: handle case where no CI record found + var noCIObj = { + ip_address: ip, + discovery_status_number: 'No CI found for this IP' + }; + ipDiscoveryMapping.push(noCIObj); + } +} + +// Log the final array of IP–Discovery Status mappings +gs.info('IP to Discovery Status mapping: ' + JSON.stringify(ipDiscoveryMapping));