Import Configuration Centreon CLAPI

Centreon CLAPI est un module/API Centreon qui permet d’administrer et de configurer votre plate-forme de supervision en ligne de commande. Les actions que l’on peut effectuer depuis l’interface web peuvent être réalisé en ligne de commande rapidement…

En effet, nous allons pouvoir ajouter, supprimer, mettre à jours les hôtes, les services, les commandes…etc, mais surtout, exporter/importer la configuration complète de Centreon Web.

Remarque : depuis la version 2.7, le module Centreon-Clapi est totalement intégré à Centreon.

Ce qu’il vous faut :

SSH/SFTP Tools :

Remarque : MobaXterm permet d’établir une connexion SSH et SFTP simultanément. Très pratique pour récupérer ou uploader les fichiers directement depuis la machine hôte vers le serveur Centreon. Il est totalement personnalisable et permet également de récupérer vos sessions PuTTy automatiquement. Bref, the best et c’est un produit français !

SSH and SFTP using MobaXterm

Commandes CLAPI

Voici la commande Clapi :

[root@centreon ~]# centreon -u USER -p PASSWORD -o OBJET -a ACTION [-v PARAMETRE]

Explication de la commande :

  • -u : l’utilisateur de l’interface Centreon.
  • -p : le mot de passe associé à l’utilisateur Centreon
  • -o : type d’objet associé à l’action. Exemple : Collecteur, hôte, service…etc.
  • -a : type d’action à réaliser : ajouter, supprimer, modifier…etc.
  • -v : pour rajouter plusieurs paramètres en fonction de l’objet ou type d’action.

Préparation pour l’import

Avant d’importer la configuration, j’ai dû remettre Centreon à zéro, j’ai supprimé les hôtes, services, commandes, les macros personnalisées…etc. Admettons même que vous avez réinstallé Centreon. A la base, on trouve déjà les Trap SNMP (pas avec la dernière version), la configuration de Centreon Broker, Centreon Engine, le collecteur Central, les utilisateurs par défaut…etc.

Donc, lors de l’export, ces paramètres sont également exportés. Lorsque vous allez importer la configuration, il vous dira que ces objets existent déjà. C’est normal !

Remarque : encore une dernière chose, si vous avez réalisé l’export avec les icônes pour les hôtes/services, pensez d’abord à installer et synchroniser le même répertoire qu’avant avec les MEMES icônes. Voir le chapitre /#Pack_icones_Centreon sinon, vous allez vous retrouver avec des messages de type Not found !

Pas d’hôtes, pas de services, pas de commandes, pas de macros

Centreon Server Fraish Install

Check host CentreonCheck Services Centreon
Check Command CentreonCheck Centreon Ressources

Importer la configuration

Lancez l’import à l’aide de la commande suivante. J’importe le fichier exporté dans cet article : full-export-conf-centreon-centreon-clapi/

[root@centreon ~]# centreon -u admin -p admin -i /tmp/centreon-conf.txt
Line 2 : Object already exists (Simple User)
Line 16 : Object already exists (Central)
Line 32 : Object already exists (24x7)
Line 40 : Object already exists (none)
Line 41 : Object already exists (nonworkhours)
[...]

Certains objets existe déjà, c’est normal donc…

Import Centreon Configuration

Une fois terminé, exporter la configuration et redémarrer le collecteur Central. Vous pouvez le faire en ligne de commande avec Centreon CLAPI :

[root@centreon ~]# centreon -u admin -p admin -a APPLYCFG -v "Central"
2018-06-10 06:30:03 - APPLYCFG
Configuration files generated for poller 'Central'

OK: Centreon Poller Central can restart without problem...

OK: All configuration files copied with success.

centengine reload: done                                    [  OK  ]
Return code end : 0
[root@centreon ~]#

Et voilà, j’ai rajouté entre temps le serveur Centreon à la supervision.

J’ai retrouvé les petits sans problème. Les commandes également, les macros…etc. Il reste maintenant à peaufiner les détails et vérifier que tout fonctionne.

C’est terminé. Voici quelques commandes CLAPI à connaître.

Gestion des collecteurs

Quelques commandes pour gérer vos collecteurs (Pollers). Dans mon cas, j’ai un seul collecteur (Poller) : Central

Afficher les colleurs disponibles :

[root@centreon ~]# centreon -u admin -p admin -a POLLERLIST
poller_id;name
---
1;Central
---
Return code end : 0
[root@centreon ~]#

Générer la configuration pour le collecteur Central :

