Prefix for Docker-Container Hosts, Hostname translation for piggyback

Hello there,

I ran into a big problem while testing out checkmk on my servers.
I want to monitor a lot of Docker-Containers as single Hosts and because I have a lot of different Hosts running the same Docker-Containers I had problems with the rule “Hostname translation for piggybacked Hosts”.
With this rule you can change the name of the piggyback/subdirectory that is created for every single container into something different, and then you can rename the Host as well, so that you have a better structure in your Webinterface.
But like I said if you have a container with the same name as the one you already have, but on a different server, you will get the problem that checkmk can not distinguish these two from another.
And I really don’t want to use a workaround here, for example renaming every directory that contains compose files specific to the used server.

So my question is: Is there a way or a rule I can use to create specific name prefixes for every child host (docker container) my parent Host has? So that I can then distinguish them all from another and monitor each one ?
Here is an example of my current situation:
I have 3 parent hosts: vm-01, vm-02, vm-03.
Every parent host has 2 docker-containers running, they are all called “tools_portainer” and “my_nginx” on all 3 hosts.
I tried creating the hostname translation rule, so that “tools_portainer” is changed to “vm-01_portainer” and “my_nginx” to “vm-01_nginx”.
The problem is that I can now only monitor the two containers from my vm-01, because checkmk can not find my “tools_portainer” and “my_nginx” from vm-02 or vm-02 anymore.

Like I said I am looking for a certain rule or anything similar, that automatically renames the child hosts “tools_portainer” and “my_nginx” to something regarding their parent host.
I would like to have “vm-01_portainer”, “vm-02_portainer” etc.

And I can not change the containers name directly on the server, because that would be an ugly workaround and I use the same .yml file on all servers and it would only make things even more complicated.

Thanks for reading, I am looking forward to help :wink:

This should really be a feature of the dynamic configuration daemon or even the mk_docker.py agent plugin, but currently is not.

You can create multiple rules in “Hostname translation for piggybacked Hosts” for each Docker node (assign every single rule to a differen Docker node host). With this and the regex replacement you can create individual prefixes for the container hosts.

Hey sorry for the late reply, thank you for your suggestion, but I found a nice workaround.
I added “hostname_name” as a third option in the mk_docker.py file where it would otherwise only be “name” or “long”. To get the hostname I simply used os.gethostname().

Just thought you’d like to know, take care :wink:

1 Like

That would make a nice pull request for the github repo.

I have the same problem.

I don’t know python, could you please share your change.

Has it already been implemented? I have 2.0.0p6 cee?

This can be achieved with a rule in “Hostname translation for piggybacked hosts” for every docker node. There you can add a custom prefix to the container name.

I am using “dynamic host management”
I don’t know why, but the following rule for changing the hostname did not work for me, although it is active.

I anonymized the hostnames

An explicit hostname mapping will not work here. If you want to add a prefix to each piggybacked host you need to use the regular expression option like this:

(.+) → prefix-\1

Thanks for the quick response, but it doesn’t work

my dcd config

The names of detected machines remain unchanged

This rule cannot work as the renaming happens before the label is applied.
I have done this prefix renaming for some kubernetes instances and it is working there as expected.
In my system i restrict the renaming rules to the source host of the data and that’s all.

The rule is applied to the piggyback source host, the docker node, and not the containers. Your condition does not work here.

I don’t understand something, so let me ask you again.

I have host01, host02 runs the same docker applications: app01

In checkmk I would like to see two hosts “app01 from host01” and “app01 from host02”

how to do it?

Go to “Hostname translation for piggybacked hosts” and create two rules.

First rule value: (.+) → host01-\1
First rule condition: explicit hostname: host01

Second rule value: (.+) → host02-\1
Second rule condition: explicit hostname: host02

1 Like

Thanks it’s working now.

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed. Contact an admin if you think this should be re-opened.