Guides‎ > ‎Common Checks‎ > ‎

Files & Folders

File Count

Check the amount of files in a folder (and sub-folders). Generate a warning if more that 500 files exist, critical if more than 1000 files exist.

NSClient++ 0.3.9
No additional configuration is required.
Command:
check_nrpe -H 192.168.142.1 -t 30 -c CheckFiles -a path='C:\\NO BACKUP' pattern=*.* 'filter=size gt 0b' 'master-syntax={%total% Files Found}' MaxWarn=500 MaxCrit=1000

Output:
{12347 Files Found}, found files: 12347 > critical|'found files'=12347;500;1000

NSClient++ 0.4.1
No additional configuration is required.
Command:
check_nrpe -H 192.168.142.1 -t 30 -c CheckFiles -a path='C:\\NO BACKUP' pattern=*.* 'master-syntax={%total% Files Found}' MaxWarn=500 MaxCrit=1000

Output:
{12347 Files Found}, found files: 12347 > critical|'found files'=12347;500;1000

NSClient++ 0.4.3.138 onwards
No additional configuration is required.
Command:
check_nrpe -H 192.168.142.1 -t 30 -c check_files -a path='C:\\NO BACKUP' pattern=*.* 'warning=count>500' 'critical=count>1000' top-syntax='${status}: ${problem_count}/${count} files' 'empty-state=ok'

Output:
CRITICAL: 21778/22278 files|'count'=22278;500;1000

Files Greater Than A Size

Check for files in a folder (and sub-folders) that are greater than 500MB in size. Generate a critical alert if more than 1 files is found.

NSClient++ 0.3.9 & 0.4.1
No additional configuration is required.
Command:
check_nrpe -H 192.168.142.1 -t 30 -c CheckFiles -a path='C:\\NO BACKUP' pattern=*.* 'filter=size gt 500M' 'master-syntax={%total% Files Found} %list%' 'syntax=%filename%: %size%' MaxCrit=1

Output:
{6 Files Found} CentOS-6.5-x86_64-bin-DVD1.iso: 4.16G, CentOS-7.0-1406-x86_64-DVD.iso: 3.86G, linuxmint-17-cinnamon-64bit-v2.iso: 1.29G, ubuntu-10.04.1-server-amd64.iso: 682M, VMware-VIMSetup-all-5.5.0-1750597-20131201.iso: 3.24G, vMA-5.5.0.1-1663088.zip: 534M, found files: 6 > critical|'found files'=6;0;1

NSClient++ 0.4.3.138 onwards
No additional configuration is required.
Command:
check_nrpe -H 192.168.142.1 -t 30 -c check_files -a path='C:\\NO BACKUP' pattern=*.* 'filter=size gt 500M' 'critical=count>0' 'detail-syntax=%(filename): %(size)' 'empty-state=ok'

Output:
CRITICAL: 9/9 files (en_windows_7_professional_with_sp1_x64_dvd_u_676939.iso: 3320903680, WindowsTechnicalPreview-x64-EN-US.iso: 4100497408, VTS_01_1.VOB: 1073641472, VTS_01_2.VOB: 1073672192, VTS_01_3.VOB: 1073680384, VTS_01_4.VOB: 1073731584, VTS_01_5.VOB: 1073539072, VTS_01_6.VOB: 911251456, vMA-5.5.0.1-1663088.zip: 559425648)|'count'=9;0;0

Make Sure A Specific File Exists

Check for a specific file in a folder. Generate a critical alert if file is not found.

NSClient++ 0.3.9
No additional configuration is required.
Command:
check_nrpe -H 192.168.142.1 -t 30 -c CheckFiles -a path='C:\\NO BACKUP' pattern='CentOS-6.5-x86_64-bin-DVD1.iso' 'filter=size gt 0b' max-dir-depth=0 MinCrit=0

Output when file is found:
CentOS-6.5-x86_64-bin-DVD1.iso|'found files'=1;0;0

Output when file is NOT found:
found files: 0 < critical|'found files'=0;0;0

NSClient++ 0.4.1
No additional configuration is required.
Command:
check_nrpe -H 192.168.142.1 -t 30 -c CheckFiles -a path='C:\\NO BACKUP' pattern='CentOS-6.5-x86_64-bin-DVD1.iso' max-dir-depth=0 MinCrit=0

Output when file is found:
CentOS-6.5-x86_64-bin-DVD1.iso|'found files'=1;0;0

Output when file is NOT found:
found files: 0 < critical|'found files'=0;0;0

NSClient++ 0.4.3.138 onwards
No additional configuration is required.
Command:
check_nrpe -H 192.168.142.1 -t 30 -c check_files -a path='C:\\NO BACKUP' pattern='CentOS-6.5-x86_64-bin-DVD111.iso' max-depth=1 'critical=count<1' 'empty-state=critical'

Output when file is found:
OK: All 1 files are ok|'count'=1;0;1

Output when file is NOT found:
No files found|'count'=0;0;1

Make Sure Files Exists That Match A Pattern

