I have written a custom ruby script to check disk usage for each volume on an ubuntu server. The servers are controlled by puppet and the nagios system has been running for years and contains a number of other custom checks. When I run my new script script on the nagios server it returns the expected output but when I run it for another server it returns NRPE:unable to read output. Running a standard plugin works on any server.

I have only loaded the file into /usr/lib/nagios/plugins and included a command in nrpe.cfg to enable me to run it from the command line in a terminal.

Do I need to set a host name (or host group) and service for my custom check for the client server to make it work on that server, even from the command line?

Here is the command in nrpe.cfg


Here are some examples of commands which illustrate the issue.

nagios@nagios-server:~$ /usr/lib/nagios/plugins/check_nrpe -H nagios-server
NRPE v2.15

nagios@nagios-server:~$ /usr/lib/nagios/plugins/check_nrpe -H client-server
NRPE v2.15

nagios@nagios-server:~$ /usr/lib/nagios/plugins/check_nrpe -H nagios-server -c check_users
USERS OK - 2 users currently logged in |users=2;5;5;0

nagios@nagios-server:~$ /usr/lib/nagios/plugins/check_nrpe -H client-server -c check_users
USERS OK - 2 users currently logged in |users=2;5;5;0

nagios@nagios-server:~$ /usr/lib/nagios/plugins/check_nrpe -H nagios-server -c check_disk_usage
OK - '/backups' 79% of disk space used | '/'=37% '/tmp'=1% '/srv'=62% '/backups'=79%

nagios@nagios-server:~$ /usr/lib/nagios/plugins/check_nrpe -H client-server -c check_disk_usage
NRPE: Unable to read output

Here is my custom check script:

#!/usr/bin/env ruby

def largest_hash_key(hash)
  hash.max_by{|k,v| v}

filesystem = %x(df -h)

perfdata = filesystem.split("\n")
                 .map{ |e| "'%s'=%s" % [ e[-1], e[-2] ] }
                 .join(" ")

volumes = Hash[perfdata.split(" ").map {|str| str.split("=")}]

volumes = volumes.map{ |k, v| [k, v.to_i] }

full_disk = largest_hash_key(volumes)

pc_full = full_disk[1]

message = "#{perfdata} | #{perfdata}" 

if pc_full > 94
   puts "DISK CRITICAL - #{message}"
   exit 2
elsif pc_full > 89
   puts "DISK WARNING - #{message}"
   exit 1
   puts "DISK OK - #{message}"
   exit 0   
  • Can you post the "client-server" "check_disk_usage" configuration line in nrpe.cfg (or the configuration file in which is added) Can you run the command in the configuration and post the exit output + the return value of the script? – ignivs Feb 10 '16 at 15:25
  • I edited the question to include this information. – markhorrocks Feb 10 '16 at 15:46
  • What's wrong with the stock check_disk? – Keith Feb 10 '16 at 17:02
  • The stock check disk only shows me the Filesystem and only /dev/. This one lists each volume. – markhorrocks Feb 10 '16 at 17:36
  • Nrpe should be logging errors via syslog. Anything useful in the log files? That error implies that nrpe knows about the check but isn't getting parsable output back. +1 for trying to run the specified command line on the client as the user that nrpe runs as. – Paul Haldane Feb 11 '16 at 8:17

You need to use the full path to your ruby binary at the top of your script.

You can't use /usr/bin/env ruby as the interpreter, because NRPE is going to run with no ENV.

This can be simulated by running your script through env -i, as the nagios/nrpe user:

env -i /usr/lib/nagios/plugins/check_disk_usage.rb
  • which ruby produced /usr/bin/ruby so should I just remove the env keyword and use #! /usr/bin/ruby? – markhorrocks Feb 10 '16 at 17:48
  • Other custom ruby scripts on the same server do use /usr/bin/env ruby – markhorrocks Feb 10 '16 at 18:14
  • #!/usr/bin/ruby did not work – markhorrocks Feb 10 '16 at 18:59
  • Interesting. Can you add output of a manual test run as the nrpe user? – Keith Feb 10 '16 at 22:22
  • The nrpe user is nagios and so the command is documented above in the terminal section. – markhorrocks Feb 11 '16 at 11:14

As usual, this was due to a stupid error. The check script file was installed onto the nagios server instead of the client server. This nagios config is controlled by puppet and some custom checks are installed on the nagios server and some are installed on the client server.

I followed the example of another custom check script which I installed. The only reason that one worked is because somebody had installed it manually in /usr/lib/nagios/plugins on the client server while puppet uselessly installed it on the nagios server as well.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.