Surveillance serveur · 7 min read · Oct 18, 2025

Surveillance de serveur avec Icinga sur Debian Squeeze - Page 2

3 Configurer Icinga

server1.example.com:

Le fichier de configuration principal d’Icinga est /etc/icinga/icinga.cfg, les configurations supplémentaires sont stockées dans /etc/icinga/commands.cfg et /etc/icinga/resource.cfg. En général, la configuration par défaut est correcte, donc vous n’avez pas besoin de modifier ces fichiers.

La première chose que vous devez changer est les coordonnées de contact dans /etc/icinga/objects/contacts_icinga.cfg afin que les notifications soient envoyées à la bonne adresse e-mail :

vi /etc/icinga/objects/contacts_icinga.cfg

| [...] define contact{ contact_name root alias Falko Timme service_notification_period 24x7 host_notification_period 24x7 service_notification_options w,u,c,r host_notification_options d,r service_notification_commands notify-service-by-email host_notification_commands notify-host-by-email email [email protected] } [...] |

Les vérifications de service pour localhost (= server1.example.com) sont définies dans /etc/icinga/objects/localhost_icinga.cfg - jetez un œil à ce fichier :

cat /etc/icinga/objects/localhost_icinga.cfg

| # Un fichier de configuration simple pour surveiller l'hôte local # Cela peut servir d'exemple pour configurer d'autres serveurs ; # Des services personnalisés spécifiques à cet hôte sont ajoutés ici, mais les services # définis dans icinga-common_services.cfg peuvent également s'appliquer. # define host{ use generic-host ; Nom du modèle d'hôte à utiliser host_name localhost alias localhost address 127.0.0.1 } # Définir un service pour vérifier l'espace disque de la partition racine # sur la machine locale. Avertissement si < 20% libre, critique si # < 10% d'espace libre sur la partition. define service{ use generic-service ; Nom du modèle de service à utiliser host_name localhost service_description Espace Disque check_command check_all_disks!20%!10% } # Définir un service pour vérifier le nombre d'utilisateurs actuellement connectés # sur la machine locale. Avertissement si > 20 utilisateurs, critique # si > 50 utilisateurs. define service{ use generic-service ; Nom du modèle de service à utiliser host_name localhost service_description Utilisateurs Actuels check_command check_users!20!50 } # Définir un service pour vérifier le nombre de processus actuellement en cours d'exécution # sur la machine locale. Avertissement si > 250 processus, critique si # > 400 processus. define service{ use generic-service ; Nom du modèle de service à utiliser host_name localhost service_description Total des Processus check_command check_procs!250!400 } # Définir un service pour vérifier la charge sur la machine locale. define service{ use generic-service ; Nom du modèle de service à utiliser host_name localhost service_description Charge Actuelle check_command check_load!5.0!4.0!3.0!10.0!6.0!4.0 } |

Les commandes check_command (comme check_all_disks) sont définies dans les fichiers de configuration des plugins Nagios dans le répertoire /etc/nagios-plugins/config :

