PDA

View Full Version : Imprimante : encre etc...


seb974
07-23-2007, 09:43 AM
Bonjour !

J'aimerais dévelloper un plugin (si ça existe pas) en perl ou en bash pour avoir le niveau d'encre d'une imprimante (pour mon cas : OfficeJet 7310).

Mais je suis débutant en perl/bash et de plus, je ne sais pas à quoi correspondent exactement les MIB de mon imprimante (voir fichier texte ci-joint) :

Je voudrais savoir quel OID interroger pour avoir le niveau de l'encre ou son état : ex si niveau encre faible : warning, cartouche vide : critical.

Bien sûr s'il y a des moyens encore plus simple je suis tout ouie :)

Merci pour vos réponses !

MrBrown
07-23-2007, 10:55 AM
Il y a une MIB générique pour les imprimantes que tu peux interroger, l'OID est 1.3.6.1.2.1.43 je crois. Si tu ne trouves pas d'informations sur cette mib, tu dois passer par la MIB spécifique à ton imprimante. Tu peux faire des requêtes SNMP avec la libraire Net-SNMP pour perl.

julien60
07-23-2007, 11:22 AM
Il y a déja un plugin de developpé pour le niveau des toners et qui interroge la mib standard des imprimantes. Il s'appelle check_printer_toner je le met en piece jointe. Tu peux t'en inspirer!

DonKiShoot
07-23-2007, 12:06 PM
regarde dans ce forum, jigot a déja ecrit un plugin pour les imprimantes

http://forum.oreon-project.org/showthread.php?t=1318&highlight=imprimante+oid

seb974
07-23-2007, 01:09 PM
@Julien60 :

J'ai cette erreur lorsque j'éxécute :

bash: ./check_printer_toner.sh: /bin/bash^M: bad interpreter: Aucun fichier ou répertoire de ce type

@DonKiShoot :

J'ai vu ce post, mais ça à l'air de ne pas fonctionner :s

---

SInon, j'ai trouvé ce plugin :

#!/bin/sh

HOSTIP=$1
COMMUNITY=$2

SNMPGET="/usr/bin/snmpget"
SNMPWALK="/usr/bin/snmpwalk"

function fmodel(){

MODEL=`$SNMPGET -v 1 -c $COMMUNITY $HOSTIP host.hrDevice.hrDeviceTable.hrDeviceEntry.hrDevice Descr.1 2>/dev/null|cut -d " " -f4-`
echo $MODEL
exit 0
}
function fmessages(){
MESSAGES=`$SNMPWALK -v1 -c $COMMUNITY $HOSTIP 1.3.6.1.2.1.43.18.1.1.8|cut -d " " -f4- |tr -d "\""|tr -d "\n"`
echo $MESSAGES
exit 0
}


function fpagecount(){

PC=`$SNMPGET -v 1 -c $COMMUNITY $HOSTIP 1.3.6.1.2.1.43.10.2.1.4.1.1 2>/dev/null|cut -d " " -f4-`
echo "OK Pagecount is $PC|Pages=$PC;;;"
exit 0
}


