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 |
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 } |
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 } |
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.