Nagios est installé, il ne reste plus qu’à le configurer. Voici comment monitorer une infra simple en créant quelques fichiers de configuration.
Pour vérifier votre configuration de Nagios, vous pouvez exécuter la commande
# /usr/local/bin/nagios -v /usr/local/etc/nagios/nagios.cfg
Et pour redémarrer Nagios afin qu’il prenne en compte les dernières versions des fichiers de config
# service nagios restart
Configuration de Nagios
Afin d’avoir une structure un peu hiérarchisée au niveau des machines à surveiller, on peut éditer le fichier nagios.cfg et y ajouter
cfg_dir=/usr/local/etc/nagios/objects
afin que tous les fichiers .cfg contenus dans /usr/local/etc/nagios/objects soient ajoutés.
Dans ce directory « objects », on doit retrouver pour l’instant les fichiers
commands.cfg
contacts.cfg
timeperiods.cfg
ainsi que les templates et le fichier de config du localhost
generic-host.cfg
generic-service.cfg
generic-contact.cfg
localhost.cfg
Afficher: generic-host.cfg |
SelectAfficher> |
# All default values are set by this generic-host template
define host{
name generic-host
initial_state o
active_checks_enabled 1
passive_checks_enabled 1
notifications_enabled 1
event_handler_enabled 0
check_command check-host-alive
flap_detection_enabled 1
failure_prediction_enabled 1
failure_prediction_options d,u,r
process_perf_data 1
check_freshness 0
obsess_over_host 0
check_period 24x7
check_interval 0
retry_interval 1
stalking_options u,d
max_check_attempts 10
retain_status_information 1
retain_nonstatus_information 1
notification_period 24x7
first_notification_delay 0
contact_groups admins
notification_options d,u,r
notification_interval 0
register 0
notes generic-host
}
|
Afficher: generic-service.cfg |
SelectAfficher> |
# All default values are set by this generic-host template
define service{
name generic-service
active_checks_enabled 1
passive_checks_enabled 1
initial_state o
parallelize_check 1
obsess_over_service 0
check_freshness 0
notifications_enabled 1
event_handler_enabled 0
flap_detection_enabled 1
failure_prediction_enabled 1
failure_prediction_options w,c,u
process_perf_data 1
retain_status_information 1
retain_nonstatus_information 1
is_volatile 0
check_period 24x7
flap_detection_options o,u,c,w
max_check_attempts 5
normal_check_interval 5
retry_check_interval 2
contact_groups admins
notification_options w,u,c,r
notification_interval 0
notification_period 24x7
first_notification_delay 0
notes generic-service
register 0
}
|
Afficher: generic-contact.cfg |
SelectAfficher> |
define contact{
name generic-contact
service_notification_period 24x7
host_notification_period 24x7
service_notification_options w,u,c,r,f,s
host_notification_options d,u,r,f,s
service_notification_commands notify-service-by-email
host_notification_commands notify-host-by-email
register 0
}
|
Afficher: localhost.cfg |
SelectAfficher> |
# HOST DEFINITION
# Define a host for the local machine
define host{
use generic-host
host_name localhost
alias localhost
address 127.0.0.1
}
# SERVICE DEFINITIONS
# Define a service to "ping" the local machine
define service{
use generic-service
host_name localhost
service_description PING
check_command check_ping!100.0,20%!500.0,60%
}
# Define a service to check the disk space of the root partition
# on the local machine. Warning if < 20% free, critical if
# < 10% free space on partition.
define service{
use generic-service
host_name localhost
service_description Root Partition
check_command check_local_disk!20%!10%!/
}
# Define a service to check the number of currently logged in
# users on the local machine. Warning if > 20 users, critical
# if > 50 users.
define service{
use generic-service
host_name localhost
service_description Current Users
check_command check_local_users!20!50
}
# Define a service to check the number of currently running procs
# on the local machine. Warning if > 250 processes, critical if
# > 400 users.
define service{
use generic-service
host_name localhost
service_description Total Processes
check_command check_local_procs!250!400!RSZDT
}
# Define a service to check the load on the local machine.
define service{
use generic-service
host_name localhost
service_description Current Load
check_command check_local_load!5.0,4.0,3.0!10.0,6.0,4.0
}
# Define a service to check the swap usage the local machine.
# Critical if less than 10% of swap is free, warning if less than 20% is free
define service{
use generic-service
host_name localhost
service_description Swap Usage
check_command check_local_swap!20!10
}
# Define a service to check SSH on the local machine.
# Disable notifications for this service by default, as not all users may have SSH enabled.
define service{
use generic-service
host_name localhost
service_description SSH
check_command check_ssh
notifications_enabled 0
}
# Define a service to check HTTP on the local machine.
# Disable notifications for this service by default, as not all users may have HTTP enabled.
define service{
use generic-service
host_name localhost
service_description HTTP
check_command check_http
notifications_enabled 0
}
|
Création d’un host
Dans le directory objects, on crée le fichier de config gandalf.cfg qui définit notre premier host (en utilisant notre template generic-host et en remplaçant les « x » par l’adresse IP)
define host{
use generic-host
host_name gandalf
alias Gandalf
address xx.xx.xx.xx
}
Si vous préférez utiliser la résolution DNS plutôt que de spécifier une adresse IP, vous pouvez supprimer la ligne « address ».
Après un redémarrage, le nouveau host apparaît dans les hosts de Nagios.

Ajout de services pour notre nouveau host
Pour créer des services pour un host, on ajoute simplement la liste des services et leurs paramètres à son fichier de config
# Definition du service de Load Average
define service{
use generic-service
host_name gandalf
service_description Load Average
check_command check_load!5.0,4.0,3.0!10.0,8.0,6.0
}
# Definition du service de controle d'url Web
define service{
use generic-service
host_name gandalf
service_description Reponse interface Web
check_command check_http!"http://gandalf"
notifications_enabled 0
}
La commande check_load n’étant pas connue (erreur lors de la vérification des fichiers), il faut la définir en l’ajoutant au fichier commands.cfg
# 'check_load' command definition
define command{
command_name check_load
command_line $USER1$/check_load -w $ARG1$ -c $ARG2$
}
Après un redémarrage de Nagios, l’affichage des services devrait ressembler à ceci

Création d’un contact
On édite le fichier contacts.cfg et on y ajoute un contact et son groupe
define contact{
contact_name jsmith
use generic-contact
alias John Smith
email j.smith@company.be
}
define contactgroup{
contactgroup_name support
alias Support Technique
members jsmith
}
Pour que le groupe Support Technique soit alerté, il faut ajouter le paramètre suivant dans le fichier de config du host (ou dans le template correspondant), soit dans la définition de l’host lui-même, soit dans la définition du service concerné (il faut que le paramètre notifications_enabled soit à 1).
contact_groups support
Si la notification par email est correctement configurée, un mail sera envoyé au déclenchement d’une alerte.