Salut à tous,
J’ai un petit problème pour un script que j’essaye d’améliorer. j’ai ajouter des options à mon script via un ‘case’ pour que cela fasse plus propre, mais je me rend compte que l’options du nom de communauté de la commande ‘snmpwalk’ que j’invoque dans mon script est vide.
j’ai par ailleurs remarqué lorsque j’utilise la commande que le nom de communauté est toujours vide (e.g. ps -ax):
/usr/bin/snmpwalk -v 2c -c ip_address .1.3.6.1.4.1.334.72.1.1.2
Est-ce lié ?
De plus j’ai beau chercher je ne trouve pas de script bash sur le net qui utiliserai “snmpwalk”, y’a bien la solution d’écrire tout en Perl mais ceci est mon premier gros script et je métrise encore moins le Perl.
Enfin je post à tout hasard si jamais quelqu’un a déjà rencontré le problème.
#! /bin/bash
#########################################################################################
#
# Author: Ludo
# Date: 2008.01.11
#########################################################################################
PROGNAME="check_AV_update.sh"
VERSION="1.0"
AUTHOR="(c) 2008 Ludo"
LASTCHANGE="2008.02.18"
# EXIT CODE
STATE_OK=0
STATE_WARNING=1
STATE_CRITICAL=2
STATE_UNKNOWN=3
STATE_DEPENDENT=4
# COMMANDS
CAT=/bin/cat
GREP=/bin/grep
CUT=/bin/cut
SED=/bin/sed
AWK=/usr/bin/awk
ECHO=/bin/echo
LS=/bin/ls
PATH_TMP=/tmp
SNMP=/usr/bin/snmpwalk
# HELP AND USAGE
print_version() {
$ECHO ""
$ECHO "------------------------------------------------------------------------------------"
$ECHO "$PROGNAME - V$VERSION, by $AUTHOR - Last Modification: $LASTCHANGE"
$ECHO "------------------------------------------------------------------------------------"
$ECHO ""
}
print_usage() {
$ECHO ""
$ECHO ""
$ECHO "Usage: $PROGNAME [-h|-V] | --com=<public> --hostaddress=<ip_address> -w <warning_value> -c <critical_value>"; $ECHO ""
$ECHO " -h, --help"; $ECHO "print the help message and exit"
$ECHO " -V"; $ECHO "print version and exit"
$ECHO " --hostaddress=*"; $ECHO "Host Address"
$ECHO " --com=*"; $ECHO "community name"
$ECHO " -w n"; $ECHO "warning day for database age"
$ECHO " -c n"; $ECHO "critical day for database age"
$ECHO ""
$ECHO ""
}
print_help() {
print_version
$ECHO ""
$ECHO "Plugin for Nagios to check the LNSNMP OID for AV datatbase age"
$ECHO ""
print_usage
$ECHO ""
}
# Make sure the correct argument have been supplied
if [[ ! `$ECHO "$*" | $GREP -E "(-[hVwc]\>|--(help|com|hostaddress)=)"` ]]; then
print_usage
exit $STATE_UNKNOWN
fi
# grab the command line arguments
thresh_warn=""
thresh_crit=""
hostaddress=""
com=""
while test -n "$1"; do
case "$1" in
--help)
print_help
exit $STATE_OK
;;
-h)
print_help
exit $STATE_OK
;;
-V)
print_version
exit $STATE_OK
;;
--com=*)
com=`$ECHO $2 | cut -d= -f2`
shift
;;
--hostaddress=*)
hostaddress=`$ECHO $1 | cut -d= -f2`
# if [[ `expr match "$hostaddress" '\[0-9]*.[0-9]*.[0-9]*.[0-9]*\'` != $hostaddress ]] || [ -z $hostaddress ]; then
# $ECHO "The address ip is not valid"
# exit $STATE_UNKNOWN
# fi
shift
;;
-w)
thresh_warn=$2
# if [[ `expr match "$thresh_warn" '\([0-9]*\)'` != $thresh_warn ]] || [ -z $thresh_warn ]; then
# $ECHO "Warning value must be a number greater than zero"
# exit $STATE_UNKNOWN
# fi
shift
;;
-c)
thresh_crit=$2
# if [[ `expr match "$thresh_warn" '\([0-9]*\)'` != $thresh_warn ]] || [ -z $thresh_warn ]; then
# $ECHO "Criticale value must be a number greater than zero"
# exit $STATE_UNKNOWN
# fi
shift
;;
*)
$ECHO "UNKNOW argument: $1"
print_usage
exit $STATE_UNKNOWN
;;
esac
shift
done
$ECHO ------------------------
$ECHO $hostaddress
$ECHO $com
$ECHO $thresh_warn
$ECHO $thresh_crit
$ECHO ------------------------
###########
# VARIABLES
###########
NOW=$(date +%c | $CUT -d\ -f1-5)
CHECK=/usr/bin/check_lnsmp_Mibs.sh
NOTES_MIBS=.1.3.6.1.4.1.334
NOTES_MIBS_START=.1.3.6.1.4.1.334.72.1.1.3
NOTES_MIBS_START_NAME=NOTES-MIB::lnStatsCurrentTime.0
NAME_AGE=SAV.Current.Definitions.Age
NAME_DATE=SAV.Current.Definitions.Date
#####################
# Check if file exist
#####################
FILE=$($LS $PATH_TMP/tmp_Nagios-$hostaddress-result.lnsnmp)
if [[ $FILE == "" ]];
then
$CHECK hostname $hostaddress
fi
# DEBUG
#$ECHO -------
#$ECHO $FILE
#$ECHO -------
# DEBUG
#####################
# assign value to VAR
#####################
DATE_MIB_FILE=$($CAT /tmp/tmp_Nagios-$hostaddress-result.lnsnmp | grep $NOTES_MIBS_START_NAME | $CUT -d\ -f4 )
DATE_MIB_SNMP=$($SNMP -v 2c -c $com $hostaddress $NOTES_MIBS_START | $CUT -d\ -f4)
#$ECHO --------
#$ECHO $DATE_MIB_FILE
#$ECHO $DATE_MIB_SNMP
#$ECHO --------
########################
# Verify the date of mib
########################
if [[ $DATE_MIB_FILE == "" ]];
then
$CHECK hostname $hostaddress
elif [[ $DATE_MIB_FILE != $DATE_MIB_SNMP ]];
then
$CHECK hostname $hostaddress
fi
##################################
# Assign Value to ask the good OID
##################################
SNMP_DMAJ=$($CAT $PATH_TMP/tmp_Nagios-$hostaddress-result.lnsnmp | $GREP -i $NAME_AGE | $CUT -d\ -f1)
SNMP_IMAJ=$($CAT $PATH_TMP/tmp_Nagios-$hostaddress-result.lnsnmp | $GREP -i $NAME_DATE | $CUT -d\ -f1)
DMAJ=$($SNMP -v 2c -c $com $hostaddress $SNMP_DMAJ | $CUT -d\ -f6 | $CUT -d\" -f1)
IMAJ=$($SNMP -v 2c -c $com $hostaddress $SNMP_IMAJ | $CUT -d\ -f6 | $CUT -d\" -f1)
#$ECHO ------
#$ECHO $DMAJ
#$ECHO $SNMP_DMAJ
#$ECHO $IMAJ
#$ECHO $SNMP_IMAJ
#$ECHO ------
#################################################################################
# check if the result is not null and verify the age of the Malaware/AV database.
#################################################################################
if [[ $DMAJ > $thresh_warn ]];
then
echo "$NOW :$($ECHO "The last update:" $IMAJ | $CUT -d= -f1-3) : WARNING"
exit $STATE_WARNING
elif [[ $DMAJ = "" ]] ;
then
echo "$NOW : No response from this host"
exit $STATE_UNKNOWN
elif [[ $DMAJ > $thresh_crit ]];
then
echo "$NOW :$($ECHO "The last update:" $IMAJ | $CUT -d= -f1-3) : CRITICAL"
exit $STATE_CRITICAL
elif [[ $DMAJ < $thresh_warn ]];
then
echo "$NOW :$($ECHO "The last update:" $IMAJ | $CUT -d= -f1-3) : OK"
exit $STATE_OK
fi
Merci de vos lecture
p.s.: La variable $CHECK qui pointe vers le programme check_lnmp_Mibs.sh est juste un script qui lance une requête snmpwalk sur l’OIDs Lotus et l’envoi vers un fichier
p.s. 2: Si vous avez des avis ou remarque je suis toutes ouies ^^