# check_filecount_dir.rb patrick@aushack.com 20080709 v0.1 # Distributed under the BSD_LICENSE e.g. free as in beer # Converted check_filecount_dir.pl to ruby, for ruby2exe compile for Windows boxes # ver = 0.1 if ARGV[2].nil? puts "#{$0} v#{ver} by Patrick Webster " puts "Nagios plugin to check a directory file count and return a status\r\n\r\n" puts "Usage: #{$0} " puts "e.g. #{$0} c:\\ 50 100" exit 3 end basedir = ARGV[0] warn = ARGV[1].to_i crit = ARGV[2].to_i unless (warn < crit) puts " must be less than " exit 3 end count = -2 # discard '.' and '..' entries Dir.foreach(basedir) do |x| count+=1 end if( count >= warn ) retval = 1 if( count >= crit ) retval = 2 end else retval = 0 end if ( retval == 0 ) puts "OK: File count - " + count.to_s + "\n" exit retval elsif ( retval == 1 ) print "WARNING: File count - " + count.to_s + "\n" exit retval elsif ( retval == 2 ) print "CRITICAL: File count - " + count.to_s + "\n" exit retval end exit retval