ls -l /etc/nagios-plugins/config
root@server1:~# ls -l /etc/nagios-plugins/config  
total 144  
-rw-r--r-- 1 root root  277 May 23 04:55 apt.cfg  
-rw-r--r-- 1 root root  182 May 23 04:55 breeze.cfg  
-rw-r--r-- 1 root root  458 May 23 04:55 dhcp.cfg  
-rw-r--r-- 1 root root  909 May 23 04:55 disk.cfg  
-rw-r--r-- 1 root root 1722 May 23 04:55 disk-smb.cfg  
-rw-r--r-- 1 root root  321 May 23 04:55 dns.cfg  
-rw-r--r-- 1 root root  673 May 23 04:55 dummy.cfg  
-rw-r--r-- 1 root root  146 May 23 04:55 flexlm.cfg  
-rw-r--r-- 1 root root  159 May 23 04:55 fping.cfg  
-rw-r--r-- 1 root root  414 May 23 04:55 ftp.cfg  
-rw-r--r-- 1 root root  320 May 23 04:55 games.cfg  
-rw-r--r-- 1 root root  157 May 23 04:55 hppjd.cfg  
-rw-r--r-- 1 root root 3579 May 23 04:55 http.cfg  
-rw-r--r-- 1 root root  818 May 23 04:55 ifstatus.cfg  
-rw-r--r-- 1 root root  748 May 23 04:55 ldap.cfg  
-rw-r--r-- 1 root root  195 May 23 04:55 load.cfg  
-rw-r--r-- 1 root root 2062 May 23 04:55 mail.cfg  
-rw-r--r-- 1 root root  708 May 23 04:55 mailq.cfg  
-rw-r--r-- 1 root root  385 May 23 04:55 mrtg.cfg  
-rw-r--r-- 1 root root  567 May 23 04:55 mysql.cfg  
-rw-r--r-- 1 root root 2355 May 23 04:55 netware.cfg  
-rw-r--r-- 1 root root  420 May 23 04:55 news.cfg  
-rw-r--r-- 1 root root  491 May 23 04:55 nt.cfg  
-rw-r--r-- 1 root root  466 May 23 04:55 ntp.cfg  
-rw-r--r-- 1 root root  426 May 23 04:55 pgsql.cfg  
-rw-r--r-- 1 root root 2026 May 23 04:55 ping.cfg  
-rw-r--r-- 1 root root  511 May 23 04:55 procs.cfg  
-rw-r--r-- 1 root root  240 May 23 04:55 radius.cfg  
-rw-r--r-- 1 root root  397 May 23 04:55 real.cfg  
-rw-r--r-- 1 root root  315 May 23 04:55 rpc-nfs.cfg  
-rw-r--r-- 1 root root 5550 May 23 04:55 snmp.cfg  
-rw-r--r-- 1 root root  753 May 23 04:55 ssh.cfg  
-rw-r--r-- 1 root root  784 May 23 04:55 tcp_udp.cfg  
-rw-r--r-- 1 root root  438 May 23 04:55 telnet.cfg  
-rw-r--r-- 1 root root  155 May 23 04:55 users.cfg  
root@server1:~#

Voyons le fichier /etc/nagios-plugins/config/disk.cfg :

cat /etc/nagios-plugins/config/disk.cfg

| # définition de la commande 'check_disk' define command{ command_name check_disk command_line /usr/lib/nagios/plugins/check_disk -w '$ARG1$' -c '$ARG2$' -e -p '$ARG3$' } # définition de la commande 'check_all_disks' define command{ command_name check_all_disks command_line /usr/lib/nagios/plugins/check_disk -w '$ARG1$' -c '$ARG2$' -e } # définition de la commande 'ssh_disk' define command{ command_name ssh_disk command_line /usr/lib/nagios/plugins/check_by_ssh -H '$HOSTADDRESS$' -C "/usr/lib/nagios/plugins/check_disk -w '$ARG1$' -c '$ARG2$' -e -p '$ARG3$'" } #### # utilisez ces vérifications, si vous souhaitez tester la connectivité IPv4 sur des systèmes activés IPv6 #### # définition de la commande 'ssh_disk_4' define command{ command_name ssh_disk_4 command_line /usr/lib/nagios/plugins/check_by_ssh -H '$HOSTADDRESS$' -C "/usr/lib/nagios/plugins/check_disk -w '$ARG1$' -c '$ARG2$' -e -p '$ARG3$'" -4 } |

Comme vous le voyez, la commande check_all_disks est définie comme /usr/lib/nagios/plugins/check_disk -w ‘$ARG1$’ -c ‘$ARG2$’ -e. Si vous regardez à nouveau le fichier /etc/icinga/objects/localhost_icinga.cfg, vous verrez que nous avons la ligne check_command check_all_disks!20%!10% dedans. Icinga nous permet de passer des arguments de ligne de commande aux vérifications de service en les séparant par un point d’exclamation (!), donc check_command check_all_disks!20%!10% signifie que nous passons 20% comme le premier argument de ligne de commande et 10% comme le deuxième argument de ligne de commande à la commande /usr/lib/nagios/plugins/check_disk -w ‘$ARG1$’ -c ‘$ARG2$’ -e, de sorte que cela se traduit finalement par /usr/lib/nagios/plugins/check_disk -w ‘20%’ -c ‘10%’ -e.

Si vous souhaitez passer un argument de ligne de commande qui contient un point d’exclamation, vous devez échapper le point d’exclamation avec un antislash : !

