Tous les articles par jb

Ipfire : Configurer Nagios

Voici la procédure que j’ai suivis pour configurer nagios dans ipfire.nagios dans ipfire

Procédure :

  • Créer l’utilisateur nagios et lui attribuer la propriété sur nagios.

[code lang= »bash »]
useradd nagios -s /bin/false -d /var/nagios
chown nagios: /etc/nagios/*.cfg
chown nagios: /etc/nagios/objects/*.cfg
chown nagios: /var/nagios/ -R
sed -i.bak ‘s/^nagios_user=.*/nagios_user=nagios/’ /etc/nagios/nagios.cfg
sed -i.bak ‘s/^nagios_group=.*/nagios_group=nagios/’ /etc/nagios/nagios.cfg
sed -i.bak ‘s/^NagiosUser=.*/NagiosUser=nagios/’ /etc/init.d/nagios
sed -i.bak ‘s/^NagiosGroup=.*/NagiosGroup=nagios/’ /etc/init.d/nagios
[/code]

  • Configurer son compte utilisateur, modifier /etc/nagios/objects/contacts.cfg

[code lang= »bash »]define contact{
contact_name webmaster; Short name of user
use generic-contact ; Inherit default values from generic-contact template (defined above)
alias webmaster ; Full name of user

email webmaster@jbsky.fr ; <<***** CHANGE THIS TO YOUR EMAIL ADDRESS ******
}
define contactgroup{
contactgroup_name admins
alias Nagios Administrators
members webmaster
}[/code]

  • Modifier le mot de passe:

[code lang= »bash »]htpasswd -c /etc/nagios/htpasswd.users webmaster
[/code]

  • Ajouter la commande dans le fichier /etc/nagios/objects/commands.cfg

[code lang= »bash »]# ‘check_https_ipfire’ command definition
define command{
command_name check_https_ipfire
command_line $USER1$/check_http -S -I $HOSTADDRESS$ $ARG1$ -p 444 -a admin:motdepass
}[/code]

  • Rectifier le service https sur le port 444, chercher check_http dans le fichier cat /etc/nagios/objects/localhost.cfg et le tout remplacer par

[code lang= »bash »]define service{
use local-service ; Name of service template to use
host_name localhost
service_description HTTPS_444
check_command check_https_ipfire
notifications_enabled 0
}[/code]

  • Changer le format de date dans /etc/nagios/nagios.cfg

[code lang= »bash »]
sed -i.bak ‘s/^date_format=.*/date_format=euro/’ /etc/init.d/nagios
[/code]

  • Modifié les commandes de notification dans  /etc/nagios/objects/commands.cfg pour que nagios envoie des mails, ajouter le package sendEmail depuis pakfire.

[code lang= »bash »]
# ‘notify-host-by-email’ command definition
define command{
command_name notify-host-by-email
command_line /usr/bin/printf "%b ***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState: $HOSTSTATE$\nAddress: $HOSTADDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n** " | /usr/local/bin/sendEmail -f agent.nagios@jbsky.fr -t $CONTACTEMAIL$ -u "** $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ ** " -s 10.0.0.4 -xp motdepass -v
}

# ‘notify-host-by-email’ command definition
define command{
command_name host-notify-by-email
command_line /usr/bin/printf "%b ***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState: $HOSTSTATE$\nAddress: $HOSTADDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n** " | /usr/local/bin/sendEmail -f agent.nagios@jbsky.fr -t $CONTACTEMAIL$ -u "** $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ ** " -s 10.0.0.4 -xp motdepass -v
}

# ‘notify-service-by-email’ command definition
define command{
command_name notify-service-by-email
command_line /usr/bin/printf "%b ***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\n\nService: $SERVICEDESC$\nHost: $HOSTALIAS$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\n\nDate/Time: $LONGDATETIME$\n\nAdditional Info:\n\n$SERVICEOUTPUT$" | /usr/local/bin/sendEmail -f agent.nagios@jbsky.fr -t $CONTACTEMAIL$ -u "** $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" -s 10.0.0.4 -xp motdepass -v

}

