Centreon Clapi (Command Line API) permet d’administrer 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.
Ce que vous pouvez faire en ligne de commande avec Clapi :
- Ajout/Suppression/Mise à jour d’objets tels que les hôtes, les services, les modèles d’hôtes, les groupes d’hôtes, les contacts, etc.
- Générer des fichiers de configuration
- Tester la génération des fichiers de configuration
- Déplacer les fichiers de configuration vers le collecteur de supervision
- Relancer le collecteur Central
- Importation et exportation d’objets e la configuration Centreon.
Nous allons voir dans cet article comment utiliser Centreon Clapi et quelques exemples de commandes très utiles à connaître.
Ce qu’il vous faut :
- Votre plate-forme de supervision Centreon
- Documentation : docs.centreon.com
Voir aussi mes articles sur Clapi :
- Export avec Centreon Clapi : export-configuration-centreon-clapi/
- Import avec Centreon Clapi : import-configuration-centreon-clapi/
- Export / Import avec AWIE : export-import-configuration-centreon-awie/
Centreon Clapi
Pour faciliter l’utilisateur , nous allons d’abord créer un alias sur le serveur Centreon.
Par exemple, au lieu de taper à chaque fois :
[root@pixelabs ~]# ./centreon -u admin -p centreon -o HOST -a ADD -v "PC-PIXEL;Windows 10;192.168.1.5;generic-host;central;Windows"
Ce sera par exemple :
[root@pixelabs ~]# clapi -o HOST -a ADD -v "PC-PIXEL;Windows 10;192.168.1.5;generic-host;central;Windows"
Cela évite également d’afficher le mot de passe Centreon s’il y a du monde autour de vous !
Editer le fichier bashrc à la racine de votre serveur :
[root@pixelabs ~]# nano /root/.bashrc
Ajoutez-y la ligne suivante :
# .bashrc # User specific aliases and functions alias clapi='centreon -u admin -p admin'
Enregistrer & quitter.
Remarque : l’utilisateur et le mot de passe de l’interface web Centreon.
Appliquez les modifications :
[root@pixelabs ~]# source ~/.bashrc
Testez votre alias :
[root@pixelabs ~]# clapi -o HG -a show id;name;alias 5;Serveur-Firewall;Serveur-Firewall 13;Serveur-Linux;Serveur-Linux 19;Serveur-Fichiers;Serveur-Fichiers 26;Serveur-ESXi;Serveur-ESXi 27;Serveur-Exchange;Serveur-Exchange 28;Serveur-Impression;Serveur-Impression 31;Serveur-AIX;Serveur-AIX 32;Serveur-AD;Serveur-AD 33;Serveur-DHCP;Serveur-DHCP 35;Serveur-NextCloud;Serveur-NextCloud 41;Serveur-Windows;serveur-windows [root@pixelabs ~]#
HG : Host Group | Groupe d’hôtes
Commande Clapi
Pour toutes les commandes, si vous souhaitez enregistrer le résultat dans un fichier txt, ajoutez à la fin de votre commande :
> /tmp/centreon_HG.txt
[root@pixelabs ~]# clapi -o HG -a show > /tmp/centreon_HG.txt
Voici quelques commandes Clapi sympa.
Lister les instances :
[root@pixelabs ~]# clapi -o INSTANCE -a show id;name;localhost;ip address;activate;status;engine restart command;engine reload command;broker reload command;bin;stats bin;ssh port;gorgone protocol;gorgone port 1;Central;1;127.0.0.1;1;1;service centengine restart;service centengine reload;service cbd reload;/usr/sbin/centengine;/usr/sbin/centenginestats;22;SSH;22 [root@pixelabs ~]#
Afficher la date de la dernière génération des ACL :
[root@pixelabs ~]# clapi -o ACL -a lastreload -v "d-m-Y H:i:s" 05-01-2021 13:30:01
Lister les macro et les ressources :
[root@pixelabs ~]# clapi -o RESOURCECFG -a show id;name;value;comment;activate;instance 1;$USER1$;/usr/lib64/nagios/plugins;Nagios Plugins Path;1;Central 2;$USER2$;/usr/lib/centreon/plugins;Centreon Plugins Path;1;Central 3;$_SERVICECOMMAND$;0;;1;Central 4;$_HOSTOPTIONV3$;0;;1;Central 5;$_SERVICECOMPONENT$;0;;1;Central 6;$_SERVICECONNECTOR$;0;;1;Central 7;$_SERVICECONTAINER$;0;;1;Central 8;$_SERVICECRITICAL$;0;;1;Central 9;$_SERVICECRITICALIN$;0;;1;Central 10;$_SERVICECRITICALOUT$;0;;1;Central 11;$_SERVICEDISK$;0;;1;Central 12;$_SERVICEESXNAME$;0;;1;Central 13;$_SERVICEHOST$;0;;1;Central 14;$_SERVICEMODE$;0;;1;Central 15;$_SERVICEOPTION$;0;;1;Central 16;$_SERVICEPASSWORD$;0;;1;Central 17;$_SERVICEPLUGIN$;0;;1;Central 18;$_SERVICEPORT$;0;;1;Central 19;$_SERVICEPROCESS$;0;;1;Central 20;$_SERVICESID$;0;;1;Central 21;$_SERVICESUBCOMMAND$;0;;1;Central 22;$_SERVICETIMEOUT$;0;;1;Central 23;$_SERVICEUSERNAME$;0;;1;Central 24;$_SERVICEWARNING$;0;;1;Central 25;$_SERVICEWARNINGIN$;0;;1;Central 26;$_SERVICEWARNINGOUT$;0;;1;Central 27;$_SERVICESTORAGE$;0;;1;Central 28;$_SERVICEPROTO$;0;;1;Central 29;$_SERVICEPATH$;0;;1;Central 30;$_SERVICENAME$;0;;1;Central 31;$_SERVICEDATABASE$;0;;1;Central 32;$_SERVICEDATASOURCE$;0;;1;Central 33;$CENTREONPLUGINS$;/usr/lib/centreon/plugins;Directory of Centreon Plugins;0;Central 34;$_SERVICEINTERFACE$;0;;1;Central 35;$USER3$;/usr/lib/nextcloud/plugins;NextCloud Plugin Path;1;Central 36;$_SERVICEUNITS$;0;;1;Central 37;$_SERVICEURL$;0;;1;Central 38;$_SERVICESQLSTATEMENT$;0;;1;Central 39;$_SERVICEFORMAT$;0;;1;Central 40;$_SERVICEFILTER$;0;;1;Central 41;$_SERVICECUSTOMCOMMAND$;0;;1;Central 42;$_SERVICESTATUS$;0;;1;Central 43;$_SERVICEPERFDATA$;0;;1;Central 44;$_SERVICEARG1$;0;;1;Central 45;$_SERVICEARG2$;0;;1;Central 46;$_SERVICEARG3$;0;;1;Central 47;$_SERVICEEXTRAOPTIONS$;0;;1;Central 48;$_SERVICESSL$;0;;1;Central 50;$_SERVICESTRING$;0;;1;Central 51;$_SERVICECOOKIES$;0;;1;Central [root@pixelabs ~]#
Lister Centreon Broker CFG :
[root@pixelabs ~]# clapi -o CENTBROKERCFG -a show config id;config name;instance 1;central-broker-master;Central 2;central-rrd-master;Central 3;central-module-master;Central [root@pixelabs ~]#
Lister la configuration LDAP :
[root@pixelabs ~]# clapi -o LDAP -a show
Afficher les paramètres d’un modèle de service. Ici, le modèle de service : Cisco-CPU
[root@pixelabs ~]# clapi -e --select='STPL;Cisco-CPU' --filter-type='^(STPL)' STPL;ADD;service_template;Service; STPL;setparam;service_template;check_period;workhours STPL;setparam;service_template;notification_period;workhours STPL;setparam;service_template;service_is_volatile;2 STPL;setparam;service_template;service_max_check_attempts;3 STPL;setparam;service_template;service_normal_check_interval;1 STPL;setparam;service_template;service_retry_check_interval;1 STPL;setparam;service_template;service_active_checks_enabled;2 STPL;setparam;service_template;service_passive_checks_enabled;2 STPL;setparam;service_template;service_parallelize_check;2 STPL;setparam;service_template;service_obsess_over_service;2 STPL;setparam;service_template;service_check_freshness;2 STPL;setparam;service_template;service_event_handler_enabled;2 STPL;setparam;service_template;service_flap_detection_enabled;2 STPL;setparam;service_template;service_process_perf_data;2 STPL;setparam;service_template;service_retain_status_information;2 STPL;setparam;service_template;service_retain_nonstatus_information;2 STPL;setparam;service_template;service_notification_interval;0 STPL;setparam;service_template;service_notifications_enabled;2 STPL;setparam;service_template;contact_additive_inheritance;0 STPL;setparam;service_template;cg_additive_inheritance;0 STPL;setparam;service_template;service_inherit_contacts_from_host;1 STPL;setparam;service_template;service_locked;0 STPL;setparam;service_template;service_register;0 STPL;setparam;service_template;service_activate;1 STPL;ADD;Cisco-CPU;Check-CPU;service_template STPL;setparam;Cisco-CPU;check_command;Check-Cisco-Storage STPL;setparam;Cisco-CPU;check_period;workhours STPL;setparam;Cisco-CPU;notification_period;workhours STPL;setparam;Cisco-CPU;service_is_volatile;2 STPL;setparam;Cisco-CPU;service_active_checks_enabled;2 STPL;setparam;Cisco-CPU;service_passive_checks_enabled;2 STPL;setparam;Cisco-CPU;service_parallelize_check;2 STPL;setparam;Cisco-CPU;service_obsess_over_service;2 STPL;setparam;Cisco-CPU;service_check_freshness;2 STPL;setparam;Cisco-CPU;service_event_handler_enabled;2 STPL;setparam;Cisco-CPU;service_flap_detection_enabled;2 STPL;setparam;Cisco-CPU;service_process_perf_data;2 STPL;setparam;Cisco-CPU;service_retain_status_information;2 STPL;setparam;Cisco-CPU;service_retain_nonstatus_information;2 STPL;setparam;Cisco-CPU;service_notification_interval;0 STPL;setparam;Cisco-CPU;service_notifications_enabled;2 STPL;setparam;Cisco-CPU;contact_additive_inheritance;0 STPL;setparam;Cisco-CPU;cg_additive_inheritance;0 STPL;setparam;Cisco-CPU;service_inherit_contacts_from_host;1 STPL;setparam;Cisco-CPU;service_locked;0 STPL;setparam;Cisco-CPU;service_register;0 STPL;setparam;Cisco-CPU;service_activate;1 STPL;setparam;Cisco-CPU;icon_image;icones/cpu2.png STPL;setmacro;Cisco-CPU;plugin;network::cisco::standard::snmp::plugin STPL;setmacro;Cisco-CPU;mode;cpu STPL;setmacro;Cisco-CPU;warning;85 STPL;setmacro;Cisco-CPU;critical;95 STPL;setmacro;Cisco-CPU;option;--verbose
Afficher les paramètres d’un modèle hôte. Ici, le modèle hôte : Serveur-ESXi
[root@pixelabs ~]# clapi -e --select='HTPL;Serveur-ESXi' --filter-type='^(HTPL)' HTPL;ADD;Serveur-ESXi;Serveur-ESXi;;;; HTPL;setparam;Serveur-ESXi;host_active_checks_enabled;2 HTPL;setparam;Serveur-ESXi;host_passive_checks_enabled;2 HTPL;setparam;Serveur-ESXi;host_checks_enabled;2 HTPL;setparam;Serveur-ESXi;host_obsess_over_host;2 HTPL;setparam;Serveur-ESXi;host_check_freshness;2 HTPL;setparam;Serveur-ESXi;host_event_handler_enabled;2 HTPL;setparam;Serveur-ESXi;host_flap_detection_enabled;2 HTPL;setparam;Serveur-ESXi;host_process_perf_data;2 HTPL;setparam;Serveur-ESXi;host_retain_status_information;2 HTPL;setparam;Serveur-ESXi;host_retain_nonstatus_information;2 HTPL;setparam;Serveur-ESXi;host_notifications_enabled;2 HTPL;setparam;Serveur-ESXi;contact_additive_inheritance;0 HTPL;setparam;Serveur-ESXi;cg_additive_inheritance;0 HTPL;setparam;Serveur-ESXi;host_snmp_community;public HTPL;setparam;Serveur-ESXi;host_snmp_version;2c HTPL;setparam;Serveur-ESXi;timezone;Europe/Paris HTPL;setparam;Serveur-ESXi;host_locked;0 HTPL;setparam;Serveur-ESXi;host_register;0 HTPL;setparam;Serveur-ESXi;host_activate;1 HTPL;setparam;Serveur-ESXi;icon_image;icones/vmware2.png HTPL;ADD;generic-host;generic-host;;;; HTPL;setparam;generic-host;check_command;check-host-alive HTPL;setparam;generic-host;check_period;workhours HTPL;setparam;generic-host;notification_period;workhours HTPL;setparam;generic-host;host_max_check_attempts;3 HTPL;setparam;generic-host;host_active_checks_enabled;1 HTPL;setparam;generic-host;host_passive_checks_enabled;0 HTPL;setparam;generic-host;host_checks_enabled;2 HTPL;setparam;generic-host;host_obsess_over_host;2 HTPL;setparam;generic-host;host_check_freshness;2 HTPL;setparam;generic-host;host_event_handler_enabled;2 HTPL;setparam;generic-host;host_flap_detection_enabled;2 HTPL;setparam;generic-host;host_process_perf_data;2 HTPL;setparam;generic-host;host_retain_status_information;2 HTPL;setparam;generic-host;host_retain_nonstatus_information;2 HTPL;setparam;generic-host;host_notification_interval;0 HTPL;setparam;generic-host;host_notification_options;d,r HTPL;setparam;generic-host;host_notifications_enabled;0 HTPL;setparam;generic-host;contact_additive_inheritance;0 HTPL;setparam;generic-host;cg_additive_inheritance;0 HTPL;setparam;generic-host;host_snmp_community;public HTPL;setparam;generic-host;host_snmp_version;2c HTPL;setparam;generic-host;timezone;Europe/Paris HTPL;setparam;generic-host;host_locked;0 HTPL;setparam;generic-host;host_register;0 HTPL;setparam;generic-host;host_activate;1 HTPL;addtemplate;Serveur-ESXi;generic-host
Lister les paramètres d’un seul service. Le nom de service ici : Check-Centengine
[root@pixelabs ~]# clapi -e --select='SERVICE' | grep "Check-Centengine" SERVICE;ADD;serv-centreon;Check-Centengine;SNMP-Linux-Process SERVICE;setparam;serv-centreon;Check-Centengine;service_is_volatile;2 SERVICE;setparam;serv-centreon;Check-Centengine;service_active_checks_enabled;2 SERVICE;setparam;serv-centreon;Check-Centengine;service_passive_checks_enabled;2 SERVICE;setparam;serv-centreon;Check-Centengine;service_parallelize_check;2 SERVICE;setparam;serv-centreon;Check-Centengine;service_obsess_over_service;2 SERVICE;setparam;serv-centreon;Check-Centengine;service_check_freshness;2 SERVICE;setparam;serv-centreon;Check-Centengine;service_event_handler_enabled;2 SERVICE;setparam;serv-centreon;Check-Centengine;service_flap_detection_enabled;2 SERVICE;setparam;serv-centreon;Check-Centengine;service_process_perf_data;2 SERVICE;setparam;serv-centreon;Check-Centengine;service_retain_status_information;2 SERVICE;setparam;serv-centreon;Check-Centengine;service_retain_nonstatus_information;2 SERVICE;setparam;serv-centreon;Check-Centengine;service_notifications_enabled;2 SERVICE;setparam;serv-centreon;Check-Centengine;contact_additive_inheritance;0 SERVICE;setparam;serv-centreon;Check-Centengine;cg_additive_inheritance;0 SERVICE;setparam;serv-centreon;Check-Centengine;service_inherit_contacts_from_host;1 SERVICE;setparam;serv-centreon;Check-Centengine;service_use_only_contacts_from_host;0 SERVICE;setparam;serv-centreon;Check-Centengine;service_locked;0 SERVICE;setparam;serv-centreon;Check-Centengine;service_register;1 SERVICE;setparam;serv-centreon;Check-Centengine;service_activate;1 SERVICE;setmacro;serv-centreon;Check-Centengine;critical;'1:';;'' SERVICE;setmacro;serv-centreon;Check-Centengine;option;--cpu --memory --regexp-name --process-status --verbose;;'' SERVICE;setmacro;serv-centreon;Check-Centengine;process;'centengine';;'' [root@pixelabs ~]#
La documentation est assez complète et vous avez ce qu’il faut pour gérer votre plate-forme en ligne de commande.
Bonne journée et à bientôt.
Merci pour l’article 🙂