Skip to main content
Needs Votes

Autodiscovery Host - delete host in Centreon

Related products:Infra Monitoring - Discovery
  • October 17, 2024
  • 7 replies
  • 151 views

Forum|alt.badge.img+8

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

7 replies

lpinsivy
Centreonian
Forum|alt.badge.img+21
  • Centreonian
  • October 18, 2024

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,


lpinsivy
Centreonian
Forum|alt.badge.img+21
  • Centreonian
  • October 18, 2024
NewDiscussion ongoing

Forum|alt.badge.img+8
  • Author
  • Steward ***
  • October 18, 2024

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?


lpinsivy
Centreonian
Forum|alt.badge.img+21
  • Centreonian
  • October 18, 2024

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


Forum|alt.badge.img+8
  • Author
  • Steward ***
  • October 18, 2024

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.


Forum|alt.badge.img+8
  • Author
  • Steward ***
  • November 7, 2024

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 [ -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 [ "${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}

 


rchauvel
Centreonian
Forum|alt.badge.img+18
  • Centreonian
  • November 29, 2024
Discussion ongoingNeeds Votes