I have this problem with NRPE, all the stuff I've found so far on the net seems to point me at things I've already tried.
# /usr/local/nagios/plugins/check_nrpe -H nrpeclient
gives
NRPE v2.12
as expected.
Running the command by hand (as defined in nrpe.cfg on "nrpeclient", gives the expected response
nrpe.cfg:
command[check_openmanage]=/usr/lib/nagios/plugins/additional/check_openmanage -s -e -b ctrl_driver=0 bat_charge
"Expected response"
But if I try to run the command from the Nagios server I get the following:
# /usr/local/nagios/plugins/check_nrpe -H comxps -c check_openmanage
NRPE: Unable to read output
Can anyone think of anywhere else I might have made a mistake with this? I've done the same thing on multiple other servers with no problem. The only difference I can think of with this is that this box is RHEL 5 based, whereas the others are RHEL 4 based.
Those two bits above that I've tested are the what most people seem to suggest when people have had this problem.
I should mention that I get a weird error in the logs when I restart nrpe
:
nrpe[14534]: Unable to open config file '/usr/local/nagios/etc/nrpe.cfg' for reading
nrpe[14534]: Continuing with errors...
nrpe[14535]: Starting up daemon
nrpe[14535]: Warning: Daemon is configured to accept command arguments from clients!
nrpe[14535]: Listening for connections on port 5666
nrpe[14535]: Allowing connections from: bodbck,combck,nam-bck
Even though, it's plainly reading that /usr/local/nagios/etc/nrpe.cfg
file to get the stuff it's talking about further down..
You have a rights problem.
Change the command to:
(add sudo)
Then, add the nagios-user to the sudoers:
Or you could just chmod the file... That also works.
If you are using CentOS, Red Hat, Scientific or Fedora, make sure to disable
Defaults requiretty
in the sudoers file.Short answer : if you're using a Bash plugin, make sure you have a shebang stating which interpreter should be used :
#!/bin/bash
I was facing the same issue with a Nagios plugin I wrote myself. The script was running as expected when launched locally, even when running as user
nagios
using following statement :But remote-launching using NRPE from the Nagios3 server was unsuccessful :
I finally solved this case by adding a shebang in my script, as it appeared that running the script through NRPE did not used the same interpreter as when running through
sudo sudo -s -u nagios
.In my case problem was simply - user nagios was not able to execute the script. After chmod it started to worked. Sudo is not necessary. Its even evil :)
check_nrpe was getting 'NRPE: Unable to read output' despite the check working locally because the plugin I was using did not work well with SELinux. Disable it and make sure to remove the file's contexts:
In my case, only one plugin failed while several others worked okay. It turned out to be a LOCALE problem.
The plugin was
check_mem.sh
and it performed a grep forMem
in the output offree
. But system wide LOCALE returnedSpeicher
(German) instead ofMem
, so all received values were empty strings.Check pathing, permissions, selinux, iptables.
Mine was a pathing issue in client:nrpe.cfg, double check the command path to the check_* plugin name. These can be confusing, (lib/local) (libexec/plugins) as a pathname. I mistakenly yanked and put the paths from the commented prepackaged nrpe cfg file to make commands. The make install or yum plugin install puts these in a difft directory.
commaneted: /usr/local/nagios/libexec/check_disk
versus
realpath: /usr/lib/nagios/plugins/check_disk
From the server I was able to confirm it was not a firewall issue, could telnet to the 5666 port, could run a blanket check_nrpe and get the status as a return value. Could run the commands locally but nrpe had the wrong path on the client in the nrpe.cfg.
In case of custom NRPE plugins, make sure to print some output along with the exit value. If there is no output from the script NRPE will complain saying
NRPE unable to read output
. You can enable debugging in nrpe.cfg and observe this error.If you can see correct output when running command directly by nagios user, but get
unable to read output
when running via NRPE, make sure the output you expect is not going to stderr. For example,ipmitool sel elist
command will returnSEL has no entries
to stderr, and stderr is not captured by nrpe. You can add2>&1
to redirect stderr to stdout in such case.This is a permission issue, just give the script execution right and it will be ok :
here an example : Before / Remote host:
NRPE server :
After : Remote Host :
Problem Resolved.
In my case the issues was selinux related (running RHEL 6.5, selinux is set to enforcing).
Installing nagios-plugins-* via yum will create your plugin files in /usr/lib64/nagios/plugins. If you check the fcontext on those plugin files (ls -lZ), you will see the files have the context type set to "nagios_system_plugin_exec_t", which is the context type that check_nrpe expects.
In my case, I had created a custom script "check_mem.sh" using "vi". The resulting file had the context type set to "lib_t". This was causing nrpe to output the "NRPE: Unable to read output".
Changing the file context to "nagios_system_plugin_exec_t" solved the issue:
chcon -t nagios_system_plugin_exec_t /usr/lib64/nagios/plugins/check_mem.sh
The usual selinux troubleshooting would have pointed me to this issue as well (checking /var/log/audit/audit.log), but it was ofcourse the last thing I thought about
Edit: chcon just temporarily changes the context. To change it persistently use
semanage fcontext -a -t nagios_system_plugin_exec_t /usr/lib64/nagios/plugins/check_mem.sh restorecon -vF /usr/lib64/nagios/plugins/check_mem.sh
In my case the log file being monitored was owned by root:adm, so adding the nagios user to the adm group made the check_log command succeed, but only when executed directly on the monitored hosts. It continued to fail using check_nrpe on the Nagios server until I restarted the nagios-nrpe-server service on the monitored hosts, e.g.
So apparently restarting the service was necessary to make the permissions change take effect for NRPE, but it took me a while to figure this out.