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