2 # Moves configuration files from /etc/icinga2/conf.d/hosts
3 # to /etc/icinga2/repository.d
5 icinga2bin=@CMAKE_INSTALL_FULL_SBINDIR@/icinga2
6 sysconfdir=`$icinga2bin variable get --current SysconfDir`
8 if [ -z "$sysconfdir" ]; then
9 echo "Could not determine SysconfDir"
13 if [ ! -d $sysconfdir/icinga2/conf.d/hosts ]; then
17 mkdir -p $sysconfdir/icinga2/repository.d/hosts
22 for hostFile in $sysconfdir/icinga2/conf.d/hosts/*.conf; do
23 if [ ! -e $hostFile ]; then
27 host_count=$(($host_count + 1))
29 host=`basename $hostFile .conf`
31 if [ "x$host" = "xlocalhost" ]; then
32 target="`hostname -f`"
37 if [ ! -e $sysconfdir/icinga2/repository.d/hosts/$target.conf ]; then
38 mv $sysconfdir/icinga2/conf.d/hosts/$host.conf $sysconfdir/icinga2/repository.d/hosts/$target.conf
39 sed "s/localhost/$target/g" $sysconfdir/icinga2/repository.d/hosts/$target.conf > $sysconfdir/icinga2/repository.d/hosts/$target.conf.tmp
40 mv $sysconfdir/icinga2/repository.d/hosts/$target.conf.tmp $sysconfdir/icinga2/repository.d/hosts/$target.conf
42 rm -f $sysconfdir/icinga2/conf.d/hosts/$host.conf
45 if [ -d $sysconfdir/icinga2/conf.d/hosts/$host ]; then
46 service_count=$(($service_count + 1))
48 if [ ! -e $sysconfdir/icinga2/repository.d/hosts/$target ]; then
49 mv $sysconfdir/icinga2/conf.d/hosts/$host $sysconfdir/icinga2/repository.d/hosts/$target
50 for file in $sysconfdir/icinga2/repository.d/hosts/$target/*.conf; do
51 if [ ! -e $file ]; then
55 sed "s/localhost/$target/g" $file > $file.tmp
59 rm -rf $sysconfdir/icinga2/conf.d/hosts/$host
64 cat >$sysconfdir/icinga2/conf.d/hosts/README <<TEXT
65 What happened to my configuration files?
66 ========================================
68 Your host and service configuration files were moved to the $sysconfdir/icinga2/repository.d directory.
70 This allows you to manipulate those files using the "icinga2 repository" CLI commands.
72 Here are a few commands you might want to try:
74 # icinga2 repository host list
76 # icinga2 repository service list
78 # icinga2 repository --help
81 echo "Migrated $host_count host(s) and $service_count service(s)."