Regex script logic to parse
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-17-2024 10:58 AM
Hi Team,
I have below script which i am using to parse host name and group name from a column in staging table.
This is working fine in some cases where alert tags have defined position (0 for host names and 2 for support group).
There are many other alerts where the positions get swapped. So i need to convert below script to use regex logic to identify Hostname and Support group values.
Please advise.
var str = source.tags;
//'Hostname:NAP01-OND02,Vitality:V0,Support Team:Real Time Applications,Application Name:EDS';
var arr = str.split(',');
var ci = arr[0].split(':')[1];
var suppG = arr[2].split(':')[1];
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-17-2024 11:03 AM
I don't know if regex is necessary. It looks like you've shown an actual example string where your code is working. What are other possibilities - a simple re-arrangement, but one of the comma-separated elements will ALWAYS starts with 'Hostname:' and one will ALWAYS starts with 'Support Team:' and in both cases you want the value from the colon to the next comma?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-17-2024 11:11 AM
Hi Brad, yes please see the below alert tag. These are all comma separated and i need to extract values from Host name: and Support Team.
[Azure]Project Name:AS9 Upgrade,Criticality:Platinum,[Azure]Application:AS9,[Azure]CostCenter:1000,Application Name:AS9,[Azure]Support_Team:AM - Asset Suite Services,Vitality:V2,Hostname:caa-nmpoo19,[Azure]Project Number:LMC009,[Azure]Environment:PROD,Support Team:Asset Services
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-17-2024 11:17 AM
Something like this might be a better approach:
var str = source.tags;
var ci = '';
var suppG = '';
var arr = str.split(',');
for (i = 0; i < arr.length; i++) {
if (arr[i].indexOf('Hostname:') == 0) {
ci = arr[i].split(':')[1];
}
if (arr[i].indexOf('Support') == 0) {
suppG = arr[i].split(':')[1];
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-17-2024 11:08 AM
Hi @dvelloriy ,
You can use this regex to get the Hostname from this string: /(?<=Hostname:)[^,]+/
This regex will fetch "NAP01-OND02" from the string "Hostname:NAP01-OND02,Vitality:V0,Support Team:Real Time Applications,Application Name:EDS"
If this solution helps you then, mark it as accepted solution ✔️ and give thumbs up 👍!