Les plugins Nagios (c’est-à-dire les outils qu’Icinga utilise pour exécuter des vérifications) se trouvent dans le répertoire /usr/lib/nagios/plugins :

ls -l /usr/lib/nagios/plugins
root@server1:~# ls -l /usr/lib/nagios/plugins  
total 2476  
-rwxr-xr-x 1 root root 106120 May 23 04:55 check_apt  
-rwxr-xr-x 1 root root   5369 May 23 04:55 check_bgpstate  
-rwxr-xr-x 1 root root   2242 May 23 04:55 check_breeze  
-rwxr-xr-x 1 root root  46192 May 23 04:55 check_by_ssh  
lrwxrwxrwx 1 root root      9 Aug 23 12:14 check_clamd -> check_tcp  
-rwxr-xr-x 1 root root  32072 May 23 04:55 check_cluster  
-rwxr-xr-x 1 root root  44816 May 23 04:55 check_dhcp  
-rwxr-xr-x 1 root root  41392 May 23 04:55 check_dig  
-rwxr-xr-x 1 root root 119216 May 23 04:55 check_disk  
-rwxr-xr-x 1 root root   8726 May 23 04:55 check_disk_smb  
-rwxr-xr-x 1 root root  45488 May 23 04:55 check_dns  
-rwxr-xr-x 1 root root  28968 May 23 04:55 check_dummy  
-rwxr-xr-x 1 root root   3053 May 23 04:55 check_file_age  
-rwxr-xr-x 1 root root   6315 May 23 04:55 check_flexlm  
-rwxr-xr-x 1 root root  44656 May 23 04:55 check_fping  
lrwxrwxrwx 1 root root      9 Aug 23 12:14 check_ftp -> check_tcp  
-rwxr-xr-x 1 root root  36584 May 23 04:55 check_game  
lrwxrwxrwx 1 root root     10 Aug 23 12:14 check_host -> check_icmp  
-rwxr-xr-x 1 root root  41136 May 23 04:55 check_hpjd  
-rwxr-xr-x 1 root root 164624 May 23 04:55 check_http  
-rwxr-xr-x 1 root root  49264 May 23 04:55 check_icmp  
-rwxr-xr-x 1 root root  34536 May 23 04:55 check_ide_smart  
-rwxr-xr-x 1 root root  15134 May 23 04:55 check_ifoperstatus  
-rwxr-xr-x 1 root root  12598 May 23 04:55 check_ifstatus  
lrwxrwxrwx 1 root root      9 Aug 23 12:14 check_imap -> check_tcp  
-rwxr-xr-x 1 root root   6887 May 23 04:55 check_ircd  
lrwxrwxrwx 1 root root      9 Aug 23 12:14 check_jabber -> check_tcp  
-rwxr-xr-x 1 root root  40816 May 23 04:55 check_ldap  
lrwxrwxrwx 1 root root     10 Aug 23 12:14 check_ldaps -> check_ldap  
-rwxr-xr-x 1 root root   3407 May 23 04:55 check_linux_raid  
-rwxr-xr-x 1 root root  36168 May 23 04:55 check_load  
-rwxr-xr-x 1 root root   6026 May 23 04:55 check_log  
-rwxr-xr-x 1 root root  20284 May 23 04:55 check_mailq  
-rwxr-xr-x 1 root root  36264 May 23 04:55 check_mrtg  
-rwxr-xr-x 1 root root  34440 May 23 04:55 check_mrtgtraf  
-rwxr-xr-x 1 root root  45936 May 23 04:55 check_mysql  
-rwxr-xr-x 1 root root  44688 May 23 04:55 check_mysql_query  
-rwxr-xr-x 1 root root  36616 May 23 04:55 check_nagios  
lrwxrwxrwx 1 root root      9 Aug 23 12:14 check_nntp -> check_tcp  
lrwxrwxrwx 1 root root      9 Aug 23 12:14 check_nntps -> check_tcp  
-rwxr-xr-x 1 root root  48720 May 23 04:55 check_nt  
-rwxr-xr-x 1 root root  46288 May 23 04:55 check_ntp  
-rwxr-xr-x 1 root root  44880 May 23 04:55 check_ntp_peer  
-rwxr-xr-x 1 root root  42224 May 23 04:55 check_ntp_time  
-rwxr-xr-x 1 root root  60912 May 23 04:55 check_nwstat  
-rwxr-xr-x 1 root root   8326 May 23 04:55 check_oracle  
-rwxr-xr-x 1 root root  40400 May 23 04:55 check_overcr  
-rwxr-xr-x 1 root root  40656 May 23 04:55 check_pgsql  
-rwxr-xr-x 1 root root  48848 May 23 04:55 check_ping  
lrwxrwxrwx 1 root root      9 Aug 23 12:14 check_pop -> check_tcp  
-rwxr-xr-x 1 root root 114640 May 23 04:55 check_procs  
-rwxr-xr-x 1 root root  40624 May 23 04:55 check_radius  
-rwxr-xr-x 1 root root  40464 May 23 04:55 check_real  
-rwxr-xr-x 1 root root   9581 May 23 04:55 check_rpc  
lrwxrwxrwx 1 root root     10 Aug 23 12:14 check_rta_multi -> check_icmp  
-rwxr-xr-x 1 root root   1137 May 23 04:55 check_sensors  
lrwxrwxrwx 1 root root      9 Aug 23 12:14 check_simap -> check_tcp  
-rwxr-xr-x 1 root root 127216 May 23 04:55 check_smtp  
-rwxr-xr-x 1 root root 152008 May 23 04:55 check_snmp  
lrwxrwxrwx 1 root root      9 Aug 23 12:14 check_spop -> check_tcp  
-rwxr-xr-x 1 root root  36688 May 23 04:55 check_ssh  
lrwxrwxrwx 1 root root      9 Aug 23 12:14 check_ssmtp -> check_tcp  
-rwxr-xr-x 1 root root  37832 May 23 04:55 check_swap  
-rwxr-xr-x 1 root root  49328 May 23 04:55 check_tcp  
-rwxr-xr-x 1 root root  38128 May 23 04:55 check_time  
lrwxrwxrwx 1 root root      9 Aug 23 12:14 check_udp -> check_tcp  
-rwxr-xr-x 1 root root  44560 May 23 04:55 check_ups  
-rwxr-xr-x 1 root root  36168 May 23 04:55 check_users  
-rwxr-xr-x 1 root root   2936 May 23 04:55 check_wave  
-rwxr-xr-x 1 root root  38152 May 23 04:55 negate  
-rwxr-xr-x 1 root root  36104 May 23 04:55 urlize  
-rw-r--r-- 1 root root   1938 May 23 04:55 utils.pm  
-rwxr-xr-x 1 root root    862 May 23 04:55 utils.sh  
root@server1:~#

