SMB

check_smb_file

Description:

Tests the existence/age/size/contents of a file/folder on a SMB share. It’s a Perl script that uses the Filesys::SmbClient module to do all the work.

Current Version

0.5

Last Release Date

2012-12-16

Compatible With

  • Nagios 3.x

Owner

License

GPL


Project Notes
Usage Switches... -H, --host The hostname to check (required) -f, --filename The share and path to the file/directory (required) -F --filename-match Only check filenames matching this regex -D --mode-directory Treat the filename to check as a directory -w, --warning Warning if file property exceeds value -c, --critical Critical if file property exceeds value -m, --warning-match Warning if contents match regex -M, --critical-match Critical if contents match regex -t, --warning-files Warning if the total files detected exceeds value -T, --critical-files Critical if the total files detected exceeds value -p, --property The property to test (Default: modified) -K, --kerberos Use Kerberos for authentication -U, --username The username to connect with -P, --password The password to authenticate with -W, --workgroup The workgroup the username is located in -K, --kerberos Use Kerberos for authentication -n, --no-data Do not collect performance data -d, --debug <0-10> Set the debug level for libsmbclient -V, --version Display the version of this script and exit -h, --help Display this usage screen and exit Warning and Critical Values --------------------------- The returned value for a non-existent file/path is CRITICAL. A warning or critical value can be a measure of time or size, with a suffix detailing the measure type. The below table is a list of possible measures. Time | Size -------- --------------- seconds | KB (kilobytes) minutes | MB (megabytes) hours | GB (gigabytes) days | You can test a few different properties of the file. The below table lists the valid properties. Property | Description --------- ---------------------- modified | Last modified time accessed | Last accessed time size | Size of the file File Paths ---------- File paths are checked with forward slashes. So a path to check should be entered with forward slashes and not back slashes, such as... SomeShare/some_directory/some_file.txt However, if you enter back slashes the script will attempt to convert them to forward slashes and check the resulting path. Also, you can check hidden and admin shares, such as the system drive, by using a double dollar sign in nagios commands... C$$/some_directory/some_file.txt Also note that file path checks are case-insensitive. TODO/Limitations ---------- * This script does not yet test the size of a directory. * Performance data is a work-in-progress.
Reviews (2) Add a Review
Dealing with directories
by cenovusjim, October 31, 2015

Love the script! Had and issues with accessing files in subdirectories so made the following changes to the script: 1. sub-directories in the share 2. added full path to commands used $ diff check_smb_file check_smb_file-orig 18c18 $PROGNAME -H -W -s -f -u -p -S -E 57,59d56 ";; 82c79 onErrorMessage="ERROR: File "//"$host""$sharePathToTest"$fileToTest" does not exists." 89c86 smbclient //"$host""$sharePathToTest" -U "$user"%"$password" -W "$workgroup" -c "get '$fileToTest' /tmp/"$fileToTest"" 92c89 rm -f /tmp/"$fileToTest"



nice way to check the backups
by natxo, February 28, 2014

I only changed this: $ diff check_smb_file.pl* 541a542 > next if $filename eq "." or $filename eq ".."; to exclude the local dir and the upper dir because it would report critical every time otherwise (yes, the modified timestamps on those are older, but I do not need to check those ;-) Thanks



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
5 (4)
Favorites
1
Views
60,639