Home Directory Plugins System Metrics File System check nfs/cifs/davfs mountpoints

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

Login

Remember Me
Don't miss your chance to attend the 2014 Nagios World conference!

Don't miss your chance to attend the 2014 Nagios World Conference, Oct 13-16th. Informative Sessions, Networking, Food and Cocktails! Visit go.nagios.com/conference/ for more information or to register.


check nfs/cifs/davfs mountpoints

Bookmark and Share

Rating
21 votes
Favoured:
6
Current Version
1.18
Last Release Date
2014-06-16
Compatible With
  • Nagios 3.x
Owner
License
MPL
Hits
99676
Files:
FileDescription
check_mountpoints.shcheck_mountpoints.sh
Check if all specified nfs/cifs/davfs mounts exist and if they are correct implemented. That means we check /etc/fstab, the mountpoints in the filesystem and if they are mounted. It is written for Linux and Solaris, uses proc-Filesystem and was tested on

Debian,
OpenSuse 10.1 10.2 10.3 11.0, SLES 10.1 11.1
RHEL 5 6, CentOS 5 6
Solaris

# changes 1.18
# - write check respects stale timeout now
# changes 1.17
# - add support for ocfs2
# changes 1.16
# - minor English fixes
# changes 1.15
# - fix bad bug in MTAB check
# changes 1.14
# - better support for HP-UX, Icinga
# - cleanup writecheck file after check
# changes 1.13
# - add support for glusterfs
# changes 1.12
# - add LIBEXEC path for OpenCSW-installed nagios in Solaris
# changes 1.11
# - just update license information
# changes 1.10
# - new flag -w results in a write test on the mountpoint
# - kernel logger logs CRITICAL check results now as CRIT
# changes 1.9
# - new flag -i disable check of fstab (if you use automount etc.)
#
# for all change infos look into file
Usage:

Usage: $PROGNAME [-m FILE] $mountpoint [$mountpoint2 ...]
Usage: $PROGNAME -a
Usage: $PROGNAME -h,--help
Options:
-m FILE Use this mtab instead (default is /proc/mounts)
-f FILE Use this fstab instead (default is /etc/fstab)
-N NUMBER FS Field number in fstab (default: 3)
-M NUMBER Mount Field number in fstab (default: 2)
-T SECONDS Responsetime at which an NFS is declared as staled (default: 3)
-i Ignore fstab. Don't fail just because mount isn't in fstab. (default: unset)
-a Autoselect mounts from fstab (default: unset)
-A Autoselect from fstab. Return OK if no mounts found. (default: unset)
-w Writetest. Touch file $mountpoint/.mount_test_from_$(hostname) (default: unset)
MOUNTPOINTS list of mountpoints to check. Ignored when -a is given
# --------------------------------------------------------------------
# now we check if the given parameters ...
# 1) ... exist in the /etc/fstab
# 2) ... are mounted
# 3) ... df -k gives no stale
# 4) ... exist on the filesystem
# 5) ... is writable (optional)

--------------------------------------------------------------------

This plugin is NOT developped by the Nagios Plugin group.
Please do not e-mail them for support on this plugin, since
they won't know what you're talking about.

For contact info, read the plugin itself...
Reviews (17)
I have a few servers that we ust rc.local to map NFS mounts (reasons beyound me). They look like this:

mount 1xx.26.xx.xx:/vol/e_oldlogs /geminilogs
sleep 2
mount 1xx.26.xx.xx:/vol/e_webdocs /webdocs
sleep 2
mount 1xx.26.xx.xx:/vol/e_weblogs /weblogs

I need to check agains this file for mounts is there an easy way or even a hard way to do this???
Owner's reply

Yoo can achieve that with a little trick.

Your rc.local file needs a little rewrite.
The lines should look like that:

mount -t nfs 1xx.26.xx.xx:/vol/e_oldlogs /geminilogs

We need that "-t nfs" because the check can use the following parameters:

-f /etc/rc.local (he takes that fiel as fstab now)
-N 3 (the fieldnumber to search for FS type, thats why we needed the nfs)
-M 5 (fieldnumber of the mountpoint)

