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.
Article Comments
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
Nov, 2012 - Permalink
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
Nov, 2012 - Permalink
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 ofCOUNT=`expr 25 + 25` echo "0:${COUNT}:Ok"
to enforce encoding the output as a simple string.Kind regards
Nov, 2012 - Permalink