SOURCES: nagios-plugin-check_multipath.sh - allow running as root
glen
glen at pld-linux.org
Wed Oct 24 23:52:56 CEST 2007
Author: glen Date: Wed Oct 24 21:52:56 2007 GMT
Module: SOURCES Tag: HEAD
---- Log message:
- allow running as root
---- Files affected:
SOURCES:
nagios-plugin-check_multipath.sh (1.1 -> 1.2)
---- Diffs:
================================================================
Index: SOURCES/nagios-plugin-check_multipath.sh
diff -u SOURCES/nagios-plugin-check_multipath.sh:1.1 SOURCES/nagios-plugin-check_multipath.sh:1.2
--- SOURCES/nagios-plugin-check_multipath.sh:1.1 Wed Oct 24 23:05:54 2007
+++ SOURCES/nagios-plugin-check_multipath.sh Wed Oct 24 23:52:50 2007
@@ -14,7 +14,8 @@
. $PROGPATH/utils.sh
-MULTIPATH='/usr/bin/sudo /sbin/multipath'
+MULTIPATH=/sbin/multipath
+SUDO=/usr/bin/sudo
print_usage() {
echo "Usage:"
@@ -28,11 +29,11 @@
echo ""
echo "Check multipath status"
echo ""
- echo "really simple: runs /sbin/multipath and greps for \"failed\" paths. No options yet."
+ echo "really simple: runs $MULTIPATH and greps for \"failed\" paths. No options yet."
echo "Requires sudo."
echo ""
echo "Add this to your sudoers file by running visudo to add access:"
- echo "Cmnd_Alias MULTIPATH=/sbin/multipath -l"
+ echo "Cmnd_Alias MULTIPATH=$MULTIPATH -l"
echo "nagios ALL= NOPASSWD: MULTIPATH"
echo "The user nagios may very well be nobody or someone else depending on your configuration"
echo ""
@@ -59,15 +60,23 @@
;;
esac
-# check
-if [ `/usr/bin/sudo -l|grep -c multipath` -eq 0 ]; then
- echo "MULTIPATH: UNKNOWN - sudo not configured"
- exit $STATE_UNKNOWN
-else
- if [ -x /sbin/multipath ]; then
- MODCOUNT=`/sbin/lsmod|grep -c ^dm_multipath`
+# if not yet root, check sudo first
+if [ $(id -un) != "root" ]; then
+ if [ `$SUDO | grep -c multipath` -eq 0 ]; then
+ echo "MULTIPATH: UNKNOWN - sudo not configured"
+ exit $STATE_UNKNOWN
+ fi
+ MULTIPATH="$SUDO $MULTIPATH"
+fi
+
+ if [ ! -x /sbin/multipath ]; then
+ echo "MULTIPATH: UNKNOWN - /sbin/multipath not found"
+ exit $STATE_UNKNOWN
+ fi
+
+ MODCOUNT=`/sbin/lsmod | grep -c ^dm_multipath`
if [ $MODCOUNT -gt 0 ]; then
- PATHCOUNT=`$MULTIPATH -l|wc -l`
+ PATHCOUNT=`$MULTIPATH -l | wc -l`
if [ $PATHCOUNT -eq 0 ]; then
echo "MULTIPATH: WARNING - no paths defined"
exit $STATEWARNING
@@ -85,10 +94,5 @@
echo "MULTIPATH: UNKNOWN - module dm_multipath not loaded"
exit $STATE_UNKNOWN
fi
- else
- echo "MULTIPATH: UNKNOWN - /sbin/multipath not found"
- exit $STATE_UNKNOWN
- fi
-fi
# vim: ts=4
================================================================
---- CVS-web:
http://cvs.pld-linux.org/cgi-bin/cvsweb.cgi/SOURCES/nagios-plugin-check_multipath.sh?r1=1.1&r2=1.2&f=u
More information about the pld-cvs-commit
mailing list