File System

check_files.pl – Check files age and number of files in a directory

Description:

This plugin takes “ls”-like file spec (such as *.tmp) and counts how many such files are there allowing to send alerts if its too many. It can also check file age and alert if file or directory has not been updated in a while. Performance info on number of files is available for graphing if you so desire.

Current Version

0.416

Last Release Date

2012-05-05

Compatible With

  • Nagios 1.x
  • Nagios 2.x
  • Nagios 3.x
  • Nagios XI

License

GPL


Project Files
Project Notes
For help and list of options do: ./check_files.pl --help The documentation in the help should be enough to get you started. The plugin despite large amount of code (to support threshold spec) is not that complex - all it does is sum number of files and alert if its too many, plus optionally track what is the oldest file. The plugin is based on check_netstat.pl 0.35 and as such shares threshold spec syntax with all my other plugins and supports slightly extended nagios plugin specification threshold syntax. The plugin itself does "ls -l" and parses that data. Depending on the options it can also add "-R" for recursion or may try to list only specific files you're looking for for large directories. I've chosen parsing "ls -l" over doing lower level direntry calls because parsing allows to use the plugin to process results from a remote system where all you need to do is execute "ls -l". To support such use the plugin has "-I" parameter telling plugin to process STDIN data as "ls -l" as well as "-C" parameter which allows to specify command in place of "ls -l" so you can substitute ssh or something else in there. Example of use is: define command { command_name check_err_files command_line $USER1$/check_files.pl -f -D $ARG1$ -F $ARG2$ -w $ARG3$ -c $ARG4$ } define service{ use prod-service host_name you_know_who service_description File Checks for error files check_command check_err_files!/var/someplace/somewhere!"*.error"!2!5 } If executing this remotely by snmp (which is rare, but I do it this way) example is: define command { command_name check_bysnmp_errfiles command_line $USER1$/check_by_snmp.pl -E someplace_fileslist -H $HOSTADDRESS$ -l snmpuser -x 'onesecret' -L sha,aes -X 'anothersecret' -S --exec $USER1$/check_files.pl -f -I -F $ARG1$ -w $ARG2$ -c $ARG3$ }
Reviews (3) Add a Review
files with spaces not count
by future001, April 30, 2016

1st - I needed to comment out lines 742-745 too! 2nd and worth: I'm would like to check mounted Windows directories and there are a lot of files with 'spaces'. These files are ignored by the script. Example: -F *.jpg ... in dir are 5 files, and only 2 are counted because in 3 are spaces like "hallo world.jpg" or "hallo-world 001.jpg" Please fix it - Thanks!



does not work
by dappa_don, February 28, 2015

[root@nagios-01]# /usr/local/nagios/libexec/check_files.pl -D /some/directory/ -F '*.txt' -c ! 27 -r -L "File Count" File Count CRITICAL - *.bk is 27 (not equal to )



Does the job and is very well written
by achoo, November 30, 2013

This works great except I needed to comment out lines 742-745. if (!defined($o_stdin) && !close(SHELL_DATA)) { print "UNKNOWN ERROR - execution of $shell_command resulted in an error $? - $!"; exit $ERRORS{'UNKNOWN'}; } These lines are giving the me the error "UNKNOWN ERROR - execution of LANG=C ls -l -R resulted in an error 512 - ' on my system (RHEL6, perl5 (revision 5 version 10 subversion 1)). 'UNKNOWN ERROR - execution of LANG=C ls -l -R resulted in an error 512 - Bad file descriptor' is the error if I just do a 'close(SHELL_DATA)'



Add a Review

You must be logged in to submit a review.

Thank you for your review!

Your review has been submitted and is pending approval.

Recommend

To:


From:


Thank you for your recommendation!

Your recommendation has been sent.

Project Stats
Rating
3.5 (4)
Favorites
1
Views
90,056