# ‘notify-service-by-email’ command definition
define command{
command_name service-notify-by-email
command_line /usr/bin/printf "%b ***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\n\nService: $SERVICEDESC$\nHost: $HOSTALIAS$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\n\nDate/Time: $LONGDATETIME$\n\nAdditional Info:\n\n$SERVICEOUTPUT$" | /usr/local/bin/sendEmail -f agent.nagios@jbsky.fr -t $CONTACTEMAIL$ -u "** $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" -s 10.0.0.4 -xp motdepass -v
}
[/code]

  • Recharger Nagios:

[code lang= »bash »]/etc/init.d/nagios reload[/code]

  1. Application Iphone intéressante:

TM-Lite
Fournir l’URL complète: http://IP:1008/nagios/cgi-bin

SPLIT

Retourne une partie de 1 à n; Si n> nombre de partie, renvoie null;
Autre source: http://blog.fedecarg.com/2009/02/22/mysql-split-string-function/
La fonction que je propose est moins performante 🙁 que le lien ci-dessus.
[code lang= »sql »]
DROP FUNCTION IF EXISTS SPLIT;
DELIMITER $$;
CREATE FUNCTION `SPLIT`( _text TEXT,_lim VARCHAR(255), _part INTEGER ) RETURNS text CHARSET utf8 COLLATE utf8_unicode_ci
BEGIN
DECLARE _substring TEXT;
DECLARE _index INTEGER ;
DECLARE _len_index INTEGER;
DECLARE _len_substring INTEGER;
DECLARE _len_lim INTEGER ;
set _part=_part-1;
set _len_lim=char_length(_lim)+1;
SET _len_index = LENGTH(_text) – LENGTH(REPLACE(_text, _lim,  »));
SET _index=0;

_indexwhile: WHILE _index <= _len_index DO
set _substring= SUBSTRING_INDEX(_text,_lim,1);
if( _part=_index) then
RETURN _substring;
END IF;
set _len_substring= char_length(_substring);
set _text=SUBSTR(_text,_len_substring+_len_lim,char_length(_text)-_len_substring);
SET _index = _index + 1;
END WHILE _indexwhile;
RETURN NULL;
END
[/code]

Pour la tester avec une procédure stocké:

[code lang= »sql »]DROP PROCEDURE IF EXISTS READ_SPLIT;
DELIMITER $$;
CREATE PROCEDURE `READ_SPLIT`( _text TEXT, _lim VARCHAR(255))
BEGIN
DECLARE _index INTEGER ;
DECLARE _len_index INTEGER;
SET _len_index = 1 + LENGTH(_text) – LENGTH(REPLACE(_text, _lim,  »));
SET _index=1;
CREATE TABLE IF NOT EXISTS RESULT(_text_result TEXT);
_indexwhile: WHILE _index <= _len_index DO
INSERT INTO RESULT ( _text_result) SELECT SPLIT(_text,_lim,_index);
SET _index = _index + 1;
END WHILE _indexwhile;
SELECT * FROM RESULT;
DROP TABLE RESULT;
END
[/code]
[code lang= »sql »]CALL READ_SPLIT("Hello World, this is a split function," ");
[/code]
Pour pousser l’histoire:
[code lang= »sql »]DROP PROCEDURE IF EXISTS LOOP_READ_SPLIT;
DELIMITER $$;
CREATE PROCEDURE `LOOP_READ_SPLIT`( _text TEXT, _lim VARCHAR(255),_len_index INTEGER)
BEGIN
DECLARE _index INTEGER ;
SET _index=1;
_indexwhile: WHILE _index <= _len_index DO
CALL READ_SPLIT(_text,_lim);
SET _index = _index + 1;
END WHILE _indexwhile;
END
[/code]
[code lang= »sql »]CALL LOOP_READ_SPLIT("Hello World, this is a split function," ",100);
[/code]