Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have written an ruby plugin for nrpe but it's not working properly.

I have written this plugin to check some backup files on a remote ftp server. When I try to execute the plugin from my nagios server like this:

./check_nrpe -H beurer.youw8.com -c check_ftp_backup

I get this response:

NRPE: Unable to read output

This is the piece of code I have written:

ftp = Net::FTP.new

   puts "Open ftp connection ..."

  puts "Get all directories from #{ftp_dir}"
  directories = Array.new
  ftp.list(ftp_dir).each do |file|   
    directories.push(file.split(' ').last)

  # Remove these from dir listing
  directories.delete_if {|x| x == '.' }
  directories.delete_if {|x| x == '..' }

  recent_backup = false
  recent_backup_date = nil
  # Loop threw all dirs and check the date
  puts "Process all directories"
  directories.each do |dir|
    # Split the dir name and create time obj
    dir_name_time = dir.split('.')
    dir_time = Time.utc(dir_name_time[0],dir_name_time[1],dir_name_time[2],dir_name_time[3],dir_name_time[4])

    # Keep track of latest time
    # TODO: cleanup
    if recent_backup_date.nil? then
      recent_backup_date = dir_time
    if recent_backup_date < dir_time then
      recent_backup_date = dir_time

    #  Substract the dir time from now, check if larger then the allowed days
    if (((Time.now.utc - dir_time) / 86400) <= min_days) then
      puts "Directory found with newer then #{min_days} day(s)"
      recent_backup = true

  if recent_backup then
    puts "Latest backup happend #{recent_backup_date} "
    puts "OK - last backed up #{recent_backup_date}"
  else # Look to pass param recent_backup_date to nagios
    puts "There is NO last backup!!! Latest backup happend #{recent_backup_date} "
    puts "CRITICAL - Latest backup happend #{recent_backup_date}"

rescue Net::FTPPermError => e 
  puts "#{e}"
  ftp.close unless ftp.nil?

When I run is on the remote server it is working properly, given me the correct status. I read about problems with permissions but I don't think this is the problem because everything is ran with root user.

Does anybody notices a bug in the code ? Or a solution?

Thanks a lot in advance!

share|improve this question
The nrpe process on the remote server typically is not run as root. It's usually running with the permissions of a nagios or nrpe user (depending on your configuration). Try running your ruby script as a non-root user and see what happens. –  cjc Apr 4 '12 at 13:36
I assume the script is either called by 'ruby scriptname' in nrpe.conf or is chmod +x with #!/usr/bin/ruby at the top, correct? –  Kyle Smith Apr 4 '12 at 13:42
I tried both with and without sudo, the ruby script runs perfectly. –  Niels Apr 4 '12 at 13:42
@KyleSmith yes, it's chmoded with +x this is the line in my nrpe.cfg: command[check_ftp_backup]=/usr/lib/nagios/plugins/check_ftp_backup But I don't think the errors lies there because the command is recognized by the nagios server itself. –  Niels Apr 4 '12 at 13:43
@cjc: I don't think the new line will cause such a problem. I tried to modify one of my plugins by adding a new line and it is still working. –  Khaled Apr 4 '12 at 13:53
show 14 more comments

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.