Nagios
Distribution Debian 5.0 / Nagios 3.0.6 :
- Installation Nagios :
apt-get install nagios3 nagios-plugins
- Ajout d'un utilisateur :
htpasswd -c /etc/nagios3/htpasswd.users nagios
- Ajouter droit à l'utilisateur "nagios"
nano/etc/nagios3/cgi.cfg
- Modification des contacts avec ajouts un utilisateur simple :
nano /etc/nagios3/conf.d/contacts_nagios2.cfg
Voici le contenue :
############################################################################### ############################################################################### # # CONTACTS # ############################################################################### ############################################################################### # Just one contact defined by default - the Nagios admin (that's you) # This contact definition inherits a lot of default values from the 'generic-contact' # template which is defined elsewhere. define contact{ contact_name nagios ; Short name of user alias Nagios Admin ; Full name of user service_notification_period 24x7 host_notification_period 24x7 service_notification_options w,u,c,r host_notification_options d,u,r service_notification_commands notify-service-by-email host_notification_commands notify-host-by-email email moi@gergosnet.com ; <<***** CHANGE THIS TO YOUR EMAIL ADDRESS ****** } define contact{ contact_name greg ; Short name of user alias GreG SMS ; Full name of user service_notification_period 24x7 host_notification_period 24x7 service_notification_options c,r host_notification_options d,u,r service_notification_commands notify-service-by-sms host_notification_commands notify-host-by-sms pager 33699887766 } ############################################################################### ############################################################################### # # CONTACT GROUPS # ############################################################################### ############################################################################### # We only have one contact in this simple configuration file, so there is # no need to create more than one contact group. define contactgroup{ contactgroup_name admins alias Nagios Administrators members nagios } define contactgroup{ contactgroup_name utilisateurs alias Utilisateurs Monito members greg }
- Configuration basique d'un pour 2 serveurs/machines :
nano /etc/nagios3/conf.d/maison.cfg
Voici le contenue :
############################################################################### ############################################################################### # # HOST DEFINITION # ############################################################################### ############################################################################### # Define a host for the local machine define host{ use maison ; Name of host template to use host_name perso alias Serveur Perso Maison address 192.168.3.1 } define host{ use maison ; Name of host template to use host_name vifi alias Serveur Routeur Wifi address 192.168.3.2 } ############################################################################### ############################################################################### # # HOST GROUP DEFINITION # ############################################################################### ############################################################################### # Define an optional hostgroup for Linux machines define hostgroup{ hostgroup_name maison ; The name of the hostgroup alias Reseau Maison ; Long name of the group members perso, vifi ; } ############################################################################### ############################################################################### # # HOST TEMPLATES # ############################################################################### ############################################################################### # Linux host definition template - This is NOT a real host, just a template! define host{ name maison ; The name of this host template use generic-host ; This template inherits other values from the generic-host template check_period 24x7 ; By default, Linux hosts are checked round the clock check_interval 5 ; Actively check the host every 5 minutes retry_interval 1 ; Schedule host check retries at 1 minute intervals max_check_attempts 10 ; Check each Linux host 10 times (max) check_command check-host-alive ; Default command to check Linux hosts notification_period 24x7 ; 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! notification_interval 120 ; Resend notifications every 2 hours notification_options d,u,r ; Only send notifications for specific host states contact_groups admins ; Notifications get sent to the admins by default register 0 ; DONT REGISTER THIS DEFINITION - ITS NOT A REAL HOST, JUST A TEMPLATE! } ############################################################################### ############################################################################### # # SERVICE DEFINITIONS # ############################################################################### ############################################################################### # Define a service to "ping" the local machine define service{ use generic-service ; Name of service template to use host_name perso, vifi ; service_description PING check_command check_ping!100.0,20%!500.0,60% }
Vous pouvez maintenant vous connectez à votre Nagios : http://votreserveur.com/nagios3/
- Supervision d'Onduleurs avec NUT
Nagios peut via des plugins surveillé un ou plusieurs onduleurs.
(Pour la configuration de nut rendez-vous : http://wiki.gergosnet.com/index.php/Onduleur )
- Ajout de la commande :
nano /etc/nagios3/commands.cfg
Ajouter à la fin du fichier :
# 'check_ups' command definition define command{ command_name check_ups command_line /usr/lib/nagios/plugins/check_ups -H "$HOSTADDRESS$" -u "$ARG1$" }
Puis pour la supervision de vos onduleurs il suffit d'ajouter après vos hosts :
nano /etc/nagios3/conf.d/maison.cfg
Ajouter :
define service{ use generic-service host_name perso service_description Etat onduleur check_command check_ups!nomdevotreups contact_groups admins }
Si jamais cela ne fonctionne pas, il faut vérifier que NUT est autorisé à répondre de l’extérieure (en cas de machine externe)
- Notifications Nagios par SMS
- Utilisation du service SMS 123-sms.net
Configuration de Nagios Il faut créer une nouvelle commande de notification dans le fichier de configuration …:
pico /etc/nagios3/commands.cfg
Ajouté :
define command{ command_name notify-service-by-sms command_line /usr/bin/printf “%b” “** $NOTIFICATIONTYPE$ alert – $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **” | /usr/bin/mail -s “MOTDEPASSE:$CONTACTPAGER$” sms@123-sms.net }
define command{ command_name notify-host-by-sms command_line /usr/bin/printf “%b” “Host $HOSTSTATE$ alert for $HOSTNAME$!” | /usr/bin/mail -s “MOTDEPASSE:$CONTACTPAGER$” sms@123-sms.net }
avec:
MOTDEPASSE est le mot de passe fournie par votre opérateur de SMS CONTACTPAGER sera automatiquement remplacer par Nagios par le numéro de téléphone portable (PAGER) du contact à prévenir sms@123-sms.net est l’adresse mail du serveur de votre opérateur SMS (le serveur qui va envoyer le SMS sur le réseau GSM) Il ne reste plus qu’a ajouter cette notification aux administrateurs/utilisateurs (par exemple le pauvre gars nommé James qui a comme numéro de téléphone 06007007) que l’on souhaite prévenir:
define contact{ contact_name monadminquivapasdormirdelanuit alias James service_notification_period 24×7 host_notification_period 24×7 service_notification_options w,u,c,r host_notification_options d,u,r service_notification_commands notify-service-by-sms host_notification_commands notify-host-by-sms pager 336007007 }
Et voilà, il ne reste plus qu’a relancer Nagios et attendre les premiers SMS…
- Utilisation de Gammu sur un serveur distant :
Au préalable suivre la procedure pour envoyer des SMS via PHP avec Gammu (et donc le téléphone / clé 3G pour les sms) : http://wiki.gergosnet.com/index.php/Linux/Gammu_SMS
pico /etc/nagios3/commands.cfg
Ajouté :
define command{
command_name notify-host-by-sms command_line /usr/bin/wget -q -O /tmp/sms "http://monserveur.com/sms.php?numeros='$CONTACTPAGER$'&texte=Host '$HOSTSTATE$' alert for '$HOSTNAME$'"
}
define command{
command_name notify-service-by-sms command_line /usr/bin/wget -q -O /tmp/sms "http://perso.gergosnet.com/sms.php?numeros='$CONTACTPAGER$'&texte=** '$NOTIFICATIONTYPE$' alert - '$HOSTALIAS$'/'$SERVICEDESC$' is '$SERVICESTATE$' **"
}