Random Project

Great, I added some code to the Status function

Hi:

We have Xerox, Ricoh and HP printers at our facility and I found that the status function wasn’t returning enough info for me. I needed the following:

1) If an HP printer is asleep, it should recognize that not go critical.
2) Xerox machines always complain about the bypass tray, ignore them. In fact never return a warning or critical with Xerox printers (specific to our environment)
3) If the printer does go into an error state, parse the return code and tell me what the actual problem is. Some issues in our environment should be fixed by our techs while others are handled by administrative staff so that is important to know.

I haven’t programmed in BASH since the mid-90’s and even then only sparingly so I apologize to the actual pro’s out there if this isn’t the cleanest but it works so, um, yay!

Here is the entire Status function that has been tested against Ricoh, Xerox and HP printers:

STATUS_EXIT_CODE=0
PRINTER_STATUS=$(snmpget -v1 -Ovq -c $COMMUNITY $HOST_NAME 1.3.6.1.2.1.25.3.5.1.1.1 2>/dev/null)
PRINTER_MODEL=$(snmpget -v1 -Ovq -c $COMMUNITY $HOST_NAME 1.3.6.1.2.1.25.3.2.1.3.1 2>/dev/null)
PRINTER_DETECTED_ERROR=$(snmpwalk -v1 -Ovxq -c $COMMUNITY $HOST_NAME 1.3.6.1.2.1.25.3.5.1.2 2>/dev/null)
DISPLAY=$(snmpwalk -v1 -Ovq -c $COMMUNITY $HOST_NAME 1.3.6.1.2.1.43.16.5.1.2.1 2>/dev/null | tr -d “””)
if [ ! -z “$PRINTER_DETECTED_ERROR” ]; then

IFS=’ ‘ read -ra ErrVals us is $PRINTER_STATUS. Printer is reporting: $PRINTER_ERROR_RESULT”
STATUS_EXIT_CODE=2
fi
if [[ “$DISPLAY” == “Sleep”* ]]; then
EXIT_STRING=”OK: Printer status is $DISPLAY.”
STATUS_EXIT_CODE=0
fi
;;
“idle”)
EXIT_STRING=”OK: Printer status is $PRINTER_STATUS”
;;
“printing”)
EXIT_STRING=”OK: Printer status is $PRINTER_STATUS”
;;
“warmup”)
EXIT_STRING=”OK: Printer status is $PRINTER_STATUS”
;;

*)
EXIT_STRING=”WARNING: Printer status is $PRINTER_STATUS”
STATUS_EXIT_CODE=1
;;
esac

return $STATUS_EXIT_CODE
}