Home Directory Plugins System Metrics File System check_files.pl - Check files age and number of files in a directory

Search Exchange

Search All Sites

Nagios Live Webinars

Let our experts show you how Nagios can help your organization.

Contact Us

Phone: 1-888-NAGIOS-1
Email: sales@nagios.com


Remember Me

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

Current Version
Last Release Date
Compatible With
  • Nagios 1.x
  • Nagios 2.x
  • Nagios 3.x
  • Nagios XI
check_files.plcheck_files.pl - version 0.36 (Sep 2012)
check_files.plcheck_files.pl - version 0.416 (May 03, 2013)
Network Monitoring Software - Download Nagios XI
Log Management Software - Nagios Log Server - Download
Netflow Analysis Software - Nagios Network Analyzer - Download
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.
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)
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!
bydappa_don, February 3, 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 )
byachoo, November 22, 2013
1 of 1 people found this review helpful
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 $? - $!";

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)'