function fconsumables(){

##testfrage

if [ "$1" = "TEST" ]
then
echo -e "Consumables you may Monitor:"
$SNMPWALK -v1 -c $COMMUNITY $HOSTIP 1.3.6.1.2.1.43.11.1.1.6.1 2>/dev/null |cut -d " " -f4-
#echo -e $OUTPUT
exit 0
else


###massenabfrage

if [ "$1" = "ALL" ]
then

EXITCODE=0
EXITSTRING=''
PERFDAT=''
for ID in `$SNMPWALK -v1 -c $COMMUNITY $HOSTIP 1.3.6.1.2.1.43.11.1.1.6.1 2>/dev/null |egrep -oe '[[:digit:]]+\ ='|cut -d " " -f1`
do
NAME=`$SNMPGET -v1 -c $COMMUNITY $HOSTIP 1.3.6.1.2.1.43.11.1.1.6.1.$ID 2>/dev/null |cut -d " " -f4- |tr -d "\""`
if [ -z "$NAME" ]
then
echo "Error OID not found,maybe your Printer does not support checking this device, call me with Option CONSUM TEST or see help"
exit 3
fi

STATUS=`$SNMPGET -v1 -c $COMMUNITY $HOSTIP 1.3.6.1.2.1.43.11.1.1.9.1.$ID 2>/dev/null |cut -d " " -f4- |tr -d "\""`
FULL=`$SNMPGET -v1 -c $COMMUNITY $HOSTIP 1.3.6.1.2.1.43.11.1.1.8.1.$ID 2>/dev/null |cut -d " " -f4- |tr -d "\""`


####debug
#echo found $ID with name $NAME , full state: $FULL , actual state: $STATUS

if [ "$FULL" -gt 0 ] && [ "$STATUS" -gt 0 ]
then
let "STATUS= $STATUS * 100 / $FULL"
if [ "$STATUS" -gt "30" ]
then
EXITSTRING="$EXITSTRING OK,$NAME is at $STATUS%"
PERFDAT="$PERFDAT $NAME=$STATUS;;$FULL;"
else
if [ "$STATUS" -lt "30" ] && [ "$STATUS" -gt "10" ]
then
EXITSTRING="$EXITSTRING, WARNING,$NAME is at $STATUS%"
PERFDAT="$PERFDAT $NAME=$STATUS;;$FULL;"
if [ "$EXITCODE" -lt 1 ]
then
EXITCODE=1
fi

else
if [ "$STATUS" -lt "10" ]
then
EXITSTRING="$EXITSTRING CRITICAL,$NAME is at $STATUS%"
PERFDAT="$PERFDAT $NAME=$STATUS;;$FULL;"
EXITCODE=2
fi
fi
fi

else
if [ "$STATUS" = "-3" ]
then
EXITSTRING="$EXITSTRING OK,$NAME is FULL"
else
if [ "$STATUS" = "-2" ]
then
EXITSTRING="$EXITSTRING WARNING,$NAME is at WARNING Level"
if [ "$EXITCODE" -lt 1 ]
then
EXITCODE=1
fi
else
if [ "$STATUS" = "0" ]
then
EXITSTRING="$EXITSTRING CRITICAL,$NAME is at CRITICAL Level"
EXITCODE=2
fi
fi
fi

fi

done
echo "$EXITSTRING|$PERFDAT"
exit $EXITCODE





###einzelne abfrage
else
ID=`$SNMPWALK -v1 -c $COMMUNITY $HOSTIP 1.3.6.1.2.1.43.11.1.1.6.1 2>/dev/null |egrep -i -e "$1"|cut -d "=" -f1|cut -d "." -f8`
fi
fi
NAME=`$SNMPGET -v1 -c $COMMUNITY $HOSTIP 1.3.6.1.2.1.43.11.1.1.6.1.$ID 2>/dev/null |cut -d " " -f4- |tr -d "\""`
if [ -z "$NAME" ]
then
echo "Error OID not found,maybe your Printer does not support checking this device, call me with Option CONSUM TEST or see help"
exit 3
fi

STATUS=`$SNMPGET -v1 -c $COMMUNITY $HOSTIP 1.3.6.1.2.1.43.11.1.1.9.1.$ID 2>/dev/null |cut -d " " -f4- |tr -d "\""`
FULL=`$SNMPGET -v1 -c $COMMUNITY $HOSTIP 1.3.6.1.2.1.43.11.1.1.8.1.$ID 2>/dev/null |cut -d " " -f4- |tr -d "\""`
if [ "$FULL" -gt 0 ] && [ "$STATUS" -gt 0 ]
then
let "STATUS= $STATUS * 100 / $FULL"
if [ "$STATUS" -gt "30" ]
then
echo "OK,$NAME is at $STATUS%|$NAME=$STATUS;;$FULL;"
exit 0
else
if [ "$STATUS" -lt "30" ] && [ "$STATUS" -gt "10" ]
then
echo "WARNING,$NAME is at $STATUS%|$NAME=$STATUS;;$FULL;"
exit 1
else
if [ "$STATUS" -lt "10" ]
then
echo "CRITICAL,$NAME is at $STATUS%|$NAME=$STATUS;;$FULL;"
exit 2
fi
fi
fi

else
if [ "$STATUS" = "-3" ]
then
echo "$NAME is OK"
exit 0
else
if [ "$STATUS" = "-2" ]
then
echo "$NAME is at warning level"
exit 1
else
if [ "$STATUS" = "0" ]
then
echo "$NAME is at critical level"
exit 2
fi
fi
fi

fi
}