[root@centreon ~]# centreon -u admin -p admin -a POLLERGENERATE -v "Central"
---
Configuration files generated for poller 'Central'
---
Return code end : 0
[root@centreon ~]#

Tester la configuration du collecteur Central :

[root@centreon ~]# centreon -u admin -p admin -a POLLERTEST -v "Central"
---
OK: Centreon Poller Central can restart without problem...
---
Return code end : 0
[root@centreon ~]#

Déplacer les fichiers pour appliquer la supervision : après avoir ajouté un hôte, service…etc

[root@centreon ~]# centreon -u admin -p admin -a CFGMOVE -v "Central"
---
OK: All configuration files copied with success.
---
Return code end : 0
[root@centreon ~]#

Relancer le collecteur Central :

[root@centreon ~]# centreon -u admin -p admin -a POLLERRESTART -v "Central"
---
.centengine restart: done                                  [  OK  ]
---
Return code end : 0
[root@centreon ~]#

Les 4 commandes ci-dessus, peuvent être réalisées en une seule commande (fallait commencer par cette commande voyons…allons !)

[root@centreon ~]# centreon -u admin -p admin -a APPLYCFG -v "Central"

Centreon Clapi APPLYCFG

Gestion des objets

Pour la gestion des objets, je vais citer juste quelques exemples, il faut des semaines pour faire le tour, mais tout est ici : Object management

Afficher les hôtes : J’ai qu’un hôte et c’est Exchange Server 2016

[root@centreon ~]# centreon -u admin -p admin -o HOST -a show
id;name;alias;address;activate
---
2;EX-SERVER1;Exchange Server 2016;172.16.1.2;1
---
[root@centreon ~]#

Afficher les services :

[root@centreon ~]# centreon -u admin -p admin -o SERVICE -a show
host id;host name;id;description;check command;check command arg;normal check interval;retry check interval;max check attempts;active checks enabled;passive checks enabled;activate
---
2;EX-SERVER1;13;Check-ComponentState;Check-ComponentState;;;;;2;2;1
2;EX-SERVER1;2;Check-CPU;Check-CPU;;;;;2;2;1
2;EX-SERVER1;15;Check-DAGHealth;Check-DAGHealth;;;;;2;2;1
2;EX-SERVER1;3;Check-Disk-C:;Check-Disk-C:;;;;;2;2;1
2;EX-SERVER1;4;Check-Disk-E:;Check-Disk-E:;;;;;2;2;1
2;EX-SERVER1;5;Check-Disk-F:;Check-Disk-F:;;;;;2;2;1
2;EX-SERVER1;6;Check-Disk-L:;Check-Disk-L:;;;;;2;2;1
2;EX-SERVER1;14;Check-ExchServices;Check-ExchServices;;;;;2;2;1
2;EX-SERVER1;16;Check-FailOverDB;Check-FailOverDB;;;;;2;2;1
2;EX-SERVER1;18;Check-IndexStateHealth;Check-IndexStateHealth;;;;;2;2;1
2;EX-SERVER1;11;Check-MailboxHealth;Check-MailboxHealth;;;;;2;2;1
2;EX-SERVER1;7;Check-Memory;Check-Memory;;;;;2;2;1
2;EX-SERVER1;10;Check-MSEProcess;Check-MSExchange;;;;;2;2;1
2;EX-SERVER1;17;Check-QueueHealth;Check-QueueHealth;;;;;2;2;1
2;EX-SERVER1;12;Check-ReplicationHealth;Check-ReplicationHealth;;;;;2;2;1
2;EX-SERVER1;9;Check-Service-IMAP4;Check-WINServices;;;;;2;2;1
2;EX-SERVER1;8;Check-Traffic;Check-traffic;;;;;2;2;1
---
[root@centreon ~]#

Afficher les commandes : bon…je trouve que… c’est très clair et… on s’y retrouve rapidos ! pas vous ?

