New Question
 
 
PRTG Network Monitor

Intuitive to Use.
Easy to manage.

200.000 administrators have chosen PRTG to monitor their network. Find out how you can reduce cost, increase QoS and ease planning, as well.

Free PRTG
Download >>

 

What is this?

This knowledgebase contains questions and answers about PRTG Network Monitor and network monitoring in general. You are invited to get involved by asking and answering questions!

Learn more

 

Top Tags


View all Tags


Custom SSH Return 'Value' from Variable

Votes:

0

Your Vote:

Up

Down

I have been setting up Custom SSH Script/Sensors for our Linux boxes. The documentation and example are great, most scripts are running perfectly. I have run into an issue when trying to set the return value using a variable, for example:

This works fine from a script:
echo "0:50:Ok"

This always causes the value in the PRTG sensor to be 0 (like its a string):
COUNT=`expr 25 + 25`
echo "0:${COUNT}:Ok"

The output on the screen when manually running these is the same:
0:50:Ok
0:50:Ok

I've tried typeset -i, declare -i on the COUNT variable to be sure its an integer. I've tried changing around how the output is wrapped, and regardless of whether the script outputs 0:50:Ok, if the 50 came from a variable the sensor does not like it.

I'd love to be able to track the actual 'value' without building a crazy CASE statement to handle every possibility.

I've also tried setting the returncode as an variable, that seems to work just fine:
RETCODE="1"
echo "${RETCODE}:50:Warning"

Thanks for any direction on this.

custom sensor ssh variable

Created on Oct 31, 2012 7:35:56 PM by  Jim Mallett (0) 1

Last change on Nov 1, 2012 11:14:52 AM by  Torsten Lindner [Paessler Support]



3 Replies

Accepted Answer

Votes:

0

Your Vote:

Up

Down

Hi,

It is curious because the output looks similar but PRTG takes the result as a string and tries to parse the value between the colons and interpret it either as an integer or a float regarding the sensor-setting. Obviously the output is only similar on the first view. We are trying to fix this as soon as possible.

In the meantime please take COUNT=`expr 25 + 25` echo "0:$COUNT:Ok" instead of COUNT=`expr 25 + 25` echo "0:${COUNT}:Ok" to enforce encoding the output as a simple string.

Kind regards

Created on Nov 2, 2012 12:33:50 PM by  Dieter Loskarn [Paessler Support]



Votes:

0

Your Vote:

Up

Down

Thank you. That did work against the simple `expr 25 + 25`, the sensor started showing 50.

I plugged in my original code. COUNT=`/usr/sbin/lsof -i @server.domain.org:1521 | wc -l` echo "0:$COUNT:Ok" It calculates the number of open connections between this server and our database. The output when run manually from the CLI looks as I would expect: 0:57:Ok (with the 57 fluctuating slightly for each run). Unfortunately the sensor in PRTG would still show 0.

I then tried to modify things a bit, just to see if the | wc -l was messing things up: COUNT=`cat /var/prtg/scripts/testing.sh | wc -l` echo "0:$COUNT:Ok"

I excpected the output to be 0:2:Ok, and it was. And the sensor showed the appropriate 2 for a value. So it looks like there's something about the lsof portion of the command messing things up. Outside the scopy of PRTG/Paessler, but I thought I'd post this in case anybody else runs into something similar.

I truly appreciate your help. If I find a cause/resolution I'll update this.

Jim

Created on Nov 5, 2012 11:36:32 PM by  Jim Mallett (0) 1



Votes:

0

Your Vote:

Up

Down

And now for the 'reply of shame'.

So from the CLI I would see the connection count I expected, great except I ran the script as root. I would then trigger the sensor and it said 0, because the prtg user I setup doesn't have permissions to see anything but its own processes when using lsof. Sigh. I've been doing this how long?

Thanks, Jim

Created on Nov 6, 2012 12:17:14 AM by  Jim Mallett (0) 1



Please log in or register to enter your reply.


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.