Améliorez vos notifications par mail
08/03/19 14:54 Classé dans: Techniques

Installation sur une ISO Centreon (CentOS)
Tout d'abord, installez git pour récupérer le dépôt git.
yum install git
Ensuite, récupérez le git
https://github.com/Shini31/centreon-notifications.git
Nous allons copier les fichiers nécessaires à ces nouvelles notifications dans un dossier que l'on nommera notification dans /usr/lib64/nagios/plugins
mkdir /usr/lib64/nagios/plugins/notifications
cp centreon-notifications/mail/* /usr/lib64/nagios/plugins/notifications
chown centreon: /usr/lib64/nagios/plugins/notifications/host-email.php
chown centreon: /usr/lib64/nagios/plugins/notifications/service-email.php
chmod 775 /usr/lib64/nagios/plugins/notifications/host-email.php
chmod 775 /usr/lib64/nagios/plugins/notifications/service-email.php
Maintenant, nous allons adapter nos commandes à notre configuration. Editons host-email.php
vi /usr/lib64/nagios/plugins/notifications/host-email.php
Première ligne, modifiez l'exécutable php
#!/opt/rh/rh-php71/root/usr/bin/php -c /etc/opt/rh/rh-php71/php.ini
Ligne 35, modifiez l'url du serveur Centreon
$url = "http://x.x.x.x";
Ligne 37, saisissez l'adresse mail de votre configuration
$from ="nom@domain.local";
Même chose pour la notification de service
vi /usr/lib64/nagios/plugins/notifications/service-email.php
Première ligne, modifiez l'exécutable php
#!/opt/rh/rh-php71/root/usr/bin/php -c /etc/opt/rh/rh-php71/php.ini
Ligne 74, modifiez l'url du serveur Centreon
$url = "http://x.x.x.x";
Ligne 76, saisissez l'adresse mail de votre configuration
$from ="nom@domain.local";
Pour ma part, j'ai modifié la ligne suivante (85) pour avoir le nom d'hôte suivi de l'alias
$body .= "<tr bgcolor=#fefefe><td><b>Host:</b></td><td><font color=#0000CC><b><a href='$url/centreon/main.php?p=20202&o=hd&host_name=$f_host_name'>$f_host_name($f_host_alias)</b></td></tr>\r\n";

Configuration dans Centreon
Pour finaliser notre configuration, nous devrons ajouter deux commandes de notifications dans l'interface de Centreon. Sélectionnez Configuration > Commandes > Notifications et ajoutez deux commande de notifications.
Détail de la commande host-notify-by-email-php
$USER1$/notifications/host-email.php "$NOTIFICATIONTYPE$" "$HOSTNAME$" "$HOSTALIAS$" "$HOSTSTATE$" "$HOSTADDRESS$" "$HOSTOUTPUT$" "$LONGDATETIME$" "$SERVICEDESC$" "$SERVICESTATE$" "$CONTACTEMAIL$" "$TOTALHOSTSUP$" "$TOTALHOSTSDOWN$" "$HOSTACKAUTHOR$" "$HOSTACKCOMMENT$"
Détail de la commande service-notify-by-email-php
$USER1$/notifications/service-email.php "$NOTIFICATIONTYPE$" "$HOSTNAME$" "$HOSTALIAS$" "$HOSTSTATE$" "$HOSTADDRESS$" "$SERVICEOUTPUT$" "$LONGDATETIME$" "$SERVICEDESC$" "$SERVICESTATE$" "$CONTACTEMAIL$" "$SERVICEDURATIONSEC$" "$SERVICEEXECUTIONTIME$" "$TOTALSERVICESWARNING$" "$TOTALSERVICESCRITICAL$" "$TOTALSERVICESUNKNOWN$" "$LASTSERVICEOK$" "$LASTSERVICEWARNING$" "$SERVICENOTIFICATIONNUMBER$" "$SERVICEACKAUTHOR$" "$SERVICEACKCOMMENT$"
Il est évident qu'il faut aussi modifier les notifications des utilisateurs concernés et d'appliquer la configuration. Attention pour les pollers distants, il faut aussi ajouter les scripts de notifications comme sur le central.
Installation sur Debian/Rapsbian
La procédure est pratiquement identique, il faudra juste modifier le chemin du php à la première ligne
#!/usr/bin/php -c /etc/php/7.1/cli/php.ini
blog comments powered by Disqus