cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Assistance with Tagging and Regex

Jonathan_Finkbi
Participant

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
  • Application
  • Role

Environment can have 4 designations:

  • prod
  • np
  • qa
  • dev

Application can have any number of designations:

  • App1
  • App2
  • App3
  • etc

Role can have 3 designations:

  • web
  • app
  • db

When installing the OneAgent, my provisioning team will be instructed to supply a Host Group name. For example:

  • np_app1_web

In this example, I define 3 tags based on this pattern:

  • Environment: np
  • Application: app1
  • Role: web

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?

14 REPLIES 14

dave_mauney
Dynatrace Champion
Dynatrace Champion

I've done it like this.

Pattern: Part1_Part2_Part3_Part4

Part1 ([^_]+?)_[^_]+_[^_]+_[^_]+

Part2: [^_]+_([^_]+?)_[^_]+_[^_]+

Part3: [^_]+_[^_]+_([^_]+?)_[^_]+

Part4: [^_]+_[^_]+_[^_]+_([^_]+?)

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."

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.

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:

  • prod_app1
  • dev_app2
  • qa_app3





Try this for the tag:

{HostGroup:Name/([^_]+?)_[^_]+?}

Try this for the condition:

[^_]+?_[^_]+?$

This seemed to work for me after a few guess and check:


Tag:

{HostGroup:Name/^(.*?)_}


Condition:

^.*?_

Hi @Jonathan F.

I would give the dynatrace regex tester a try

Yos

Anonymous
Not applicable

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.



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

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.

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!

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.

Looks good!!!



Jonathan_Finkbi
Participant

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.