Or you can just use -i ,which ignores the fstab and just checks if the given paths are mountpoint according to mtab.

Both ways should work for you.
Regards

bymv200i, February 7, 2014
I guess this plug will not work under AIX.. :o(
byWebkungen, October 15, 2013
Hi!

Tried out this and it seems to work fine. One problem though.. When I define the command like this:

command[check_mpoints]=/usr/lib/nagios/plugins/check_mountpoints.sh -a -w

And run:
/usr/lib/nagios/plugins/check_nrpe -H localhost -c check_mpoints

I'm getting "CRITICAL: /mnt/nfs/path/to/folder/.mount_test_from_hostname is not writable."

If I run it without nrpe, i.e.: /usr/lib/nagios/plugins/check_mountpoints.sh -a -w it's working fine.

Why is that? Issue with permission for the user Nagios?

Thanks,
Owner's reply

Yes, this seems to be the problem. If the nrpe users has no write permissions, the writetest will fail.

Hello,

I just tested this plugin and I have to say: this script does not what it should do (on Ubuntu 12.04)

I have a mountpoint, say /media/user/share which is defined in /etc/fstab. I ran the plugin as root and it said: "OK: all mounts were found (/media/user/share)".

Then I unmounted this share from the client,re-ran the plugin and it still claimed to be mounted: "OK: all mounts were found ( /media/user/share)".

Since Ubuntu is binary-compatibel to Debian I do really wonder why this script/plugin gives totaly wrong information (moreover, Ubuntu also uses /proc/mounts and /etc/fstab).

To put it in a nutshell: I can't blame Ubuntu for the wrong result of this plugin. I wonder how that can be, since it was updated some weeks ago :(

I will use /bin/bash -x to see if I can "debug" this script (maybe just a wrong loop logic) but consider this the reason for a low rating.

Without the bug I see on Ubuntu this would be a great plugin!
Owner's reply

Hi ronator,

you were right, so it has nothing to do with Ubuntu or Debian. There was a bug in Release 1.14, which always returns "true" when /proc/mounts was checked. The new version 1.15 should work for you now. If not contact me via mail or github.

Regards

byandreaswp, April 15, 2013
1 of 1 people found this review helpful
I like this plugin. But I had to change LIBEXEC to include /opt/csw/libexec/nagios-plugins because i use OpenCSW-installed nagios in Solaris.
Owner's reply

I added the path in version 1.12. Thanks

byinfecticide, October 25, 2012
Any chance you could include AIX support?

AIX uses /etc/filesystems instead of /etc/fstab and its a completely different format.

AIX also does not have /etc/mtab.

Thanks for the consideration.
Owner's reply

The problem is, that i never work with AIX at all. So I am not the perfect person to implement that. If you have a tested patch I would take it so. ;)

bytomagios, October 5, 2012
1 of 1 people found this review helpful
the best check for mountpoints, and actively maintained!
Thanks
bybrigo, August 23, 2012
1 of 1 people found this review helpful
Thank you for the plugin, which does exactly what I need. I find the '-a' option is particularly useful, but an exclusion list option to complement that would be super, as there may be some mountpoints I explicitly don't want to check.

One other more minor annoyance is that an unknown status is returned if there are no mounts to check. An option to silence that would also be super!
Owner's reply

Version 1.7 has the new -A flag, which returns an OK if no mount were autoread from fstab.
If you want an exclude list send me a patch ;) Time is short at the moment.

bybostonsean, July 13, 2012
1 of 1 people found this review helpful
We run tons of nfs mounts across many machines and those mounts sometimes change based on needs so I made a slight modification to avoid the need to keep track of the mountpoints to provide as args. Especially since it's likely no one will tell me beforehand.

Before the while case loop I did:

MPS=`grep nfs /etc/fstab | grep -v '^#' | awk '{print $2}' | tr '\n' ' '`

