nagios监控NFS是否被正确的挂载


脚本名称:check_nfsmount
脚本作用: 
    1,检查NFS磁盘是否被挂载 
    2,报告哪些NFS没有被挂载
使用方法: 
    1,将需要mount的NFS磁盘写入到fstab,如下
# cat /etc/fstab
/dev/VolGroup00/LogVol00 /                       ext3    defaults,usrquota,grpquota        1 1
LABEL=/boot             /boot                   ext3    defaults        1 2
tmpfs                   /dev/shm                tmpfs   defaults        0 0
devpts                  /dev/pts                devpts  gid=5,mode=620  0 0
sysfs                   /sys                    sysfs   defaults        0 0
proc                    /proc                   proc    defaults        0 0
/dev/VolGroup00/LogVol01 swap                    swap    defaults        0 0
192.168.211.129:/home/tst       /data/tst       nfs     defaults        0 0
192.168.211.129:/home/tst02     /data/tst02     nfs     defaults        0 0
192.168.211.129:/home/tst03     /data/tst03     nfs     defaults        0 0
    2,将脚本nagios安装目录的libexec下,并赋予可执行权限
    3,配置nrpe配置文件,添加相应的command
    4,nagios监控机上添加相应的服务
#!/bin/bash
#VERSION="1.1"
#AUTHOR by wenzizone.cn
. /usr/local/nagios/libexec/utils.sh
CHECKNAME="Mount NFS"
RESULT=""
EXIT_STATUS=$STATE_OK
NFSFSTAB=`LC_ALL=C awk '!/^#/ && $3 ~ /^nfs/ && $3 != "nfsd" && $4 !~ /noauto/ { print $1 }' /etc/fstab`
NFSMTAB=`LC_ALL=C awk '$3 ~ /^nfs/ && $3 != "nfsd" && $2 != "/" { print $1 }' /proc/mounts`
theend() {
    echo $RESULT
    exit $EXIT_STATUS
}
CHECK_MOUNT(){
    LIST=""
    for list in $NFSFSTAB
    do
        NFS_MOUNT=$(LC_ALL=C cat /proc/mounts |cut -d " " -f 1|grep "${list}$")
        if [ -z "${NFS_MOUNT}" ];then
            LIST="$LIST$list "
        fi
    done
}
if [ -n "${NFSMTAB}" ];then
    CHECK_MOUNT
    if [ -z "${LIST}" ];then
            RESULT="$CHECKNAME OK - NFS BE MOUNTED PROPERLY"
            EXIT_STATUS=$STATE_OK
    else
            RESULT="$CHECKNAME WARNING - ${LIST} NOT BE MOUNTED"
            EXIT_STATUS=$STATE_WARNING
    fi
else
    RESULT="$CHECKNAME CRITICAL - ALL NFS NOT BE MOUNTED"
    EXIT_STATUS=$STATE_CRITICAL
fi
theend