[root@centreon ~]# centreon -u admin -p admin -o CMD -a show
id;name;type;line
35;host-notify-by-email;notif;/usr/bin/printf "%b" "***** centreon Notification *****<br/><br/>Type:$NOTIFICATIONTYPE$<br/>Host: $HOSTNAME$<br/>State: $HOSTSTATE$<br/>Address: $HOSTADDRESS$<br/>Info: $HOSTOUTPUT$<br/>Date/Time: $DATE$" | @MAILER@ -s "Host $HOSTSTATE$ alert for $HOSTNAME$!" $CONTACTEMAIL$
36;service-notify-by-email;notif;/usr/bin/printf "%b" "***** centreon Notification *****<br/><br/>Notification Type: $NOTIFICATIONTYPE$<br/><br/>Service: $SERVICEDESC$<br/>Host: $HOSTALIAS$<br/>Address: $HOSTADDRESS$<br/>State: $SERVICESTATE$<br/><br/>Date/Time: $DATE$ Additional Info : $SERVICEOUTPUT$" | @MAILER@ -s "** $NOTIFICATIONTYPE$ alert - $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" $CONTACTEMAIL$
37;host-notify-by-epager;notif;/usr/bin/printf "%b" "Host $HOSTALIAS$ is $HOSTSTATE$<br/>Info: $OUTPUT$<br/>Time: $DATETIME$\" | @MAILER@ -s \"$NOTIFICATIONTYPE$ alert - Host $HOSTNAME$ is $HOSTSTATE$\" $CONTACTPAGER$
38;service-notify-by-epager;notif;/usr/bin/printf "%b" "Service: $SERVICEDESC$<br/>Host: $HOSTNAME$<br/>Address: $HOSTADDRESS$<br/>State: $SERVICESTATE$<br/>Info: $OUTPUT$<br/>Date: $DATETIME$" | @MAILER@ -s "$NOTIFICATIONTYPE$: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$" $CONTACTPAGER$
89;host-notify-by-jabber;notif;$USER1$/notify_via_jabber  $CONTACTPAGER$ "Host &#039;$HOSTALIAS$&#039; is $HOSTSTATE$ - Info: $HOSTOUTPUT$"
90;service-notify-by-jabber;notif;$USER1$/notify_via_jabber $CONTACTPAGER$ "$NOTIFICATIONTYPE$ $HOSTNAME$ $SERVICEDESC$ $SERVICESTATE$ $SERVICEOUTPUT$ $LONGDATETIME$"
91;Check-traffic;check;$USER2$/centreon_plugins.pl --plugin=$_SERVICEPLUGIN$ --hostname=$HOSTADDRESS$ --snmp-community=$_HOSTSNMPCOMMUNITY$ --snmp-version=$_HOSTSNMPVERSION$ --mode=$_SERVICEMODE$ --interface=$_SERVICEINTERFACE$ --warning-in-traffic=$_SERVICEWARNINGIN$ --warning-out-traffic=$_SERVICEWARNINGOUT$ --critical-in-traffic=$_SERVICECRITICALIN$ --critical-out-traffic=$_SERVICECRITICALOUT$ $_SERVICEOPTION$ $_SERVICEOPTION$
92;Check-ICMP;check;$USER1$/check_icmp -H $HOSTADDRESS$ -n $ARG1$ -w $ARG2$ -c $ARG3$
93;Check-CPU;check;$USER2$/centreon_plugins.pl --plugin=$_SERVICEPLUGIN$ --mode=$_SERVICEMODE$ --hostname=$HOSTADDRESS$ --snmp-community=$_HOSTSNMPCOMMUNITY$ --snmp-version=$_HOSTSNMPVERSION$ --warning=$_SERVICEWARNING$ --critical=$_SERVICECRITICAL$
94;Check-Memory;check;$USER2$/centreon_plugins.pl --plugin=$_SERVICEPLUGIN$ --mode=$_SERVICEMODE$ --hostname=$HOSTADDRESS$ --snmp-community=$_HOSTSNMPCOMMUNITY$ --snmp-version=$_HOSTSNMPVERSION$ --warning-memory=$_SERVICEWARNING$ --critical-memory=$_SERVICECRITICAL$
95;Check-Disk-C:;check;$USER2$/centreon_plugins.pl --plugin=$_SERVICEPLUGIN$ --mode=$_SERVICEMODE$ --hostname=$HOSTADDRESS$ --snmp-community=$_HOSTSNMPCOMMUNITY$ --snmp-version=$_HOSTSNMPVERSION$ --warning-usage=$_SERVICEWARNING$ --critical-usage=$_SERVICECRITICAL$ --storage=$_SERVICEDISK$
96;Check-Disk-E:;check;$USER2$/centreon_plugins.pl --plugin=$_SERVICEPLUGIN$ --mode=$_SERVICEMODE$ --hostname=$HOSTADDRESS$ --snmp-community=$_HOSTSNMPCOMMUNITY$ --snmp-version=$_HOSTSNMPVERSION$ --warning-usage=$_SERVICEWARNING$ --critical-usage=$_SERVICECRITICAL$ --storage=$_SERVICEDISK$
97;Check-Disk-F:;check;$USER2$/centreon_plugins.pl --plugin=$_SERVICEPLUGIN$ --mode=$_SERVICEMODE$ --hostname=$HOSTADDRESS$ --snmp-community=$_HOSTSNMPCOMMUNITY$ --snmp-version=$_HOSTSNMPVERSION$ --warning-usage=$_SERVICEWARNING$ --critical-usage=$_SERVICECRITICAL$ --storage=$_SERVICEDISK$
98;Check-Disk-L:;check;$USER2$/centreon_plugins.pl --plugin=$_SERVICEPLUGIN$ --mode=$_SERVICEMODE$ --hostname=$HOSTADDRESS$ --snmp-community=$_HOSTSNMPCOMMUNITY$ --snmp-version=$_HOSTSNMPVERSION$ --warning-usage=$_SERVICEWARNING$ --critical-usage=$_SERVICECRITICAL$ --storage=$_SERVICEDISK$
99;Check-WINServices;check;$USER2$/centreon_plugins.pl --plugin=$_SERVICEPLUGIN$ --mode=$_SERVICEMODE$ --hostname=$HOSTADDRESS$ --snmp-community=$_HOSTSNMPCOMMUNITY$ --snmp-version=$_HOSTSNMPVERSION$ --service=$_SERVICENAME$ $_SERVICEOPTION$
100;Check-MSExchange;check;$USER2$/centreon_plugins.pl --plugin=$_SERVICEPLUGIN$ --mode=$_SERVICEMODE$ --hostname=$HOSTADDRESS$ --snmp-community=$_HOSTSNMPCOMMUNITY$ --snmp-version=$_HOSTSNMPVERSION$ --process-name=$_SERVICEPROCESS$ $_SERVICEOPTION$
101;Check-MailboxHealth;check;$USER1$/check_centreon_nrpe -H $HOSTADDRESS$ -t $_SERVICETIMEOUT$ -c $_SERVICECOMMAND$
103;Check-ReplicationHealth;check;$USER1$/check_centreon_nrpe -H $HOSTADDRESS$ -t $_SERVICETIMEOUT$ -c $_SERVICECOMMAND$
104;Check-ComponentState;check;$USER1$/check_centreon_nrpe -H $HOSTADDRESS$ -t $_SERVICETIMEOUT$ -c $_SERVICECOMMAND$
105;Check-ExchServices;check;$USER1$/check_centreon_nrpe -H $HOSTADDRESS$ -t $_SERVICETIMEOUT$ -c $_SERVICECOMMAND$
106;Check-DAGHealth;check;$USER1$/check_centreon_nrpe -H $HOSTADDRESS$ -t $_SERVICETIMEOUT$ -c $_SERVICECOMMAND$
107;Check-FailOverDB;check;$USER1$/check_centreon_nrpe -H $HOSTADDRESS$ -t $_SERVICETIMEOUT$ -c $_SERVICECOMMAND$
108;Check-QueueHealth;check;$USER1$/check_centreon_nrpe -H $HOSTADDRESS$ -t $_SERVICETIMEOUT$ -c $_SERVICECOMMAND$
109;Check-IndexStateHealth;check;$USER1$/check_centreon_nrpe -H $HOSTADDRESS$ -t $_SERVICETIMEOUT$ -c $_SERVICECOMMAND$
[root@centreon ~]#

