How to automatically set tag value based on regex

Our server names follow a naming convention : 4 letters company + 4 letters for the location (I simplified). What I am trying to do is to have a tag being automatically created for each server containing its location. There are around 50-70 possible locations, and there can be new ones created without notification. So I need a way which does not require having to change the Dynatrace config each time there’s a server with a new location in its name.

 

For example if the server name is BOBUCEB4, the location is CEB4, so I would like a tag called INT_LOCATION with the value CEB4.

 

We installed oneAgent on the servers, so they are considered as Hosts in Dynatrace.

 

What I thought would be the logical to do is to create an entry in Settings/Tags/Automatically applied tags:

 

Rule type=Monitored Entity

Rule applies to=Hosts

Condition : hostname contains regex ‘^.{4}.{4}’

Optional tag value: In this field, Dynatrace expects either a string or one pre-made variable. But there’s nothing about extracting part of the hostname or referencing the regex groups.

What I would have expected is to have a regex like this : ^.{4}(.{4})   (ie with a capturing group for the location), and being able to reference it in the Optional tag value field. But that doesn’t seem to be possible.

 

So how do I achieve being able to create automatic tags and set the value based on part of the host name? Using either a regex or something else.

 

Read more here: Source link