Skip to main content

Hello,

In the discovery of hosts, is it possible to automatically delete a host from centreon when it no longer exists following the discovery update.
This is a missing feature: Hosts are automatically added but if a host is deleted on the provider, it is not deleted from Centreon.
THANKS

Hi @LEBRETON,

Today it is possible to disable hosts.

What if discovery doesn't find the host while it is temporarily unavailable? Delete it and lose all history?

Regards,


NewDiscussion ongoing

Hi,


In the case of providers like VmWare or Tower, if Discovery no longer finds a host, it is because it has really been deleted.
For the other providers I don't know how to answer you, having the possibility of choosing deletion would be a plus.
I am currently testing with Tower and when a host has been deleted, it remains active in Centreon, it is not deactivated.
How do we deactivate it?


You have “Disable hosts already added to configuration if the mapping rule excludes them” option in Policy option


Yes, this option is activated.
During the first discovery, host Y was added to Centreon.
The user deleted this host Y and during the second discovery 24 hours later, the host Y no longer exists in the list of hosts but is not deactivated on Centreon.


hi,

I created a shell script which removes from supervision the hosts deleted between two discoveries.

And put this script in a crontab.

#!/bin/bash
#
# Suppression de la supervision des Hosts dicovery supprimés entre deux inventaires
#
# select host_name, host_id, nagios_server_id from host inner join ns_host_relation on host.host_id=ns_host_relation.host_host_id where host_id in (select host_id from mod_host_disco_host_already_discovered where uuid not in (select uuid from mod_host_disco_host));

CENTREON_DIR=/etc/centreon
CENTREON_CONF_FILE=centreon.conf.php
DB_LOGIN=$(cat ${CENTREON_DIR}/${CENTREON_CONF_FILE}|awk -e '/user/ {gsub(/;/, "",$3);gsub(/"/,"",$3);print $3}')
DB_PASSWORD=$(cat ${CENTREON_DIR}/${CENTREON_CONF_FILE}|awk -e '/password/ {gsub(/;/, "",$3);print $3}'|sed -e "s/'//g")
DB_HOST=$(cat ${CENTREON_DIR}/${CENTREON_CONF_FILE}|awk -e '/hostCentreon/ {gsub(/;/, "",$3);gsub(/"/,"",$3);print $3}')
CLAPI_USER=$1
CLAPI_PWD=$2
RESULT_FILE="/tmp/host_discovery_delete-$$.txt"

QUERY="select host_name, host_id, nagios_server_id from host inner join ns_host_relation on host.host_id=ns_host_relation.host_host_id where host_id in (select host_id from mod_host_disco_host_already_discovered where uuid not in (select uuid from mod_host_disco_host));"

echo -e " `date` Liste de Hosts supprimés depuis le dernier inventaire : \n"
mysql -h ${DB_HOST} -u ${DB_LOGIN} -p${DB_PASSWORD} centreon -e "${QUERY}" --batch --skip-column-names > ${RESULT_FILE}
if f -s ${RESULT_FILE} ]; then
   echo "host_name      host_id         nagios_server_id"
   cat ${RESULT_FILE}
   echo -e "\nSuppresion des Hosts de Centreon: \n"
   while IFS=$'\t' read -r host_name host_id nagios_server_id; do
        echo "Suppression du host : ${host_name} de Centreon"
        /usr/bin/centreon -u ${CLAPI_USER} -p ${CLAPI_PWD} -o HOST -a del -v ${host_name}
   done < ${RESULT_FILE}
   # On regénère la conf des pollers concernés et on applique
   echo -e "\nRegénération des pollers suite à la suppression: \n"
   POLLER_ID=""
   while IFS=$'\t' read -r host_name host_id nagios_server_id; do
        echo "ID poller du host ${host_name} : ${nagios_server_id} de Centreon"
        if s "${POLLER_ID}" != "${nagios_server_id}" ]; then
           echo "traitement poller: ${nagios_server_id}"
           /usr/bin/centreon -u ${CLAPI_USER} -p ${CLAPI_PWD} -a APPLYCFG -v ${nagios_server_id}
           POLLER_ID=${nagios_server_id}
         else
          echo "Poller ${nagios_server_id} déjà traité"
        fi
   done < ${RESULT_FILE}
 else
   echo -e "Cool, Rien à faire, pas de hosts supprimés\n"
fi   
rm -f ${RESULT_FILE}

 


Discussion ongoingNeeds Votes