Hello,

I'm wondering how to implement this command in to a script:

lpstat | grep DOWN

If a printer has status down then it has to get a down value in ptrg.

I couldnt get started without a good sample, I think it has to be a ssh/script sensor


Article Comments

Hello there,

Here's a basic idea (courtesy of a colleague who's more into UNIX/Linux stuff than myself) for a script:

#!/bin/bash RESULT=`lpstat | grep 'DOWN' | wc -l` echo "0:$RESULT:There are $RESULT down printers."

That's basically your script. Make sure it is located in /var/prtg/scripts on the target device as described in the sensor's manual page.

To keep things simple, the script is "neutral" on the sensor state, meaning it always returns an "OK" state (represented by "0" in the echo statement). What you need to do then is to set a limit in the sensor's channel that displays the returned value to go into error when upper error limit is 0, meaning every value greater than 0 will lead to the sensor showing an error.

In case this does not work as expected, please post the output of lpstat | grep DOWN so we can finetune the script if necessary.

Kind regards.


Jul, 2016 - Permalink

Hello,

This is what I'm looking for! I forget to say it is for an AIX machine. I changed it a little bit:

RESULT="`lpstat | grep DOWN | wc -l`" echo "0:$RESULT:There are $RESULT down printers."

And now its displaying the down printers. I'm wondering if its possible to get my gauge red in case of down printers. I can do it with the channel setting limits but maybe there is a nicer way?


Jul, 2016 - Permalink
RESULT="`lpstat | grep DOWN | wc -l`"
EXITCODE=0

if [ $RESULT -gt 0 ]
then
 EXITCODE=2
fi

echo "$EXITCODE:$RESULT:There are $RESULT down printers."

The sensor will then error as soon as there's a down printer :)


Jul, 2016 - Permalink

I now get this

System Error: There are 1 down printers. (code: PE022)

I dont know for sure if thats right because of the code PE022

Actuaully yes there is 1 down printer.

When there are no down printers, the sensor is nice green.


Jul, 2016 - Permalink

It's indeed correct - you can also set the exitcode to one instead of 2; then it will go into a warning state. It's either that or using limits :) You can also use the SSH Script Advanced sensor which gives you more options in sensor customization (<your-prtg>/api.htm?tabid=7) :)


Jul, 2016 - Permalink

thanks!


Jul, 2016 - Permalink