Bulk rename of hosts

Hello,

I would like to rename a large number of hosts. First the current host name is to be added as an alias and in the second step the IP address is to be stored as the new host name.
All hosts that are to be renamed are located in the same folder. Theoretically, I could delete all hosts and create new ones. However, this would take some time (+1000 hosts) and I would also lose the historical data. Is there an easy way to do this?
Thank you in advance.

Hi Thomas and welcome to the forum!

well, there is an option to bulk-rename hosts. You can find it in Setup → Hosts and then in the Hosts menu as Rename multiple hosts:

image

But unfortuanetly there is no option to change or set the alias and only an option to change the name from IP → DNS name but not the other way round:

image

I’m afraid you have to write a script and rename your hosts with the REST API.


Oh, and if deleting and re-creating the hosts is really an option, then I’d do it via CSV import. Just prepare a CSV file with name, alias, IP (and maybe some other values) and import that into checkmk. That is far quicker than creating them one by one.

Just a note, if you delete and recreate the hosts, you will lose all rules created for these hosts.

1 Like

Hi Dirk,

thank you for your answer.
Is there perhaps a way to save the historical data of the hosts and link them when recreating them?
Thank you.

This is not a problem. I have not generated the rules for the hosts, but defined them for the entire folder.

Disclaimer: I haven’t tried this. Make a backup before fiddling with these files.

The rrd data (i.e. the historical data for the graphs) is stored in the directories ~/var/check_mk/rrd/HOSTNAME.

Inside such a host specific directory there are two files per service: the *.rrd file with the actual data and a corresponding *.info file with some meta information about the rrd data (hostname, service name, and a list of metric names). The *.info file is just ascii and you can simpy cat it.

I would guess, the following might work:

omd stop;

mv ~/var/check_mk/rrd/OLD_HOSTNAME ~/var/check_mk/rrd/NEW_HOSTNAME
cd ~/var/check_mk/rrd/NEW_HOSTNAME
sed -i -r "/^HOST/ s/${OLD_HOSTNAME}/${NEW_HOSTNAME}/;" *.info

omd start;

Of course, the middle block with the three lines has to be repeated for every hostname.

But as said: make a backup before trying this!

1 Like

For rrd there is also a dump and restore option. Just in case rename of files didn’t work.

More Information here
https://oss.oetiker.ch/rrdtool/doc/rrddump.en.html
https://oss.oetiker.ch/rrdtool/doc/rrdrestore.en.html

1 Like

Hi Dirk and dabrein,
since the servers were split at the same time, I was able to extract the rrd files, rename them as desired, transfer them to the new server and create the hosts on the new server as “new”. This meant that the existing rrd files were still used and there was no loss of historical data.
Thanks for the hint with the rrd files!

2 Likes