Page 1 of 1

check_by_ssh issues running remote Python script

PostPosted: Mon Oct 29, 2018 5:24 am
by andrewmoore
Hi All,

I have a Raspberry Pi with a temperature sensor connected via GPIO. To pull the data from the sensor I use the following Python script (get-temp.py).

Code: Select all
#!/usr/bin/python3

import sys, Adafruit_DHT

sensor = Adafruit_DHT.AM2302
pin = 4

temperature = round(Adafruit_DHT.read_retry(sensor, pin)[1],2)

if temperature is not None:
        sys.stdout.write('Temperature = {0}°C|{0};;;;'.format(temperature))
        sys.exit(0)
else:
        sys.stdout.write('Failed to get reading.')
        sys.exit(3)


If I run the script remotely using the standard SSH command it's fine:
bash-4.2$ ssh monitoring@172.16.1.101 -i /etc/icinga2/secure/monitoring /opt/get-temp.py
Temperature = 25.4°C|25.4;;;;


However, if I run it using the get_by_ssh plugin it returns exit code 1 (which isn't a valid exit code for the script):
bash-4.2$ ./check_by_ssh -l monitoring -i /etc/icinga2/secure/monitoring -C /opt/get-temp.py -H 172.16.1.101 -E
WARNING - check_by_ssh: Remote command '/opt/get-temp.py' returned status 1


I'm not familiar with how get_by_ssh operates. Why would the result be different with the 2 methods above? Any help would be appreciated.
Thanks.

Re: check_by_ssh issues running remote Python script

PostPosted: Mon Oct 29, 2018 1:53 pm
by tgriep
Can you run the following command so we can get the version of the check_by_ssh plugin you are running?
Code: Select all
./check_by_ssh  -V


Then replace the -E with -v to get a verbose output to see if there are any errors that the -E option is ignoring.
Code: Select all
./check_by_ssh -l monitoring -i /etc/icinga2/secure/monitoring -C /opt/get-temp.py -H 172.16.1.101 -v


I had some issues with the degree symbol that the get-temp.py outputs so for a test, try removing that to see if that allows the check to run.