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:12 AM
Hello, can you please share the code?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-17-2024 11:19 AM
Sure, Here it is:
// Regex to match the hostname
var string = "Hostname:NAP01-OND02,Vitality:V0,Support Team:Real Time Applications,Application Name:EDS";
var regex = /Hostname:([^,]+)/;
var match = string.match(regex);
var hostname = match ? match[1] : null;
gs.log('Extracted Hostname: ' + hostname);