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
command[check_disk_usage]=/usr/lib/nagios/plugins/check_disk_usage.rb
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}
end
filesystem = %x(df -h)
perfdata = filesystem.split("\n")
.grep(/\A\/dev/)
.map(&:split)
.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
else
puts "DISK OK - #{message}"
exit 0
end
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: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.