Skip to content

Commit 8a9b3e4

Browse files
Script to Trigger Quick Discovery from Workflow / Flow (#1100)
* README.md * Script to trigger quick discovery Script to trigger quick discovery from workflow or flow * README.md Updated the README.md file
1 parent ecac3c3 commit 8a9b3e4

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

ITOM/Discovery/README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
This code snippet automates the discovery of devices in ServiceNow using MID (Management, Instrumentation, and Discovery) servers by triggering Quick Discovery through a workflow. The code can also be modified for different workflows/ flows as needed.
2+
3+
Key features include:
4+
5+
MID Server Setup: It defines two MID servers to ensure redundancy, which improves the chances of successfully finding devices.
6+
7+
IP Address Retrieval: The code retrieves the IP address to be scanned from the current workflow context.
8+
9+
Discovery Process:
10+
11+
It creates a Discovery object to initiate the process. The script first attempts to find the device using the first MID server. If that fails, it logs a message and tries again with the second MID server. Logging and Status Update: After the discovery attempts, the script logs the results and updates the current context with the discovery status.
12+
13+
This code enhances device discovery in ServiceNow, making the process more reliable by utilizing multiple MID servers.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
var midServer1 = 'SNOWMIDPRD01'; // Rename/input your MID server as per your organization
2+
var midServer2 = 'SNOWMIDPRD02'; // Rename/input your second MID server accordingly
3+
var ipAddressScan = current.variables.ip_address; // IP address to scan
4+
var discovery = new Discovery(); // Create a new Discovery object
5+
6+
// Attempt discovery using the first MID Server
7+
workflow.scratchpad.statusID = discovery.discoveryFromIP(ipAddressScan, midServer1);
8+
9+
// If the first attempt was unsuccessful, try the second MID Server
10+
if (workflow.scratchpad.statusID == null) {
11+
gs.info('Discovery using ' + midServer1 + ' failed. Trying ' + midServer2);
12+
workflow.scratchpad.statusID = discovery.discoveryFromIP(ipAddressScan, midServer2);
13+
}
14+
15+
// Log the results
16+
gs.log('DiscoveryStatusId: ' + workflow.scratchpad.statusID);
17+
gs.log('QuickDiscoveryIPAddress: ' + ipAddressScan);
18+
current.variables.discovery_status = workflow.scratchpad.statusID;

0 commit comments

Comments
 (0)