function fpaper1(){
PAPERSTATUS1=`$SNMPGET -v1 -c $COMMUNITY $HOSTIP 1.3.6.1.2.1.43.8.2.1.10.1.1|cut -d " " -f4- |tr -d "\""`
if [ "$PAPERSTATUS1" = "-3" ]
then
echo "TRAY1 is OK"
exit 0
else
if [ "$PAPERSTATUS1" = "-2" ]
then
echo "TRAY1 is at warning level"
exit 1
else
if [ "$PAPERSTATUS1" = "0" ]
then
echo "TRAY1 is at critical level"
exit 2
fi
fi
fi
}


function fpaper2(){
PAPERSTATUS2=`$SNMPGET -v1 -c $COMMUNITY $HOSTIP 1.3.6.1.2.1.43.8.2.1.10.1.2|cut -d " " -f4- |tr -d "\""`
if [ "$PAPERSTATUS2" = "-3" ]
then
echo "TRAY2 is OK"
exit 0
else
if [ "$PAPERSTATUS2" = "-2" ]
then
echo "TRAY2 is at warning level"
exit 1
else
if [ "$PAPERSTATUS2" = "0" ]
then
echo "TRAY2 is at critical level"
exit 2
fi
fi
fi
}


function fpaper3(){
PAPERSTATUS3=`$SNMPGET -v1 -c $COMMUNITY $HOSTIP 1.3.6.1.2.1.43.8.2.1.10.1.3|cut -d " " -f4- |tr -d "\""`
if [ "$PAPERSTATUS3" = "-3" ]
then
echo "TRAY3 is OK"
exit 0
else
if [ "$PAPERSTATUS3" = "-2" ]
then
echo "TRAY3 is at warning level"
exit 1
else
if [ "$PAPERSTATUS3" = "0" ]
then
exit "TRAY3 is at critical level"
exit 2
fi
fi
fi
}
function ferror(){
echo usage is:
echo "$0 <HOSTIP> <COMMUNITY> <CHECK>"
echo " where CHECK can be:"
echo -e " MESSAGES"
echo -e " MODEL"
echo -e " CONSUM TEST"
echo -e " CONSUM ALL"

echo -e " CONSUM <String>"
echo -e " PAPER1"
echo -e " PAPER2"
echo -e " PAPER3"
echo -e " PAGECOUNT"
echo -e "CONSUM TEST, will give you the exact Names of installed Consumables like:"
echo -e "\"Black Toner Cartridge HP C4191A\""
echo -e "For monitoring this consumable you'll call me like this:"
echo -e "$0 <HOSTIP> <COMMUNITY> CONSUM black"
echo -e "The string just needs to be unique"
echo -e "CONSUM ALL will give you all the Stuff at once..."

}

if [ "$#" -lt 3 ]
then
ferror
exit 3
fi

if [ "$3" = "MESSAGES" ]
then
fmessages
else
if [ "$3" = "MODEL" ]
then
fmodel
else
if [ "$3" = "CONSUM" ]
then
fconsumables $4
else
if [ "$3" = "PAPER1" ]
then
fpaper1
else
if [ "$3" = "PAPER2" ]
then
fpaper2
else
if [ "$3" = "PAPER3" ]
then
fpaper3
else
if [ "$3" = "PAGECOUNT" ]
then
fpagecount
else
if [ "$3" = "TEST" ]
then
fconsumables $3
else
ferror
exit 3
fi
fi
fi
fi
fi
fi
fi
fi
echo UNKNOWN something went wrong whilst checking the stats
exit 3



Lorsque je fais :

./check_snmp_printer 192.168.1.150 public CONSUM ALL
CRITICAL,black ink cartridge is at CRITICAL Level|

ALL, je devrais normallement voir aussi l'état de l'encre couleur, je fais donc :

./check_snmp_printer 192.168.1.150 public CONSUM black
black ink cartridge is at critical level


Mais lorsque j'interroge pour les couleurs :

./check_snmp_printer 192.168.1.150 public CONSUM tri-color
UNKNOWN something went wrong whilst checking the stats

Pourtant :

./check_snmp_printer 192.168.1.150 public CONSUM TEST
Consumables you may Monitor:
"black ink cartridge"
"tri-color ink cartridge"
"ink blotter"

Quelqu'un a une idée ? :p

Merci ! :D

MrBrown
07-23-2007, 01:19 PM
Pour le check_printer_toner.sh fait un dos2unix sur ce fichier, il contient des caractères propres à windows qu'il faut enlever. Tu devrais pouvoir l'exécuter par la suite.

seb974
07-23-2007, 01:38 PM
Ca se lance mais avec beaucoup d'erreur :/

Sinon tu ne sais pas pourquoi l'autre fonctionne pas pour les couleurs ? :p