I've installed an NRPE in a server and I am testing with check_nrpe.
I've made this bash script /usr/local/nagios/libexec/example.sh:
ll /usr/local/nagios/libexec/example.sh
-rwxr-xr-x 1 root root 56 Sep 21 12:37 /usr/local/nagios/libexec/example.sh
cat
#!/bin/bash
echo "WARNING: This is a test"
exit 1
The /usr/local/nagios/etc/nrpe.cfg file has this command defined:
command[example]=sudo /usr/local/nagios/libexec/example.sh
The /etc/sudoers.d/nrpe has these two lines:
nagios ALL = NOPASSWD:/usr/local/nagios/libexec/example.sh
nrpe ALL = NOPASSWD:/usr/local/nagios/libexec/example.sh
When I run:
/usr/local/nagios/libexec/check_nrpe -H 127.0.0.1 -c example
The output:
NRPE: Unable to read output
The log file(daemon mode):
[1663794786] CONN_CHECK_PEER: checking if host is allowed: 127.0.0.1 port 41351
[1663794786] Connection from 127.0.0.1 port 41351
[1663794786] is_an_allowed_host (AF_INET): is host >127.0.0.1< an allowed host >127.0.0.1<
[1663794786] is_an_allowed_host (AF_INET): host is in allowed host list!
[1663794786] Host address is in allowed_hosts
[1663794786] Host 127.0.0.1 is asking for command 'example' to be run...
[1663794786] Running command: sudo /usr/local/nagios/libexec/example.sh
[1663794786] Command completed with return code 1 and output:
[1663794786] Return Code: 3, Output: NRPE: Unable to read output
[1663794786] Connection from 127.0.0.1 closed.
Additional Information
- I tryed the root and the nagios/nrpe users to run
check_nrpe(Both with same result). - I attempted with
echo "WARNING - ..."andecho "WARNING: ..."syntaxes. - I checked each point mentioned in the NRPE: Unable To Read Output - Nagios Support page.
- I searched my issue in Google, the Nagios Forum, here... I didn't found or realize of anything wrong.
- I tried to run the command in the localhost, and from a remote Nagios Core Server, always the same issue.
- Obviously, the bash script runs okay in every environment... Including as a locally defined command in a Nagios Core Server.
- This command will work as a Nagios service.