Les amis, je peux passer des jours et des semaines sur ce truc. Vous avez surement compris le fonctionnement. Il y a la documentation Centreon si vous souhaitez maîtriser Clapi.

Vous pouvez effectuer la même chose depuis l’interface Web de Centreon avec Centreon AWIEfull-export-import-conf-centreon-centreon-awie/

Bonne journée et à très bientôt.

10 Responses

  1. amal dit :

    bonjour , je vais faire une migration depuis centreon 2.3 vers 2.8 mais je sais pas d’ou je dois commencer

  2. ash dit :

    bonjour,
    par un pure hasard as tu essayé de de faire une import d’un centreon 2.7.4 et exporter le fichier vers un centreon 2.8.25 !?
    avec clapi j’ai une belle fatal error en lien avec php quand je tente cette manip d’export.
    merci pour tout retour ,
    ash

    • sysadmin dit :

      Bonjour Ash,

      Hum…non malheureusement.
      Pourquoi ne pas mettre à jour d’abord Centreon 2.7.4 à la dernière version (2.8.x) puis faire un export ?
      Tu as installé Centreon manuellement ? ou tu as pris l’ISO Centreon ?
      -Pixel.

Laisser un commentaire

Votre adresse e-mail ne sera pas publiée. Les champs obligatoires sont indiqués avec *