Get IP address from incident Descrption.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-21-2023 04:54 AM
HI,
I have one requirement to get IP address from incident description.
Below is example of incident description.
Alert name - Node is Trigger
Node name -
Device status - Node status is Trigger.
IP address - 24.227.78.411
Device type - Unknown
so Ips are changing in each incident , so I need to get/capture . I have tried below code but no use
///Script///
var regEx = new RegExp('(?<=IP address - ).*', 'j');
var incDesc = fd_data.subflow_inputs.inc.description;
var matchData = regEx.exec(incDesc);
//matchData = parseFloat(matchData);
return matchData.toString();
I am not getting output , Please help me.
Thanks in advance.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-21-2023 05:18 AM
Hi @ack ,
Please see below:
The string is the incident description,.
Create a Fix Script and use the following code snippet:
var gr = new GlideRecord("incident");
// Replace the sys id with your incident sys id
gr.get("8639745d079931104185f0269c1ed0dc");
var inputString = gr.description;
// Define the regular expression pattern
var ipAddressRegex = /\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b/;
// Use JavaScript's RegExp object to find the IP address in the input string
var ipAddressMatch = inputString.match(ipAddressRegex);
if (ipAddressMatch && ipAddressMatch.length > 0) {
var ipAddress = ipAddressMatch[0];
gs.info("IP Address: " + ipAddress);
} else {
gs.info("IP Address not found in the input string.");
}
Here is the result in Logs
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-25-2023 04:35 AM
HI Donald,
Thank for the quick help.
I am trying to build new Flow designer where I am patching IP address from Incident descption , If IP address is in pre defined list(we have Some List) than I need to trigger subfow to reach out IP owner.
I am using below script but getting null vale as result.
var regEx = new RegExp('(?<=IP address - ).*', 'j');
var incDesc = fd_data.subflow_inputs.inc.description;
var matchData = regEx.exec(incDesc);
//matchData = parseFloat(matchData);
return matchData.toString();
Please help me.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-26-2023 06:25 AM
Instead of using RegExp, please use "match" function as shown in the example.