check-nfs-hang.sh: Added script to monitor NFS mount health
authorMegaBrutal <code+git@megabrutal.com>
Sat, 5 Nov 2016 22:20:40 +0000 (23:20 +0100)
committerMegaBrutal <code+git@megabrutal.com>
Sat, 5 Nov 2016 22:20:40 +0000 (23:20 +0100)
The check-nfs-hang.sh script alerts when the monitored network file system
is not mounted or hanging. Similarly to check-fs-usage.sh, it may be
scheduled with cron, and sends e-mail when an e-mail address is supplied.

By the way, check-fs-usage.sh has been moved to the more appropriate
"fs" directory.

renamed:    host/check-fs-usage.sh -> fs/check-fs-usage.sh
new file:   fs/check-nfs-hang.sh

fs/check-fs-usage.sh [new file with mode: 0755]
fs/check-nfs-hang.sh [new file with mode: 0755]
host/check-fs-usage.sh [deleted file]

diff --git a/fs/check-fs-usage.sh b/fs/check-fs-usage.sh
new file mode 100755 (executable)
index 0000000..3b7cd8d
--- /dev/null
@@ -0,0 +1,24 @@
+#!/bin/sh
+
+if [ $# -lt 2 ]
+then
+       echo "Usage: $0 <fs> <percentage> [email]"
+       echo "Where"
+       echo "  fs              - file system to check"
+       echo "  percentage      - acceptable file system usage treshold"
+       echo "  email           - send warning to specified e-mail address (print to stdout, if omitted)"
+       echo "Example: $0 / 95 admin@cutekittens.tld"
+       exit
+fi
+
+if [ $(df -m $1 | sed 1d | awk '{print $5}' | sed "s/%//") -ge $2 ]
+then
+       subject="WARNING! File system usage ($1) on $(hostname) is higher than $2 percent!"
+       if [ -z "$3" ]
+       then
+               echo ${subject}
+               df -m
+       else
+               df -m | mail -s "${subject}" $3
+       fi
+fi
diff --git a/fs/check-nfs-hang.sh b/fs/check-nfs-hang.sh
new file mode 100755 (executable)
index 0000000..f50cc85
--- /dev/null
@@ -0,0 +1,52 @@
+#!/bin/sh
+
+if [ $# -lt 1 ]
+then
+       echo "Usage: $0 <fs> [email]"
+       echo "Where"
+       echo "  fs              - file system to check"
+       echo "  email           - send warning to specified e-mail address (print to stdout, if omitted)"
+       echo "Example: $0 /srv/remoteshare admin@cutekittens.tld"
+       exit 1
+fi
+
+make_command()
+{
+       if [ -z "$1" ]
+       then
+               echo "cat"
+       else
+               echo "mail -s \"$subject\" $1"
+       fi
+}
+
+if ! mount | grep "on $1 type nfs" > /dev/null
+then
+       subject="WARNING! Network file system ($1) on $(hostname) is not mounted!"
+
+       [ -z "$2" ] && echo "${subject}"
+       CMD=$(make_command "$2")
+       eval ${CMD} << EOT
+This is to inform you that no NFS is mounted at $1.
+Please investigate immediately!
+EOT
+exit 2
+
+elif ! timeout 15 stat "$1" > /dev/null
+then
+       subject="WARNING! Network file system ($1) on $(hostname) is hanging/unreachable!"
+
+       [ -z "$2" ] && echo "${subject}"
+       CMD=$(make_command "$2")
+       eval ${CMD} << EOT
+This is to inform you that network share $1 is hanging/unreachable.
+
+Mount details:
+
+$(mount | grep "$1")
+
+Please investigate immediately!
+EOT
+exit 3
+
+fi
diff --git a/host/check-fs-usage.sh b/host/check-fs-usage.sh
deleted file mode 100755 (executable)
index 3b7cd8d..0000000
+++ /dev/null
@@ -1,24 +0,0 @@
-#!/bin/sh
-
-if [ $# -lt 2 ]
-then
-       echo "Usage: $0 <fs> <percentage> [email]"
-       echo "Where"
-       echo "  fs              - file system to check"
-       echo "  percentage      - acceptable file system usage treshold"
-       echo "  email           - send warning to specified e-mail address (print to stdout, if omitted)"
-       echo "Example: $0 / 95 admin@cutekittens.tld"
-       exit
-fi
-
-if [ $(df -m $1 | sed 1d | awk '{print $5}' | sed "s/%//") -ge $2 ]
-then
-       subject="WARNING! File system usage ($1) on $(hostname) is higher than $2 percent!"
-       if [ -z "$3" ]
-       then
-               echo ${subject}
-               df -m
-       else
-               df -m | mail -s "${subject}" $3
-       fi
-fi