29 Oct 2020 03:40 PM
Hey all,
I have some tagging needs and based on some deployment/provisioning processes I want to implement tagging based on a simple Host Group pattern. I have 3 tags I want to define:
Environment can have 4 designations:
Application can have any number of designations:
Role can have 3 designations:
When installing the OneAgent, my provisioning team will be instructed to supply a Host Group name. For example:
In this example, I define 3 tags based on this pattern:
I am currently trying to build out the first part, but I found out you cannot use specific regex methods (probably for performance reasons) inside Dynatrace. Typically I would use:
^(.*?)_
To identify "np" as the environment however apparently you cannot use capturing and instead you have to use atomic groups. Can anyone make a suggestion on how to move forward?
Solved! Go to Solution.
29 Oct 2020 04:03 PM
I've done it like this.
Pattern: Part1_Part2_Part3_Part4
Part1 ([^_]+?)_[^_]+_[^_]+_[^_]+
Part2: [^_]+_([^_]+?)_[^_]+_[^_]+
Part3: [^_]+_[^_]+_([^_]+?)_[^_]+
Part4: [^_]+_[^_]+_[^_]+_([^_]+?)
29 Oct 2020 04:56 PM
Interesting, I tried the following to identify what I classify as "environment" (Part1):
([^_]+?)_[^_]+_[^_]+_[^_]+
I got an error that says: "Greedy or lazy character classes are not allowed, please use a possessive quantifier instead."
01 Nov 2020 11:10 PM
Here's mine:
{HostGroup:Name/([^_]+?)_[^_]+_[^_]+_[^_]+}
I get no error when I save it.
My host groups don't fit the pattern so I cannot easily test it, but I copied from a customer I used it on, basically...so I think it should work and it works fine on regex101.com when I test it as:
([^_]+?)_[^_]+_[^_]+_[^_]+
You have three groups, so maybe try these:
([^_]+?)_[^_]+_[^_]+
([^_]+?)_[^_]+?_[^_]+?
The question marks make it non-greedy, so the last one should work and be more efficient, I think.
02 Nov 2020 02:16 PM
I think this must be a user issue (my side obviously). So in the "Optional Tag Value" section I am putting in the following:
{HostGroup:Name/([^_]+?)_[^_]+}
And then in the Conditions section I have:
Conditions:
Host Group Name contains regex ([^_]+?)_[^_]+
I then get
"Greedy or lazy character classes are not allowed, please use a possessive quantifier instead."
For reference, my current host groups are defined by 2 pieces of meta-data separated by an underscore. Examples are currently:
02 Nov 2020 02:47 PM
Try this for the tag:
{HostGroup:Name/([^_]+?)_[^_]+?}
Try this for the condition:
[^_]+?_[^_]+?$
02 Nov 2020 06:29 PM
This seemed to work for me after a few guess and check:
Tag:
{HostGroup:Name/^(.*?)_}
Condition:
^.*?_
30 Oct 2020 07:48 AM
Hi @Jonathan F.
I would give the dynatrace regex tester a try
Yos
02 Nov 2020 12:00 AM
Looks like the domain is down? I check it with the Cache of Google and it seems like it has a lot of other things besides the Regex.
02 Nov 2020 03:14 PM
Yes its some times losing its DNS or something and yes its got lots of nice features here.
May be you can use the its IP 35.201.104.155 instead of URL?
Try to play around with the help of the cheat sheet .....
May be ([a-z]{1,4}\d|[a-z]{1,4}) can do the job?
HTH
Yos
02 Nov 2020 07:06 PM
My biggest issue is that I am having a difficult time understanding the "optional tag value" and the function that the "conditions" section carries out.
I am using "Host Group Name" and "contains regex" and then trying to select the part in the "optional tag value" section that I want to target under conditions. I think I am misinterpreting something. There seems to be things you CAN do in the "Optional Tag Value" section that you CANNOT do in the "Conditions" section.
02 Nov 2020 07:51 PM
The optional tag value puts the value in the key/value pair of the tag. You can leave it out, but I always recommend key/value pairs over "flat" tags that consist of just a name. In this case, the regex tells it via the parentheses on the "group" to grab the first part of the Host Group before the first delimiter ("_").
The conditions part optionally filters the input. In this case saying to only include Host Groups that have a delimiter of "_". you cannot use the parentheses here as you cannot extract data in the condition.
HTH!
09 Nov 2020 02:51 PM
Hey Yos,
I appreciate your help with this man. I replied to Dave M. below with my solution. Check it out and let me know if you have any further feedback.
09 Nov 2020 03:09 PM
Looks good!!!
09 Nov 2020 02:50 PM
Hey Dave M,
I wanted to thank you for your help on this. Here is what I had to do to get this to work for me (your guidance was crucial). The format of my host tags is as follows:
env_app_role
So below highlights the regex strings for each one:
Environment:
{HostGroup:Name/^(.*?)_}
Application:
HostGroup:Name/^.*?_(.*?)_}
Role:
{HostGroup:Name/.*?_.*?_(.*?$)}
For the condition, I just used "HostGroup" and "exists". I decided not to use a selection method in the condition section and just rely on the tag part.
18 Jun 2022 12:09 AM
Thank you for posting what worked for you. It helped me out today.