then commented out the /*MPS line in the case block.
Owner's reply

Version 1.6 adds the flag -a to the script, which means mountpoints are autoselected from fstab file.
So use the new version like:

check_mountpoints.sh -a

byarnotron, July 2, 2012
1 of 1 people found this review helpful
The check seems to work, but I get a warning for line 140, when I supply multiple mount points:

./check_mountpoints.sh: line 140: [: /srv/apache/etc: binary operator expected

I fixed it by quoting the variable:

if [ -z "${MPS}" ]; then
Owner's reply

fixed in version 1.6

bydeutschf3, March 20, 2012
1 of 1 people found this review helpful
Thanks, that's what I needed!
To use it with NRPE, do the following:

1. add the following to commands.cfg on the Nagios server:
"
# check mountpoints
define command {
command_name check_mountpoints
command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -p 5666 -c check_mountpoints -a $ARG1$ $ARG2$
}
"

2. Copy / move / download the plugin to the target server's plugin directory.

3. Adjust the NRPE config on the target server to be monitored:

#:nano /etc/nagios/nrpe.d/template.cfg
add:
"command[check_mountpoints]=/usr/lib/nagios/plugins/check_mountpoints.sh $ARG1$"

4. Restart the NRPE damon
#:/etc/init.d/nagios-nrpe-server restart

5. Add a service check on the nagios server..
bydraurdraur, September 7, 2011
If NFS is mounted, and connection to server is lost after, then script hangs.
NFS share is listed after mount command, but it also hangs after df -h.
Owner's reply

Hi, your were totaly right and version 1.2 should fix that problem. The "df -k", which hangs on staled NFS mountpoints is now killed after 3 seconds or whatever time you define with -T. Try the new version.

Thanks for the reply.

bylinux_samurai, July 5, 2011
1 of 1 people found this review helpful
We use Windows shared folders to mount as CIFS shares on our Linux servers for backups. The below modifications where made to get it working for our CIFS mount points. Overall, the script works as advertised, and I have tested (CentOS 5) to confirm the script properly errors when mount is not attached or if folder is moved.

CHANGES:
1. Since our mounts are CIFS, we changed all occurrences of "nfs" to "cifs".

2. Commented out section checking fstab. I would prefer to see this as a function in the script and have it be an optional check if the mount point is in fstab.
commented out:
# awk '{if ($3=="cifs"){print $2}}' /etc/fstab | grep -q ${MP} &>/dev/null
# if [ $? -ne 0 ]; then
# log "WARN: ${MP} don't exists in /etc/fstab"
# ERR_MESG[${#ERR_MESG[*]}]="${MP} don't exists in /etc/fstab"
# fi
Owner's reply

Support for CIFS is implemented now. Should work fine.

byeriqut, June 14, 2011
0 of 2 people found this review helpful
Hi everyone, I am using this plugins and I got this error:
"Unknown service Usage: check_nfs_mounts.sh [-m FILE] $NFSmountpoint [$NFSmountpoint2 ...]"

Even though after a while it displays OK status, in the next schedule the same error appears again..

I don't know what could be happened.

Please, if anyone can help me...
Owner's reply

Try the new Version. I fixed and added alot of thinks.

bynordri, March 4, 2011
2 of 2 people found this review helpful
In Debian Squeeze with NFS v4 support, partitions in /proc/mounts are show as
X.X.X.X:/path/to/remote /path/to/local nfs4 rw,...

In the script you must to change
grep -q /proc/mounts -e " ${MP} nfs " &>/dev/null
to
grep -q /proc/mounts -e " ${MP} nfs4 " &>/dev/null

And it'll work nice for you.
Owner's reply

The new Version 1.1 fix that. Thanks for the hint.

byhypnoz, December 2, 2010
0 of 2 people found this review helpful
This was a good starting point, but I think I have improved on this template, while also simplifying it. Check out my modifications.

http://dpaste.de/nGQj/

One of the things I added was a reverse check, ot see if everything mounted on the system is also listed in fstab.
Owner's reply

The link is dead :(

bymomocello, September 4, 2010
2 of 2 people found this review helpful
Nice works,
I did a modification on the file to works on debian lenny.

Comment
#LIBEXEC="/usr/local/nagios/libexec"
Replace by
LIBEXEC="/usr/lib/nagios/plugins"
Owner's reply

The new Version 1.1 fix that. Just a little late ;-) Thanks for the hint.