What is this?

This knowledgebase contains questions and answers about PRTG Network Monitor and network monitoring in general.

Learn more

PRTG Network Monitor

Intuitive to Use. Easy to manage.
More than 500,000 users rely on Paessler PRTG every day. Find out how you can reduce cost, increase QoS and ease planning, as well.

Free Download

Top Tags


View all Tags

lpstat unix command

Votes:

0

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

commands lpstat unix

Created on Jul 5, 2016 7:13:17 AM



Best Answer

Accepted Answer

Votes:

0

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 :)

Created on Jul 5, 2016 6:15:12 PM by  Stephan Linke [Paessler Support]



6 Replies

Votes:

0

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.

Created on Jul 5, 2016 12:01:28 PM by  Erhard Mikulik [Paessler Support]

Last change on Jul 5, 2016 12:04:52 PM by  Erhard Mikulik [Paessler Support]



Votes:

0

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?

Created on Jul 5, 2016 5:55:01 PM



Accepted Answer

Votes:

0

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 :)

Created on Jul 5, 2016 6:15:12 PM by  Stephan Linke [Paessler Support]



Votes:

0

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.

Created on Jul 5, 2016 7:34:19 PM



Votes:

0

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) :)

Created on Jul 5, 2016 7:39:18 PM by  Stephan Linke [Paessler Support]

Last change on Jul 5, 2016 7:40:27 PM by  Stephan Linke [Paessler Support]



Votes:

0

thanks!

Created on Jul 5, 2016 8:06:58 PM




Disclaimer: The information in the Paessler Knowledge Base comes without warranty of any kind. Use at your own risk. Before applying any instructions please exercise proper system administrator housekeeping. You must make sure that a proper backup of all your data is available.