Skip to content

Commit f49d864

Browse files
Itom disco status (#1833)
1 parent dbe2fa3 commit f49d864

File tree

2 files changed

+100
-0
lines changed

2 files changed

+100
-0
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
// Array of IP addresses to check
2+
var ipAddressLists = ['192.168.1.35', '192.168.1.27', '192.168.1.15'];
3+
4+
// CMDB table where CI records are stored(Could be Linux/Unix,AIX server,etc)
5+
var ciTableName = 'cmdb_ci_computer';
6+
7+
// Array to hold the final output objects
8+
var ipDiscoveryMapping = [];
9+
10+
// Loop through each IP address in the list
11+
for (var i = 0; i < ipAddressLists.length; i++) {
12+
var ip = ipAddressLists[i];
13+
14+
// Query the CMDB to find the CI record with the given IP address
15+
var ciRecord = new GlideRecord(ciTableName);
16+
ciRecord.addEncodedQuery('ip_address=' + ip);
17+
ciRecord.query();
18+
19+
// Proceed only if a CI record is found for this IP
20+
if (ciRecord.next()) {
21+
22+
// Query discovery_device_history to find the related discovery status
23+
var deviceHistoryGr = new GlideRecord('discovery_device_history');
24+
deviceHistoryGr.addEncodedQuery(
25+
'cmdb_ci=' + ciRecord.getUniqueValue() +
26+
'^last_state=Created CI^ORlast_state=Updated CI'
27+
);
28+
deviceHistoryGr.query();
29+
30+
// If discovery history exists, capture its status number
31+
if (deviceHistoryGr.next()) {
32+
// Create an object with IP and discovery status number
33+
var recordObj = {
34+
ip_address: ip,
35+
discovery_status_number: deviceHistoryGr.getDisplayValue('status')
36+
};
37+
ipDiscoveryMapping.push(recordObj);
38+
} else {
39+
// Optional: handle case where no discovery status found
40+
var noStatusObj = {
41+
ip_address: ip,
42+
discovery_status_number: 'No discovery record found'
43+
};
44+
ipDiscoveryMapping.push(noStatusObj);
45+
}
46+
} else {
47+
// Optional: handle case where no CI record found
48+
var noCIObj = {
49+
ip_address: ip,
50+
discovery_status_number: 'No CI found for this IP'
51+
};
52+
ipDiscoveryMapping.push(noCIObj);
53+
}
54+
}
55+
56+
// Log the final array of IP–Discovery Status mappings
57+
gs.info('IP to Discovery Status mapping: ' + JSON.stringify(ipDiscoveryMapping));
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
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.
2+
3+
This requirement was critical to help the client:
4+
5+
Identify IPs that were discovered successfully.
6+
7+
Find those that were not rediscovered after migration.
8+
9+
Diagnose potential discovery or configuration issues efficiently.
10+
11+
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.
12+
13+
What the Script Does
14+
15+
The script performs the following steps:
16+
17+
Takes a list of IP addresses as input.
18+
19+
Looks up each IP in the cmdb_ci_computer table(It could be Linux, AIX,etc.) to find its corresponding Configuration Item (CI).
20+
21+
Queries the Discovery Device History (discovery_device_history) to determine whether the CI was created or updated by a discovery process.
22+
23+
Builds a JSON array mapping each IP address to its respective discovery status number (e.g., DIS123145).
24+
25+
Prints the result in the system logs for quick review and validation.
26+
27+
Example output:
28+
29+
[
30+
{"ip_address": "192.168.1.35", "discovery_status_number": "DIS123145"},
31+
{"ip_address": "192.168.1.27", "discovery_status_number": "DIS123189"},
32+
{"ip_address": "192.168.1.15", "discovery_status_number": "No discovery record found"}
33+
]
34+
35+
Benefits
36+
37+
Saves significant debugging and analysis time.
38+
39+
Helps identify why certain CIs stopped being discovered after migration.
40+
41+
Provides clear mapping between IP addresses and their last discovery statuses.
42+
43+
Enables faster root cause analysis and improves operational efficiency.

0 commit comments

Comments
 (0)