The following file exists: "C:\Downloads\test1\test-123.txt" AND it has some text added to it (so it doesn't have a byte size of 0).
These commands find any files that start with test-
Generate a critical alert if no files are found.

NSClient++ 0.3.9
No additional configuration is required.
Command:
check_nrpe -H 192.168.142.1 -t 30 -c CheckFiles -a path='C:\\Downloads\\test1' pattern='test-*' 'filter=size gt 0b' max-dir-depth=0 MinCrit=0

Output when files are found:
test-123.txt|'found files'=1;0;0

Output when NO files are found:
found files: 0 < critical|'found files'=0;0;0

NSClient++ 0.4.1
No additional configuration is required.
Command:
check_nrpe -H 192.168.142.1 -t 30 -c CheckFiles -a path='C:\\Downloads\\test1' pattern='test-*' max-dir-depth=0 MinCrit=0

Output when files are found:
test-123.txt|'found files'=1;0;0

Output when NO files are found:
found files: 0 < critical|'found files'=0;0;0

NSClient++ 0.4.3.138 onwards
No additional configuration is required.
Command:
check_nrpe -H 192.168.142.1 -t 30 -c check_files -a path='C:\\Downloads\\test1\\' pattern=test-* 'critical=count<1' max-depth=1 'empty-state=critical'

Output when file is found:
OK: All 1 files are ok|'count'=1;0;1

Output when file is NOT found:
No files found|'count'=0;0;1

Make Sure Files Exists That Were Modified In The Last Two Hours

Check a folder to make sure files exist that were modified in the past two hours. Generate a critical alert if no files matching this criteria are found.

NSClient++ 0.3.9 & 0.4.1
No additional configuration is required.
Command:
check_nrpe -H 192.168.142.137 -c CheckFiles -a path='D:\\Important Stuff' pattern=*.* 'filter=written > -2h' 'master-syntax={%total% Files Found}' MinCrit=0

Output when files matching criteria are found:
{1 Files Found}|'found files'=1;0;0

Output when NO files matching criteria are found:
{0 Files Found}, found files: 0 < critical|'found files'=0;0;0

NSClient++ 0.4.3.138 onwards
No additional configuration is required.
Command:
check_nrpe -H 192.168.142.1 -t 30 -c check_files -a path='E:\\Important Stuff\\' pattern=*.* 'filter=written > -2h' 'critical=count<1' 'empty-state=critical'

Output when files matching criteria are found:
OK: All 1 files are ok|'count'=1;0;1

Output when NO files matching criteria are found:
No files found|'count'=0;0;1

Check For Files Older Than Two Hours

Check a folder to determine if any files exist that are older than two hours. Generate a critical alert if at least 1 file matches this criteria.

NSClient++ 0.3.9 & 0.4.1
No additional configuration is required.
Command:
check_nrpe -H 192.168.142.137 -c CheckFiles -a path='D:\\Important Stuff' pattern=*.* 'filter=written < -2h' 'master-syntax={%total% Files Found}' MaxCrit=1

Output when files matching criteria are found:
{3 Files Found}, found files: 3 > critical|'found files'=3;0;1

Output when NO files matching criteria are found:
{0 Files Found}|'found files'=0;0;1

NSClient++ 0.4.3.138 onwards
No additional configuration is required.
Command:
check_nrpe -H 192.168.142.1 -t 30 -c check_files -a path='E:\\Important Stuff2\\' pattern=*.* 'filter=written < -2h' 'critical=count>0' top-syntax='${status}: ${problem_count}/${count} files' 'empty-state=ok'

Output when files matching criteria are found:
CRITICAL: 1/1 files|'count'=1;0;0

Output when NO files matching criteria are found:
No files found|'count'=0;0;0

Check That Folder Exists That Matches A Date Pattern

This came up on the Nagios Support Forum and it's a great solution. The user needed to check that a subdirectory was being created each day and this was a date based directory. The answer was to use the date command in backticks on the Nagios server which would generate the correct folder name. Credit goes to tmcdonald & warnox.

NSClient++ 0.4.3
No additional configuration is required.
Command:
check_nrpe -H 192.168.1.60 -c check_files -a file="c:\\TEMP" "max-depth=2" "filter=filename='`date +%d%m%Y`'" "critical=count<1" "empty-state=CRITICAL" "empty-syntax=CRITICAL - Cannot find folder `date +%d%m%Y`"

Output when folder matching criteria is found:
OK: All 1 files are ok|'count'=1;0;1

Output when folder matching criteria is NOT found:
CRITICAL - Cannot find folder 10082015|'count'=0;0;1


Notes about path= and pattern=

When using path= and pattern= together, this will take more overhead to execute as it looks at all the files in the folder.

If you only wanted to watch a specific file, ditch pattern= and put the while filename in path=

For example:
path='D:\\Important Stuff\\Important File.txt'


HOWEVER if there is a chance that the file doesn't exist sometimes, then define the filename in the patttern=

For example:
path='D:\\Important Stuff' pattern='Important File.txt'