tech:exemple_simple_de_conf_nagios
Différences
Ci-dessous, les différences entre deux révisions de la page.
| Les deux révisions précédentesRévision précédente | |||
| tech:exemple_simple_de_conf_nagios [2026/01/22 17:06] – Jean-Baptiste | tech:exemple_simple_de_conf_nagios [2026/01/22 17:06] (Version actuelle) – Jean-Baptiste | ||
|---|---|---|---|
| Ligne 1: | Ligne 1: | ||
| + | < | ||
| + | {{tag> | ||
| + | |||
| + | # Exemple simple de conf Nagios | ||
| + | |||
| + | Voir : | ||
| + | * https:// | ||
| + | * https:// | ||
| + | * https:// | ||
| + | |||
| + | Voir aussi : | ||
| + | * https:// | ||
| + | |||
| + | |||
| + | ## Arborescence proposée | ||
| + | |||
| + | |||
| + | Le fichier de conf principal appelant tous les autres : | ||
| + | * etc/ | ||
| + | * Voir https:// | ||
| + | |||
| + | Fichier contenant les commandes à exécuter : | ||
| + | * etc/ | ||
| + | |||
| + | Ce fichier ne doit pas contenir de mot de passe. | ||
| + | |||
| + | Le fichier contenant les mots de passe utilisés par commands.cfg : | ||
| + | * etc/ | ||
| + | |||
| + | Ce fichier ne devrait être en lecture que pour l' | ||
| + | |||
| + | |||
| + | Fichiers de conf basiques modifiés peu souvent : | ||
| + | * etc/ | ||
| + | * etc/ | ||
| + | * etc/ | ||
| + | * etc/ | ||
| + | |||
| + | |||
| + | |||
| + | Fichier de conf contenant la liste des hôtes à superviser : | ||
| + | * etc/ | ||
| + | |||
| + | Il est possible d' | ||
| + | |||
| + | Le nom des fichiers cfg est libre, mais ils doivent être appelés par nagios.cfg | ||
| + | |||
| + | |||
| + | ## Exemple de conf | ||
| + | |||
| + | ### Fichier de conf principal nagios.cfg | ||
| + | |||
| + | Extrait | ||
| + | |||
| + | `nagios.cfg` | ||
| + | ~~~bash | ||
| + | # | ||
| + | # | ||
| + | # | ||
| + | # | ||
| + | # | ||
| + | # | ||
| + | # | ||
| + | # | ||
| + | |||
| + | cfg_dir=/ | ||
| + | resource_file=/ | ||
| + | |||
| + | nagios_user=nagios | ||
| + | nagios_group=nagios | ||
| + | |||
| + | check_external_commands=1 | ||
| + | max_concurrent_checks=0 | ||
| + | retain_state_information=0 | ||
| + | enable_flap_detection=1 | ||
| + | |||
| + | date_format=iso8601 | ||
| + | |||
| + | use_syslog=1 | ||
| + | log_file=/ | ||
| + | debug_level=0 | ||
| + | debug_file=/ | ||
| + | ~~~ | ||
| + | |||
| + | |||
| + | |||
| + | ### Fichier commands.cfg | ||
| + | |||
| + | `commands.cfg` | ||
| + | |||
| + | ~~~c | ||
| + | define command { | ||
| + | command_name | ||
| + | command_line | ||
| + | } | ||
| + | |||
| + | define command { | ||
| + | command_name | ||
| + | command_line | ||
| + | } | ||
| + | |||
| + | define command { | ||
| + | command_name | ||
| + | command_line | ||
| + | } | ||
| + | |||
| + | |||
| + | # NOTE: The following ' | ||
| + | # various metrics on the host that Nagios is running on (i.e. this one). | ||
| + | define command { | ||
| + | command_name | ||
| + | command_line | ||
| + | } | ||
| + | |||
| + | define command { | ||
| + | command_name | ||
| + | command_line | ||
| + | } | ||
| + | |||
| + | #define command { | ||
| + | # command_name | ||
| + | # command_line | ||
| + | #} | ||
| + | |||
| + | #define command { | ||
| + | # command_name | ||
| + | # command_line | ||
| + | #} | ||
| + | ~~~ | ||
| + | |||
| + | Ce fichier contient les commandes qui seront exécutées. | ||
| + | |||
| + | Tous les scripts ne renvoyant que des données locales (de localhost), et donc ne contenant pas '' | ||
| + | |||
| + | Seul le fichier `localhost.cfg` devrait faire appel aux commandes " | ||
| + | |||
| + | |||
| + | ### Fichier contenant les Templates | ||
| + | |||
| + | `templates.cfg` | ||
| + | ~~~c | ||
| + | define contact { | ||
| + | name generic-contact | ||
| + | service_notification_period | ||
| + | host_notification_period | ||
| + | service_notification_options | ||
| + | host_notification_options | ||
| + | service_notification_commands | ||
| + | host_notification_commands | ||
| + | register | ||
| + | } | ||
| + | |||
| + | # Generic host definition template - This is NOT a real host, just a template! | ||
| + | define host { | ||
| + | name generic-host | ||
| + | notifications_enabled | ||
| + | event_handler_enabled | ||
| + | flap_detection_enabled | ||
| + | failure_prediction_enabled | ||
| + | process_perf_data | ||
| + | retain_status_information | ||
| + | retain_nonstatus_information | ||
| + | notification_period | ||
| + | register | ||
| + | } | ||
| + | |||
| + | define host { | ||
| + | name linux-server | ||
| + | use | ||
| + | check_period | ||
| + | check_interval | ||
| + | retry_interval | ||
| + | max_check_attempts | ||
| + | check_command | ||
| + | notification_period | ||
| + | ; Note that the notification_period variable is being overridden from | ||
| + | ; the value that is inherited from the generic-host template! | ||
| + | notification_interval | ||
| + | notification_options | ||
| + | contact_groups | ||
| + | register | ||
| + | } | ||
| + | |||
| + | # Custom | ||
| + | define host { | ||
| + | name tpl-host-linux | ||
| + | use | ||
| + | hostgroups | ||
| + | register | ||
| + | } | ||
| + | |||
| + | |||
| + | define service { | ||
| + | name generic-service | ||
| + | active_checks_enabled | ||
| + | passive_checks_enabled | ||
| + | parallelize_check | ||
| + | obsess_over_service | ||
| + | check_freshness | ||
| + | notifications_enabled | ||
| + | event_handler_enabled | ||
| + | flap_detection_enabled | ||
| + | failure_prediction_enabled | ||
| + | process_perf_data | ||
| + | retain_status_information | ||
| + | retain_nonstatus_information | ||
| + | is_volatile | ||
| + | check_period | ||
| + | max_check_attempts | ||
| + | normal_check_interval | ||
| + | retry_check_interval | ||
| + | contact_groups | ||
| + | notification_options | ||
| + | notification_interval | ||
| + | notification_period | ||
| + | register | ||
| + | } | ||
| + | |||
| + | # Local service definition template - This is NOT a real service, just a template! | ||
| + | define service { | ||
| + | name local-service | ||
| + | use | ||
| + | max_check_attempts | ||
| + | normal_check_interval | ||
| + | retry_check_interval | ||
| + | register | ||
| + | } | ||
| + | |||
| + | # Custom | ||
| + | define service { | ||
| + | name tpl-service-mca1 | ||
| + | max_check_attempts | ||
| + | normal_check_interval | ||
| + | retry_check_interval | ||
| + | check_period | ||
| + | notification_interval | ||
| + | notification_period | ||
| + | notification_options | ||
| + | contact_groups | ||
| + | register | ||
| + | } | ||
| + | |||
| + | ~~~ | ||
| + | |||
| + | Ce fichier devrait être dédié aux Templates. Chaque bloque devrait contenir '' | ||
| + | |||
| + | Pour utiliser un template il faut utiliser la directive " | ||
| + | |||
| + | Pour tous les nouveaux objets templates, nous recommandons pour une meilleurs lisibilité de leurs appliquer une convention de nommage spécifique. | ||
| + | Par exemple en les préfixant par " | ||
| + | |||
| + | |||
| + | ### Passons rapidement sur timeperiods.cfg & contacts.cfg | ||
| + | |||
| + | `timeperiods.cfg` | ||
| + | ~~~c | ||
| + | # This defines a timeperiod where all times are valid for checks, | ||
| + | # notifications, | ||
| + | define timeperiod { | ||
| + | timeperiod_name | ||
| + | alias 24 Hours A Day, 7 Days A Week | ||
| + | sunday | ||
| + | monday | ||
| + | tuesday | ||
| + | wednesday | ||
| + | thursday | ||
| + | friday | ||
| + | saturday | ||
| + | } | ||
| + | |||
| + | # ' | ||
| + | define timeperiod { | ||
| + | timeperiod_name | ||
| + | alias Normal Work Hours | ||
| + | monday | ||
| + | tuesday | ||
| + | wednesday | ||
| + | thursday | ||
| + | friday | ||
| + | } | ||
| + | ~~~ | ||
| + | |||
| + | `contacts.cfg` | ||
| + | ~~~c | ||
| + | define contact { | ||
| + | contact_name | ||
| + | use | ||
| + | alias | ||
| + | email | ||
| + | } | ||
| + | |||
| + | |||
| + | define contactgroup { | ||
| + | contactgroup_name | ||
| + | alias | ||
| + | members | ||
| + | } | ||
| + | ~~~ | ||
| + | |||
| + | Notez ici la directive " | ||
| + | |||
| + | |||
| + | |||
| + | |||
| + | ### Fichier localhost.cfg | ||
| + | |||
| + | `localhost.cfg` | ||
| + | ~~~c | ||
| + | define host { | ||
| + | use | ||
| + | ; This host definition will inherit all variables that are defined | ||
| + | ; in (or inherited by) the linux-server host template definition. | ||
| + | host_name | ||
| + | alias | ||
| + | address | ||
| + | } | ||
| + | |||
| + | |||
| + | define hostgroup { | ||
| + | hostgroup_name | ||
| + | alias Linux Servers | ||
| + | members | ||
| + | } | ||
| + | |||
| + | |||
| + | define service { | ||
| + | use | ||
| + | host_name | ||
| + | service_description | ||
| + | check_command | ||
| + | } | ||
| + | |||
| + | ~~~ | ||
| + | |||
| + | Toutes les commandes présentent dans ce fichier devraient avoir pour check_command " | ||
| + | Voir `commands.cfg` | ||
| + | |||
| + | |||
| + | ### Fichier servers.cfg | ||
| + | |||
| + | `servers.cfg` | ||
| + | ~~~c | ||
| + | define host { | ||
| + | host_name | ||
| + | use | ||
| + | alias srv01 | ||
| + | } | ||
| + | |||
| + | define host { | ||
| + | host_name | ||
| + | use | ||
| + | alias srv01 | ||
| + | } | ||
| + | |||
| + | |||
| + | define hostgroup { | ||
| + | hostgroup_name | ||
| + | alias Linux Servers | ||
| + | } | ||
| + | |||
| + | define hostgroup { | ||
| + | hostgroup_name | ||
| + | alias | ||
| + | members | ||
| + | } | ||
| + | |||
| + | define hostgroup { | ||
| + | hostgroup_name | ||
| + | alias | ||
| + | # hostgroup_members | ||
| + | hostgroup_members | ||
| + | } | ||
| + | |||
| + | |||
| + | define service { | ||
| + | service_description | ||
| + | use | ||
| + | hostgroup_name | ||
| + | check_command | ||
| + | # event_handler | ||
| + | } | ||
| + | ~~~ | ||
| + | |||
| + | |||
| + | Notez que un hostgroup peut inclure des hôtes avec `members` | ||
| + | |||
| + | ou d' | ||
| + | |||
| + | Souvent on préférera utliser les templates à l'aide de la directive " | ||
| + | |||
| + | |||
| + | ## Vérification de la conf | ||
| + | |||
| + | ### Vérif | ||
| + | |||
| + | ~~~bash | ||
| + | / | ||
| + | ~~~ | ||
| + | |||
| + | ### Commandes | ||
| + | |||
| + | Trouver les commandes non utilisées | ||
| + | ~~~bash | ||
| + | for CMD in $(grep command_name etc/ | ||
| + | ~~~ | ||
| + | |||
| + | Trouver les commandes en double | ||
| + | ~~~bash | ||
| + | diff <(grep -v ^# etc/ | ||
| + | ~~~ | ||
| + | |||
| + | |||
| + | #### Sondes locales | ||
| + | |||
| + | |||
| + | Toutes les sondes locales (qui remonte des infos du host sur lequel le script est exécuté) devraient avoir un '' | ||
| + | |||
| + | Sauf exception seules les fichiers suivants devraient contenir ce motif | ||
| + | ~~~ | ||
| + | $ rgrep -l check_local_ * | ||
| + | objects/ | ||
| + | objects/ | ||
| + | ~~~ | ||
| + | |||
| + | |||
| + | |||
| + | |||
| + | Même chose avec les '' | ||
| + | |||
| + | ~~~ | ||
| + | $ rgrep -l local-service * | ||
| + | objects/ | ||
| + | objects/ | ||
| + | ~~~ | ||
| + | |||
| + | |||
| + | ### templates.cfg | ||
| + | |||
| + | * Tous les bloques de code '' | ||
| + | * Tous les bloques de code présent dans le fichier templates.cfg devrait avoir '' | ||
| + | |||
| + | |||
| + | ### Autres conditions | ||
| + | |||
| + | * Pour toute directive " | ||
| + | * Pour chaque " | ||
| + | * Tous les noms indiqués par la directive " | ||
| + | |||
