Skip to content

Script to Trigger Quick Discovery from Workflow / Flow #1100

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Oct 2, 2024
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
13 changes: 13 additions & 0 deletions ITOM/Discovery/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
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.

Key features include:

MID Server Setup: It defines two MID servers to ensure redundancy, which improves the chances of successfully finding devices.

IP Address Retrieval: The code retrieves the IP address to be scanned from the current workflow context.

Discovery Process:

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.

This code enhances device discovery in ServiceNow, making the process more reliable by utilizing multiple MID servers.
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
var midServer1 = 'SNOWMIDPRD01'; // Rename/input your MID server as per your organization
var midServer2 = 'SNOWMIDPRD02'; // Rename/input your second MID server accordingly
var ipAddressScan = current.variables.ip_address; // IP address to scan
var discovery = new Discovery(); // Create a new Discovery object

// Attempt discovery using the first MID Server
workflow.scratchpad.statusID = discovery.discoveryFromIP(ipAddressScan, midServer1);

// If the first attempt was unsuccessful, try the second MID Server
if (workflow.scratchpad.statusID == null) {
gs.info('Discovery using ' + midServer1 + ' failed. Trying ' + midServer2);
workflow.scratchpad.statusID = discovery.discoveryFromIP(ipAddressScan, midServer2);
}

// Log the results
gs.log('DiscoveryStatusId: ' + workflow.scratchpad.statusID);
gs.log('QuickDiscoveryIPAddress: ' + ipAddressScan);
current.variables.discovery_status = workflow.scratchpad.statusID;
Loading