Get IP address from incident Descrption.

ack
Tera Contributor

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.

3 REPLIES 3

DYCM
Mega Sage

Hi @ack ,

Please see below:

The string is the incident description,.1.png

 

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

2.png

 

ack
Tera Contributor

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.

   

Instead of using RegExp, please use "match" function as shown in the example.