Use API to add host to a (renamed) folder

Just a heads up. If you use the API to add a host to a folder, the name/path to the folder can be different than the current name of the folder!!

If a folder get renamed, it old name is still used as ID (see the url in you browser when setup → hosts → your folder). You have to use this old name, not the current name.

After replacing all to lowercase, replacing spaces to underscore this was kind of “unpleasant” …

And, as expected, non of this is documented anywhere …

Yes, there is a difference between the internal name of the folder and the title that is shown in the web GUI.

And that wouldn’t be a problem if they would document that somewhere…

like in the API docs maybe? But hey, don’t make CheckMK to user friendly…

The folder methods have the hint that the folder name is different from the folder title.

But admittedly the API method for moving a host to a different folder does only talk about the folder’s name without explicitly mentioning this difference.

Maybe @mschlenker can make a change here.

TBH any random numer or sting would be better as unique ID than an OLD name.

Ironically the name of the filesystem directory below $OMD_ROOT/etc/check_mk/conf.d/wato does not matter at all.
You can use mv to rename it.

In my opinion this is really bad behavior, as it is not always transparent to the user and everyone using the API gets confused. Sure, you can look it up in the URL or in the filesystem, but you must be aware of that. And, second point which makes it even worse, for automation tasks you cannot rely on the folder name you see in the UI, that caused a lot of headaches for us here… We built some automation where users can just add simple toml files to folders and the automation creates and configures the hosts but if you move / rename folders the pain starts and the automation folder name does not match the name in the UI anymore.

3 Likes