Page 1 of 1

check_snmp_printer: Syntax error

Posted: Wed Feb 03, 2016 10:32 am
by celticpiping
Hi,
I'm getting an error no matter what I issue for a command using check_snmp_printer
it sits in: /usr/local/nagios/libexec
perms: nagios nagios rwxr-wr-w
I issued: #./check_snmp_printer -H 111.111.111.111 -C public -x "CONSUM ALL" -w 20 -c 10
and I get:
./check_snmp_printer: Syntax error: "(" unexpected
every time..

Thoughts?
Rich

Re: check_snmp_printer: Syntax error

Posted: Wed Feb 03, 2016 1:31 pm
by rkennedy
Can you post the entire contents of your check_snmp_printer file? Also, where did you download it from?

Re: check_snmp_printer: Syntax error

Posted: Wed Feb 03, 2016 1:50 pm
by celticpiping
Downloaded from:
https://exchange.nagios.org/directory/P ... ck/details

program contents:
#!/bin/sh

###############################################################################
# +-------------------------------------------------------------------------+
# | Copyright (C) 2007 S&L Netzwerktechnik |
# | |
# | This program is free software; you can redistribute it and/or |
# | modify it under the terms of the GNU General Public License |
# | as published by the Free Software Foundation; either version 2 |
# | of the License, or (at your option) any later version. |
# | |
# | This program is distributed in the hope that it will be useful, |
# | but WITHOUT ANY WARRANTY; without even the implied warranty of |
# | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
# | GNU General Public License for more details. |
# +-------------------------------------------------------------------------+
# |Monitoring Solution: The Complete Network Monitoring Solution :) |
# +-------------------------------------------------------------------------+
# | This code is designed, written, and maintained by the Serge Mueller/ S&L|
# +-------------------------------------------------------------------------+
# | http://www.monitoring-solution.de/ |
# +-------------------------------------------------------------------------+
###############################################################################
#
# check_snmp_printer - printer/consumables monitoring plugin for Nagios
# Version: 0.1.0
#
###############################################################################
#
# CHANGE LOG
#
# 2007-05-23 - Script creation
# 2007-06-06 - Added CONSUM ALL functionality
#
###############################################################################
#
# COMMENTS
# The Papertray stuff may need some attention...
# Most printers' output sucks there
#
#
###############################################################################
#
# DEPENDS On
# snmpwalk - if needet change variable below
# snmpget - see above
#
###############################################################################



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.hrDeviceDescr.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

Re: check_snmp_printer: Syntax error

Posted: Wed Feb 03, 2016 3:42 pm
by rkennedy
Odd - I am seeing another issue (I assume dependency):

Code: Select all

[root@suse11 libexec]# ./check_snmp_printer -H 111.111.111.111 -C public -x "CONSUM ALL" -w 20 -c 10
which: no xxd in (/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin)
UNKNOWN: check_snmp_printer: No usable 'xxd' binary in '/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin'
[root@suse11 libexec]#
Perhaps there is a ( somewhere in a variable that shouldn't be, or the script may have been pasted improperly. To rule out user error, can you run the following commands and try again?

Code: Select all

rm check_snmp_printer
wget -O check_snmp_printer "https://exchange.nagios.org/components/com_mtree/attachment.php?link_id=1758&cf_id=24"
chmod +x check_snmp_printer

Re: check_snmp_printer: Syntax error

Posted: Thu Feb 04, 2016 9:03 am
by celticpiping
oh well done sir!
It now works
:)

Re: check_snmp_printer: Syntax error

Posted: Thu Feb 04, 2016 11:47 am
by rkennedy
Ah! Glad to see this working, and that it wasn't anything too crazy.

I'll go ahead and close this thread out, feel free to open a new one if you ever need assistance in the future.