Pour découvrir quels arguments de ligne de commande un plugin peut accepter, appelez ce plugin avec l’option –help. Par exemple, pour savoir comment le plugin check_disk peut être utilisé, exécutez

/usr/lib/nagios/plugins/check_disk --help

Avec cette connaissance, vous pouvez modifier les vérifications de service dans /etc/icinga/objects/localhost_icinga.cfg selon vos préférences, et vous pouvez ajouter/modifier les configurations de plugin dans le répertoire /etc/nagios-plugins/config.

Maintenant, supposons que nous voulons ajouter une vérification de service pour MySQL, nous jetons d’abord un œil à la configuration de plugin appropriée :

cat /etc/nagios-plugins/config/mysql.cfg

| # définition de la commande 'check_mysql' define command{ command_name check_mysql command_line /usr/lib/nagios/plugins/check_mysql -H '$HOSTADDRESS$' } # définition de la commande 'check_mysql_cmdlinecred' define command{ command_name check_mysql_cmdlinecred command_line /usr/lib/nagios/plugins/check_mysql -H '$HOSTADDRESS$' -u '$ARG1$' -p '$ARG2$' } # définition de la commande 'check_mysql_database' define command{ command_name check_mysql_database command_line /usr/lib/nagios/plugins/check_mysql -d '$ARG3$' -H '$HOSTADDRESS$' -u '$ARG1$' -p '$ARG2$' } |

