
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-25-2022 02:54 AM
Hi,
We get emails in from a certain place. They all have the same subject and the actual error is in the body. It's not formatted in such a way that I can use name:value pairs to pick it out so I'm trying to parse the text to grab the string.
The problem is that the string can vary in length. Here is my code:
var ecaBody = email.body_text;
var shortDesc = ecaBody.substr(ecaBody.indexOf('Details')+10,31);
current.short_description = current.short_description + ' - ' + shortDesc;
That starts getting the text at the right place (i.e. just after "Details"). I want it stop before the comes the a '[' character rather than me specifying the length. To demonstrate, this is the result from an email that has the appropriately length error string:
But, this is the result from one with a shorted length:
I can rely on the next unrequired character being a left square bracket - '['.
Can I say, take substring from the body after "details" and before "["?
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-25-2022 03:08 AM
To stop at a specific character use split function. Refer the code below
var shortDesc = ecaBody.substr(ecaBody.indexOf('Details')+10).split("[")[0];
Thank you,
Palani
Palani

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-25-2022 03:08 AM
To stop at a specific character use split function. Refer the code below
var shortDesc = ecaBody.substr(ecaBody.indexOf('Details')+10).split("[")[0];
Thank you,
Palani
Palani

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-25-2022 03:17 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-25-2022 05:29 AM
This doesn't seem to work for me every time.
My alert email is:
#
# Celerra celerraSerial:APM00152427017, Control Station: pdusdc1mgtvnx101
#
************* Apr 24, 2022 12:00:21 PM *************
Alert W1:
Storage pool 'US_VNX5800_Storage_Pool' is using 98.0% of its maximum capacity.
For recommended action, use the 'nas_message -i' CLI command with associated Message ID 87518806228
I pick it out with the code you showed me:
if (email.body.alert_w1 != undefined){
email.body_text = email.body_text.replace(/\s+/g, '');
email.body_text = email.body_text.substr(email.body_text.indexOf('Alert W1:')+9).split(".")[0];
//current.short_description = email.body.alert_w1;
gs.info('XX W1' + email.body_text);
But the result is this:
acelerraSerial:APM00152427017,ControlStation:pdusdc1mgtvnx101#*************Apr24,202212:00:21PM*************AlertW1:Storagepool'US_VNX5800_Storage_Pool'isusing98
It stops in the right place but starts 9 characters in rather than where I tell it with indexOf. What am I doing wrong?