Home Directory Plugins System Metrics File System check mountpoints like nfs, cifs, davfs, lustre, ocf2, etc.

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

Directory Tree

check mountpoints like nfs, cifs, davfs, lustre, ocf2, etc.

Rating
27 votes
Favoured:
6
Current Version
2.6
Last Release Date
2021-11-26
Compatible With
  • Nagios 3.x
Owner
License
MPL
Hits
167100
Files:
FileDescription
check_mountpoints.shcheck_mountpoints.sh
Nagios CSP

Meet The New Nagios Core Services Platform

Built on over 25 years of monitoring experience, the Nagios Core Services Platform provides insightful monitoring dashboards, time-saving monitoring wizards, and unmatched ease of use. Use it for free indefinitely.

Monitoring Made Magically Better

  • Nagios Core on Overdrive
  • Powerful Monitoring Dashboards
  • Time-Saving Configuration Wizards
  • Open Source Powered Monitoring On Steroids
  • And So Much More!
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 7 8, CentOS 5 6 7 8
Solaris
FreeBSD

# changes 2.6
# - check only dataset type filesystem on zfs
# changes 2.5
# - add -E flag to exclude path
# - add yas3fs
# changes 2.4
# - add support for ext2
# changes 2.3
# - add support for btrfs
...
See script or github for full list of changes.
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)
-L Allow softlinks to be accepted instead of mount points
-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)
-E PATH Use with -a or -A to exclude a path from fstab. Use '|' between paths for multiple. (default: unset)
-o When autoselecting mounts from fstab, ignore mounts having
noauto flag. (default: unset)
-w Writetest. Touch file $mountpoint/.mount_test_from_$(hostname) (default: unset)
-e ARGS Extra arguments for df (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 (22)
Hello! Thanks for writing this.

I'm having an issue. When I run the plugin locally with -a, everything reports OK. When I run the command on nagios server via nrpe I get a CRITICAL error. Its almost like its checking for those paths on the nagios server instead of the remote host:

Nagios server:
check_nrpe -H myhost.mydomain.com -c check_mounts
CRITICAL: /mnt/testmnt doesn't exist on filesystem ;

Command from nrpe_local.cfg:
command[check_mounts]=/usr/lib/nagios/plugins/check_mountpoints.sh /mnt/testmnt

Result running command manually on remote host:

/usr/lib/nagios/plugins/check_mountpoints.sh /mnt/testmnt
OK: all mounts were found ( /mnt/testmnt )

Any ideas?
bywurlog, July 6, 2020
works with btrfs over iscsi
bystauraum, October 12, 2017
Was is wrong here?! :-O

root@nfsclnt ~ # grep -i nfsserver /etc/vfstab
nfsserver:/mnt - /mnt nfs - yes rw,xattr

root@nfsclnt ~ # grep -i nfsserver /etc/mnttab
nfsserver:/mnt /mnt nfs rw,xattr,dev=9300001 1507803587

root@nfsclnt ~ # ./check_mountpoints.sh /mnt
CRITICAL: /mnt is not mounted ;
Thanks for this plugin, it works great on local Nagios server.

When checking shares on a remote host I get :
"(Return code of 127 is out of bounds - plugin may be missing) "

The help file does not show there is a -H option, so was wondering if you plan to implement this, or if you can tell what I am doing wrong.
Owner's reply

The plugin is designed to be used with nrpe. So it has to be executed on the machine that is checked.

bybelgotux, June 1, 2015
1 of 1 people found this review helpful
For me it works great with CIFS mount on CentOS host
byjkissner, May 9, 2014
1 of 1 people found this review helpful
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.

Page 1 of 2