La commande que je veux utiliser est check_mysql_cmdlinecred - cela prend un nom d’utilisateur MySQL et un mot de passe comme arguments (en plus de l’adresse hôte qui est prise à partir du paramètre host_name de la définition de vérification de service. Je veux utiliser l’utilisateur MySQL nagios avec le mot de passe howtoforge ici, donc j’ajoute la section suivante à /etc/icinga/objects/localhost_icinga.cfg :

vi /etc/icinga/objects/localhost_icinga.cfg

| [...] define service{ use generic-service host_name localhost service_description MySQL check_command check_mysql_cmdlinecred!nagios!howtoforge } |

Avant de redémarrer Icinga, nous devons créer l’utilisateur MySQL nagios avec le mot de passe howtoforge :

mysql -u root -p
GRANT USAGE ON *.* TO nagios@localhost IDENTIFIED BY 'howtoforge';  
GRANT USAGE ON *.* TO [email protected] IDENTIFIED BY 'howtoforge';  
FLUSH PRIVILEGES;
quit;

(Le privilège USAGE est un synonyme de ‘aucun privilège’, c’est-à-dire que l’utilisateur nagios peut se connecter à MySQL, mais ne peut pas modifier ou lire des données.)

Maintenant, nous redémarrons Icinga pour que nos modifications prennent effet :

/etc/init.d/icinga restart

Si vous vérifiez les services de localhost dans l’interface web d’Icinga maintenant, vous devriez voir qu’une vérification pour MySQL a été ajoutée :

De même, nous pouvons ajouter des vérifications pour SMTP, POP3 et IMAP - ce sont juste des vérifications de connexion, donc nous n’avons besoin d’aucun argument :

vi /etc/icinga/objects/localhost_icinga.cfg

| [...] define service{ use generic-service host_name localhost service_description SMTP check_command check_smtp } define service{ use generic-service host_name localhost service_description POP3 check_command check_pop } define service{ use generic-service host_name localhost service_description IMAP check_command check_imap } |

Redémarrez Icinga…

/etc/init.d/icinga restart

… et quelques instants plus tard, vous devriez voir les nouvelles vérifications dans l’interface web d’Icinga :

Vous avez peut-être remarqué les vérifications SSH et HTTP pour localhost qui ne sont pas définies dans /etc/icinga/objects/localhost_icinga.cfg. Celles-ci sont définies dans les groupes d’hôtes dans le fichier /etc/icinga/objects/hostgroups_icinga.cfg. Un groupe d’hôtes nous permet d’exécuter une vérification de service pour plusieurs serveurs et de la définir une seule fois. Jetez un œil à ce fichier :

cat /etc/icinga/objects/hostgroups_icinga.cfg

| # Quelques définitions de groupes d'hôtes génériques # Un groupe d'hôtes simple avec un joker define hostgroup { hostgroup_name all alias Tous les Serveurs members * } # Une liste de vos serveurs Debian GNU/Linux define hostgroup { hostgroup_name debian-servers alias Serveurs Debian GNU/Linux members localhost } # Une liste de vos serveurs web define hostgroup { hostgroup_name http-servers alias Serveurs HTTP members localhost } # Une liste de vos serveurs accessibles par ssh define hostgroup { hostgroup_name ssh-servers alias Serveurs SSH members localhost } |

Comme vous le voyez, nous avons un groupe d’hôtes appelé http-servers et un groupe d’hôtes appelé ssh-servers, et localhost est membre de chacun de ces groupes. Les vérifications de service pour les groupes d’hôtes sont définies dans /etc/icinga/objects/services_icinga.cfg. Ce fichier contient des vérifications de service et fait référence aux groupes d’hôtes auxquels ces vérifications doivent s’appliquer en utilisant le paramètre hostgroup_name :

cat /etc/icinga/objects/services_icinga.cfg

| # vérifier que les services web fonctionnent define service { hostgroup_name http-servers service_description HTTP check_command check_http use generic-service notification_interval 0 ; définir > 0 si vous souhaitez être renotifié } # vérifier que les services ssh fonctionnent define service { hostgroup_name ssh-servers service_description SSH check_command check_ssh use generic-service notification_interval 0 ; définir > 0 si vous souhaitez être renotifié } |

Share: X/Twitter LinkedIn

Recevez de nouveaux articles dans votre boîte de réception.

Aucun spam. Désabonnez-vous à tout moment.