- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā08-05-2024 03:46 AM
Hi,
I am trying to create a flow for handling alerts from our network monitoring platform.
We will receive 2 emails one when the device goes down and one when it comes back up.
Inside the body of the text is the device (Screenshot attached) I want to extract so that I populate the CI field.
We have a similar email handler to get the variable for us just wondering how I would modify it to get the device
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā08-05-2024 05:15 AM
Hi @RobDoyle
Can you try with the below regex:
/Device:(\s([A-Za-z]+\s)+)/
I tried this in the background script and it is giving me expected output :
Thanks and Regards
Amit Verma
Please mark this response as correct and helpful if it assisted you with your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā08-05-2024 05:03 AM
Try:
var regex = /Device:\s(.*?)\s\(/;
Only thing is that you are checking between 'Device:' and '(', so I hope you always have the IP there. If not, you will need some logic to check on the IP being there or not and if so, remove it.
Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā08-05-2024 05:15 AM
Hi @RobDoyle
Can you try with the below regex:
/Device:(\s([A-Za-z]+\s)+)/
I tried this in the background script and it is giving me expected output :
Thanks and Regards
Amit Verma
Please mark this response as correct and helpful if it assisted you with your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā08-06-2024 08:21 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā08-06-2024 09:26 AM
This is how i ended running it to get it to work
/*
** Access Flow/Action data using the fd_data object. Script must return a value.
*/
// Assuming body_text contains the whole text block provided
var bodyText = fd_data.trigger.body_text;
// Use a regular expression to match "Device" followed by any amount of whitespace, a colon, the device name, and optionally an IP address in parentheses
var regex = /Device:\s*([A-Za-z0-9\s]+)(\s\([0-9.]+\))?/;
var match = bodyText.match(regex);
// Check if the match was successful before trying to access the result
if (match) {
var deviceName = match[1].trim(); // match[1] contains the device name, we use .trim() to remove any leading/trailing spaces
gs.info(deviceName); // Log the device name
return deviceName; // Return the device name
} else {
gs.info('No match found'); // Log the failure to match
return 'No match found'; // Return a default value
}