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,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"
}
]

10 changes: 10 additions & 0 deletions Specialized Areas/ITOM/Track Discovery Status/ReadME.md
Original file line number Diff line number Diff line change
@@ -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.
Loading