Académique Documents
Professionnel Documents
Culture Documents
30 novembre 2009
Nagios
Nagios, Apache, Fedora
Tp n1
Installation de Nagios Afin dinstaller Nagios il est tout dabord ncessaire dinstaller certains composants : Un serveur web (nous utiliserions Apache) :
yum install httpd
Un compilateur C :
yum install gcc
Compilation et Installation
make all make make make make install install-init install-config install-commandmode
Dans le fichier ci-dessus nous avons paramtr le compte admin comme tant nagiosadmin et les messages derreur seront envoys sur la boite mail root@localhost. Compilation et Installation de linterface Web de Nagios :
make install install-webconf
Redmarrage de Apache :
service httpd restart
Lancement de Nagios :
service nagios start
Configuration des htes Afin de pouvoir ajouter un fichier de configuration supplmentaire Nagios, il faut ajouter une ligne du style suivant :
cfg_file=/usr/local/nagios/etc/objects/gervaisboris.cfg
On utilise le template linux-server tant donn quil sagit exclusivement de machines sous Fedora. use permet de dclarer le template utilis host_name dclare le nom dhte alias lui donne un alias dans Nagios (plus simple utiliser dans certains cas) address prcise lIp de lhte distant
generic-host 1 1 1 1 1 1 1 24x7 0
; ; ; ; ; ; ; ; ;
; The name of this host template Host notifications are enabled Host event handler is enabled Flap detection is enabled Failure prediction is enabled Process performance data Retain status information across program restarts Retain non-status information across program restarts Send host notifications at any time DONT REGISTER THIS DEFINITION - ITS NOT A REAL HOST, JUST A TEMPLATE!
define host{ name use check_period check_interval retry_interval max_check_attempts check_command notification_period notification_interval notification_options contact_groups register }
; The name of this host template ; This template inherits other values from the generic-host template ; By default, Linux hosts are checked round the clock ; Actively check the host every 5 minutes ; Schedule host check retries at 1 minute intervals ; Check each Linux host 10 times (max) ; Default command to check Linux hosts ; Linux admins hate to be woken up, so we only notify during the day ; Note that the notification_period variable is being overridden from ; the value that is inherited from the generic-host template! ; Resend notifications every 2 hours ; Only send notifications for specific host states ; Notifications get sent to the admins by default ; DONT REGISTER THIS DEFINITION - ITS NOT A REAL HOST, JUST A TEMPLATE!
Configuration des groupes Les groupes permettent de rassembler les htes de manire organise. Extrait du fichier groups.cfg :
define hostgroup{ hostgroup_name Linux_1 alias Machines sous Linux (1) members Julien-Bastien, Fabien-Charly hosts that belong to this group } ; The name of the hostgroup ;Long name of the group ; Comma separated list of
define hostgroup{ hostgroup_name Linux_2 ; The name of the hostgroup alias Machines sous Linux (2) ;Long name of the group members localhost, Alexandre-Gael, Alpha-Fiacre, Alexandre-Gael, Fabien-Charly, Julien-Bastien, Prof ; Comma separated list of hosts that belong to this group } define hostgroup{ hostgroup_name Autre alias Autres members Prof hosts that belong to this group } define hostgroup{ hostgroup_name Portables alias Portables sous Windows members MiniNeuf, Tyrael hosts that belong to this group } ; The name of the hostgroup ;Long name of the group ; Comma separated list of
; The name of the hostgroup ; Long name of the group ; Comma separated list of
hostgroup_name dclare le nom du groupe alias permet de dcrire le groupe plus en dtails members incluse les htes appartenant au groupe (chacun spar par une virgule).
L aussi limage t prise par le groupe compos de Julien-Ugo et Bastien ce qui explique la non-correspondance des noms de groupe et des membres.
local-service ; Name of service template to use Alpha-Fiacre, Alexandre-Gael, Fabien-Charly, Julien-Bastien, Prof PING check_ping!100.0,20%!500.0,60%
Lattribut jacky correspond au groupe SNMP. Afin dassurer le bon fonctionnement de NSClient il faut activer le service correspondant. Sur le client Windows il faut paramtrer ladresse du client SNMP (ici notre poste Fedora avec Nagios) ainsi que le groupe, tout ceci ce fait dans le fichier : C:\Program Files\NSClient\NSC.ini
[Settings] ;# OBFUSCATED PASSWORD ; This is the same as the password option but here you can store the password in an obfuscated manner. ; *NOTICE* obfuscation is *NOT* the same as encryption, someone with access to this file can still figure out the ; password. Its just a bit harder to do it at first glance. ;obfuscated_password=Jw0KAUUdXlAAUwASDAAB ; ;# PASSWORD ; This is the password (-s) that is required to access NSClient remotely. If you leave this blank everyone will be able to access the daemon remotly. ;password=secret-password ; ;# ALLOWED HOST ADDRESSES ; This is a comma-delimited list of IP address of hosts that are allowed to talk to the all daemons. ; If leave this blank anyone can access the deamon remotly (NSClient still requires a valid password). ; The syntax is host or ip/mask so 192.168.0.0/24 will allow anyone on that subnet access allowed_hosts=10.153.3.0/24 ; ;# USE THIS FILE ; Use the INI file as opposed to the registry if this is 0 and the use_reg in the registry is set to 1 ; the registry will be used instead. use_file=1 allowed_hosts=10.153.3.81 password=jacky ; ; # USE SHARED MEMORY CHANNELS ; This is the "new" way for using the system tray based on an IPC framework on top shared memmory channels and events. ; It is brand new and (probably has bugs) so dont enable this unless for testing! ; If set to 1 shared channels will be created and system tray icons created and such and such... ;shared_session=0
On autorise les machines du sous rseau 10.153.8.0 /24 ainsi que le serveur en lui-mme et on dclare le mot de passe (groupe SNMP).
On utilise le template local-service pour le PING et generic-service pour tout ce qui concerne Windows.
; ; ; ; ; ;
The name of this service template Inherit default values from the generic-service definition Re-check the service up to 4 times in order to determine its final (hard) state Check the service every 5 minutes under normal conditions Re-check the service every minute until a hard state can be determined DONT REGISTER THIS DEFINITION - ITS NOT A REAL SERVICE, JUST A TEMPLATE!
Configuration des switchs Plugin que nous avons utilis pour tester les interfaces du Switch (Cisco Catalyst 2960) :
#!/bin/sh # Paramtres : # $1 : Adresse Ip de l'adresse de l'hte tester # $2 : Numro de l'interface tester # 1=FastEthernet0, # 2=Serial0, # 3=Serial1, # 4=Null, # Definition des valeurs de retour possibles OK=0 WARNING=1 CRITICAL=2 UNKNOWN=3 # Test de la syntaxe de l'appel du plugin if [ $# -ne 2 ] ; then # Affichage d'un message d'erreur echo "Usage : $0 <host> <interface_number>" echo "" echo "1 = FastEthernet0" echo "2 = Serial0" echo "3 = Serial1" echo "4 = Null" exit $UNKNOWN fi # Requete SNMP retour=`snmpget $1 -c public -v 2c ifOperStatus.$2` # Est-ce que l'interface est UP ? rt=`echo $retour | grep up` # Si elle n'est pas UP : if [ -z "$rt" ] ; then # Est-ce qu'elle est DOWN ? rt=`echo $retour | grep down` # Si elle n'est ni UP ni DOWN : if [ -z "$rt" ] ; then echo "Interface $2 state is UNKNOWN !" exit $UNKNOWN fi # SI elle est DOWN : echo "Interface $2 is DOWN !" exit $CRITICAL fi # Si elle est UP : echo "Interface $2 is UP !" exit $OK
Ci-dessous la configuration de Nagios pour relever les informations du switch : switchs.cfg testant luptime, le PING ainsi que le statuts des interfaces 1 9.
define host{ use host_name alias address hostgroups } define hostgroup{ hostgroup_name alias }
; ; ; ; ;
Inherit default values from a template The name we\'re giving to this switch A longer name associated with the switch IP address of the switch Host groups this switch is associated with
define service{ use host_name service_description check_command } define service{ use host_name service_description check_command normal_check_interval retry_check_interval determined } define service{ use host_name service_description check_command } define service{ use host_name service_description check_command } define service{ use
generic-service ; Inherit values from a template Cisco Catalyst 2960 Uptime check_snmp!-C public -o sysUpTime.0
generic-service ; Inherit values from a template Cisco Catalyst 2960 ; The name of the host the service is associated with PING ; The service description check_ping!200.0,20%!600.0,60% ; The command used to monitor the service 5 ; Check the service every 5 minutes under normal conditions 1 ; Re-check the service every minute until its final/hard state is
generic-service ; Inherit values from a template Cisco Catalyst 2960 Port 1 Link Status check_snmp!-C public -o ifOperStatus.1 -r 1 -m RFC1213-MIB
generic-service ; Inherit values from a template Cisco Catalyst 2960 Port 2 Link Status check_snmp!-C public -o ifOperStatus.2 -r 1 -m RFC1213-MIB
generic-service
host_name service_description check_command } define service{ use host_name service_description check_command } define service{ use host_name service_description check_command } define service{ use host_name service_description check_command } define service{ use host_name service_description check_command } define service{ use host_name service_description check_command } define service{ use host_name service_description check_command }
Cisco Catalyst 2960 Port 3 Link Status check_snmp!-C public -o ifOperStatus.3 -r 1 -m RFC1213-MIB
generic-service ; Inherit values from a template Cisco Catalyst 2960 Port 4 Link Status check_snmp!-C public -o ifOperStatus.4 -r 1 -m RFC1213-MIB
generic-service ; Inherit values from a template Cisco Catalyst 2960 Port 5 Link Status check_snmp!-C public -o ifOperStatus.5 -r 1 -m RFC1213-MIB
generic-service ; Inherit values from a template Cisco Catalyst 2960 Port 6 Link Status check_snmp!-C public -o ifOperStatus.6 -r 1 -m RFC1213-MIB
generic-service ; Inherit values from a template Cisco Catalyst 2960 Port 7 Link Status check_snmp!-C public -o ifOperStatus.7 -r 1 -m RFC1213-MIB
generic-service ; Inherit values from a template Cisco Catalyst 2960 Port 8 Link Status check_snmp!-C public -o ifOperStatus.8 -r 1 -m RFC1213-MIB
generic-service ; Inherit values from a template Cisco Catalyst 2960 Port 9 Link Status check_snmp!-C public -o ifOperStatus.9 -r 1 -m RFC1213-MIB