check_by_ssh issues running remote Python script

Support forum for Nagios Core, Nagios Plugins, NCPA, NRPE, NSCA, NDOUtils and more. Engage with the community of users including those using the open source solutions.
Locked
andrewmoore
Posts: 1
Joined: Mon Oct 29, 2018 5:06 am

check_by_ssh issues running remote Python script

Post 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.
User avatar
tgriep
Madmin
Posts: 9177
Joined: Thu Oct 30, 2014 9:02 am

Re: check_by_ssh issues running remote Python script

Post 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.
Be sure to check out our Knowledgebase for helpful articles and solutions!
Locked