Skip to content

January 3, 2009

18

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]

Read more from Linux, Unix
18 Comments Post a comment
  1. Hoang Ha Du
    Dec 3 2009

    Thanks you so much !

  2. Darko Topolko
    Dec 8 2009

    Thanks a bunch!

    I’ve spent last hour trying to figure out what I was doing wrong :)

    Best regards,

    Darko

  3. Steakudnerscore
    Jan 18 2010

    Can some one tell me why the check_md_raid plugin needs root access? Isn’t it a little over kill?

  4. Jan 19 2010

    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).

  5. lomiz
    Apr 30 2010

    Thank’s so much!
    That was usefull!

  6. adamaxeman
    Jul 5 2010

    Thank you sir, this problem has been driving me nuts!

  7. Davide
    Sep 20 2010

    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

  8. dcslv
    Oct 11 2010

    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!

  9. Andy
    Feb 21 2011

    Thanks!

  10. Mar 3 2011

    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.

  11. Beastsign
    Apr 20 2011

    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

  12. Beastsign
    Apr 20 2011

    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 :)

  13. Jul 18 2011

    Damn, wasted a whole days to figure out this, just put little # on that line…crazy, very thank you man.

  14. Aug 20 2011

    Thank you very much, saved my day!!

  15. gregrwm
    Nov 16 2011

    @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)

  16. zerowolfgang
    Dec 4 2011

    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!

  17. Jurgen
    Dec 29 2011

    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!

  18. Tom
    Jan 2 2012

    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.

Share your thoughts, post a comment.

(required)
(required)

Note: HTML is allowed. Your email address will never be published.

Subscribe to comments