TechTrekwithAJ_ITOM Discovery automate Via Workflow script #2398
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This script is used in ServiceNow to automate device discovery on a network by triggering Quick Discovery using a MID Server. It is typically used within a workflow or flow, where you want to scan a device using its IP address.
It adds reliability by using two MID servers, so if one fails, the other is used as a backup.
Two MID servers are defined to run the discovery process, providing a fallback if the first one fails.
Replace 'mid_server_1' and 'mid_server_2' with actual MID server names or sys_ids.
The script fetches the IP address either from the current record (current.ip_address) or from the inputs.
If no IP address is available, it logs an error and exits.
A helper function is used to initiate Quick Discovery for a specific IP using a specified MID server.
It first attempts discovery using the first MID server.
If successful, it logs the success and updates the record with the status.
If it fails, it logs a warning and tries the second MID server.
If both attempts fail, it logs an error and marks the discovery as failed.
Finally, it updates the record with the outcome and the MID server used.