PROJET AUTOBLOG


Planet-Libre

source: Planet-Libre

⇐ retour index

Slobberbone : check_file_content : Plugin Nagios tout terrain pour consulter le contenu d'un fichier

lundi 18 mars 2013 à 23:20

Présentation

Ce projet est un projet sous licence GPL v2. Cette commande est un plugin pour Nagios 3.x, développé en PERL et oui, on prend les mêmes et on recommence ;) )

Son objectif est de permettre de consulter un fichier local ou sur le réseau et de retourner des alertes selon la présence ou non d'une suite de mots passés en paramètre. Dans un premier temps, le plugin ne prend en compte que le protocol samba, mais ça ne devrait pas être compliqué d'en intégrer d'autres.

Ce plugin permet de :

Pour le reste, je vous laisse parcourir le fichier, tout doit être dedans ;)  et assez explicite ! Sinon, vous savez où me trouver ;)

Installation

Vous l'aurez compris, pour l'utiliser, il suffit d'un serveur Nagios (Installer Nagios sur CentOS sans RPM) sur lequel vous aurez installé les packages suivant :

# yum install perl perl-Filesys-SmbClient

Une fois fais, il ne vous reste qu'à placer check_file_content.pl dans le répertoire libexec de votre arborescence Nagios :

# chmod +x check_file_content.pl

Et voilà, le tour est joué !

$ perl check_file_content.pl --help

Check_file_content for Nagios, version 1.0
GPL licence, (c)2013 Slobberbone

Site http://www.slobberbone.net

Usage: check_file_content.pl -f -P [-u -p -d ] -s <"search_expression"> -t [-w -c ] -V
-h, --help
print this help message
-f, --filepath=PATHTOFILENAME
full path to file to analyze
-P, --protocol=PROTOCOL
protocol used to acess file :
LOCAL for local file (default),
SMB for CIFS file
-u, --user=USER
user to login
-p, --password=PASSWORD
password
-d, --domain=DOMAIN
domain name
-s, --search="EXPRESSION", if empty looks for lines present in the file
expression to search in the specified file
-t, --check_type=TYPE
Type of search :
INCLUDE for include at least the critical option, then the warning option
EXCLUDE for exclude with a maximum of founded expression smaller than critical option
-w, --warn=INTEGER
number that will cause a warning
-c, --critical=INTEGER
number that will cause an error (Default: 1)
-V, --version
prints version number
Note :
The script will return
* With warn and critical options:
OK if we are able to found expression and the count result respect and depending check_type,
WARNING if we are able to found expression and the count result unrespect and depending check_type,
CRITICAL if we are able to found expression and the count result unrespect and depending check_type,
UNKNOWN if we aren't able to read the file

Configuration

Pour que ce plugin soit opérationnel avec notre serveur de supervision Nagios (ou Shinken), il faut ajouter dans le fichier commands.cfg :

# 'check_file_content' command definition
define command{
    command_name    check_file_content
    command_line    $USER1$/check_file_content.pl -f $ARG1$ -P $ARG2$ -u $ARG3$ -p $ARG4$ -d $ARG5$ -t $ARG6$ -s $ARG7$ -w $ARG8$ -c $ARG9$
    }

Puis, il ne vous reste plus qu'à l'appeler de la manière suivante :

define service{
    use            generic-service
    host_name        my_file_server
    service_description    Include at least 4 instances of "Provider : OK" in mytest.log
    check_command        check_file_content!smb://server/dir/file.log!SMB!user!password!domain!INCLUDE!"Provider : OK"!5!3
    normal_check_interval    10
}

Et voilà, il ne reste plus qu'à modifier ce projet pour vos propres besoins ! Pour ça, direction SourceForge.net !

Si vous avez des questions, les commentaires sont ouverts !

Gravatar de Slobberbone
Original post of Slobberbone.Votez pour ce billet sur Planet Libre.