Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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));
43 changes: 43 additions & 0 deletions Specialized Areas/ITOM/Track Discovery Status/readme.md
Original file line number Diff line number Diff line change
@@ -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.
Loading