• Photos Photos
  • Linked In Linked In
  • Google + Google +
  • Facebook Facebook
  • Flickr Flickr
  • Vimeo Vimeo

www.gavinwill.me.uk

Photography, IT, Bikes and more.

  • Pages

    • About
    • Blog
    • Contact
    • Home
  • Archives

    • January 2013
    • September 2012
    • August 2012
    • July 2012
    • June 2012
    • May 2012
    • April 2012
    • March 2012
    • February 2012
    • January 2012
    • December 2011
    • November 2011
  • Search:

Posts

  • View Archive

Simple Nagios Check for Windows Share Mount in Linux

I had a requirement to ensure that a linux server was mounted to a windows share that was used for backups. Adding this check into Nagios was incredibly easy with a custom script and use the check_by_ssh command.

First I needed to create a script that would check if the mountpoint existed and then report back an exit code of 2 if it is mounted and an exit code of 0 if it was not mounted so Nagios can report accordingly.

 
test "`mount | grep windows.share`" ==  ""
if [ $? == 0 ]; then
echo " Windows Share Not Mounted.  Backups will fail "
exit 2
 
else
echo " Windows Share Mounted "
exit 0
fi

test "`mount | grep windows.share`" == "" if [ $? == 0 ]; then echo " Windows Share Not Mounted. Backups will fail " exit 2 else echo " Windows Share Mounted " exit 0 fi

This script was then saved in /usr/local/bin as check_mount.sh and made executable.

On the Nagios Server I then created the simple custom command to run this script.

##############################################################################
# CUSTOM Check Linux Mounted to Backup Drive
#
##############################################################################
 
define command{
command_name    check_mount
command_line $USER1$/check_by_ssh -H $HOSTADDRESS$ -t 45 -C /usr/local/bin/check_mount.sh
}

############################################################################## # CUSTOM Check Linux Mounted to Backup Drive # ############################################################################## define command{ command_name check_mount command_line $USER1$/check_by_ssh -H $HOSTADDRESS$ -t 45 -C /usr/local/bin/check_mount.sh }

Finally you then need to define the service for the check to occur.

define service{
        use generic-service
        host_name remoteserver
        service_description Backup Drive Mounted
        check_command check_mount
}

define service{ use generic-service host_name remoteserver service_description Backup Drive Mounted check_command check_mount }

With the command now defined it is really easy to add any further monitoring of other linux servers that have a windows share mounted by simply copying the script over, amending it to suit and adding the extra host to the service description.

  • August 10, 2012
  • IT & Computing, Linux
  • 0
Cancel Reply

Copyright © 2021 www.gavinwill.me.uk.

  • LinkedIn
  • Google +
  • Facebook
  • Flickr
  • Vimeo
Back to Top