Check NRPE unable to read output but only with custom check

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
Vinc
Posts: 1
Joined: Wed Jun 30, 2021 11:02 am

Check NRPE unable to read output but only with custom check

Post by Vinc »

Hello,

I used an raspberry pi 3 with the DHT22 Sensor and wrote a little python script.

The script runs fine and without sudo so I dont think its an permission problem. All NRPE checks work from my nagios host except my own script.

I worked my way thru several posts but wasnt able to get it fixed.

log on Nagios Host says: Jun 30 17:52:42 MON1 check_nrpe: Remote 10.0.0.162 accepted a Version 3 Packet

root@MON1:~# /usr/lib/nagios/plugins/check_nrpe -H 10.0.0.162 -c check_users
USERS OK - 2 users currently logged in |users=2;5;10;0
root@MON1:~# /usr/lib/nagios/plugins/check_nrpe -H 10.0.0.162 -c check_temps
NRPE: Unable to read output

Code: Select all

#!/usr/bin/python3
import Adafruit_DHT, sys

DHT_SENSOR = Adafruit_DHT.DHT22
DHT_PIN = 4

#while True:
werte = Adafruit_DHT.read_retry(DHT_SENSOR, DHT_PIN)
temproom = werte[1]

if temproom < 25:
    print("OKAY - Temperatur ist {:.1f}".format(temproom))
    sys.exit(0)
elif temproom > 25 and temproom < 30:
    print("WARNING - Temperatur ist {:.1f}".format(temproom))
    sys.exit(1)
elif temproom > 30:
    print("CRITICAL - Temperatur ist {:.1f}".format(temproom))
    sys.exit(2)
else:
    print("UNKNOWN - Fehler beim auslesen")
    sys.exit(3)
Any ideas?
User avatar
mcapra
Posts: 3739
Joined: Thu May 05, 2016 3:54 pm

Re: Check NRPE unable to read output but only with custom ch

Post by mcapra »

NRPE doesn't execute commands with a full shell -- it uses popen. In your NRPE command definition, I would suggest including a full path to the particular Python binary rather than relying on the shebang.

I would also make sure the system user associated with the NRPE or xinetd daemon (which might be root, but isn't necessarily) has execute privileges on both the Python binary as well as your Python script.
Former Nagios employee
https://www.mcapra.com/
eee
Posts: 1
Joined: Thu Jul 15, 2021 11:25 pm

Re: Check NRPE unable to read output but only with custom ch

Post by eee »

hi, im also using RPi. small world. RPi3 to monitor, Ubuntu20.04 on RPi4 as remote server.

I'm new to nagios, so please take this suggestion with a grain of salt.


REMOTE SERVER (ubuntu 20.04)

I created my own check_php which simply called the CLI php php function php version.

basically, my entire file is
/usr/lib/nagios/plugins/check_php

Code: Select all

#!/usr/bin/php
<?PHP echo "OK." . phpversion(); ?>
then set my nrpe.cfg to recv pokes from the monitor by ADDING

/etc/nagios/nrpe.cfg

Code: Select all

command[check_php]=/usr/lib/nagios/plugins/check_php

then restart nagios-nrpe-server.service >
$> sudo systemctl restart nagios-nrpe-server.service




MONITOR Side: test
$> /usr/lib/nagios/plugins/check_nrpe -H RPI4B -c check_php
OK. 7.0.33-51+ubuntu20.04.1+deb.sury.org+1
Locked