Nagios nrpe and sudo: “NRPE: Unable to read output”
On CentOS 5 (and RedHat EL as well), you can encounter the following behaviour when configuring an nrpe plugin with sudo:
[andrea@feyd ~]$ /usr/lib/nagios/plugins/check_nrpe -H 1.2.3.4 -c check_md_raid
NRPE: Unable to read output
Given that check_md_raid is defined as follows, in nrpe.conf:
command[check_md_raid]=sudo /usr/local/bin/nagios_check_md_raid
And given (for completeness) its relative /etc/sudoers line as follows:
nagios ALL=(ALL) NOPASSWD:/usr/local/bin/nagios_check_md_raid
Then the problem is in the requiretty options in /etc/sudoers, enabled by default on CentOS. Simply comment it as follows:
#Defaults requiretty
After that the plugin should work as expected:
[andrea@feyd ~]$ /usr/lib/nagios/plugins/check_nrpe -H 1.2.3.4 -c check_md_raid
RAID OK: All arrays OK [1 array checked]


Thanks you so much !
Thanks a bunch!
I’ve spent last hour trying to figure out what I was doing wrong
Best regards,
Darko
Can some one tell me why the check_md_raid plugin needs root access? Isn’t it a little over kill?
It looks like there are some check md scripts that will work without root privileges (those using /proc/mdstat) and some requiring it (those using mdadm).
Thank’s so much!
That was usefull!
Thank you sir, this problem has been driving me nuts!
I tryed to use this solution in my system but doesn’t work . To solved the problem I add this line in the file nrpe.cfg :
command_prefix=/usr/bin/sudo
regards
Davide
Big help, I was banging my head against this problem for a few hours.
Seems simple now, but this was a great find.
Thank you!
Thanks!
Thank you, I have come across this post twice now, years apart. Fixed the problem for me both times. Simple and concise without assuming too much.
Hi, I’ve problem with my script. I’ve red few other articles and documentation, but still without success.
My script is simple bash, just checking mounts and returning
exit 2 or exit 0 as status. But if I run my script it doesn’t return any visible status (so I’ve added echo “critical” and echo “ok” for testing). I’m running Debian squeeze and nagios is still giving me status UNKNOWN NRPE Unable to read output. I’ve added to my sudoers nagios user nopassword /path/to/my/check_mounts.sh. I’ve correct privileges on script ugo r-x for all.
I’ve no other inspiration how could I solve it. I’ll be happy for some tips and tricks. Thank you.
Here is one of articles I’ve followed: http://debianclusters.org/index.php/Creating_Your_Own_Nagios_Plugin
Ok, my false.
Be sure, that you have in your nrpe.d/my_check.cfg and nagios-plugins/config/mycheck.cfg in command /path/to/mycheck.SH at the end or .PY or .PL or whatever
Don’t copy and paste
Damn, wasted a whole days to figure out this, just put little # on that line…crazy, very thank you man.
Thank you very much, saved my day!!
@Beastsign perhaps your admonition might help me but i can’t quite decipher what you mean (my Defaults requiretty commented longago still get NRPE: Unable to read output)
once you figure out that your plugins are trying to do something as root, mine normally don’t but i needed a couple that did, using sudo is kind of a no-brainer solution – when one’s brain is working correctly, that is.
today mine wasn’t, so thanks for the tip!
You also saved my day, I’ve been searching for this solution for a couple of hours.
I ran into this problem when I upgraded from Centos 5 to Centos 6
Thank you so much!
you may also modify your /etc/sudoers on a per-user
basis, while keeping the general “requiretty” flag ON for the sake of security.
eg :
Defaults:nagios !requiretty
will allow the ‘nagios’ user to run sudo without tty.