Module: check_mk
Branch: master
Commit: 90541b0c7d5ca988457327f7fedb96c04caa7f0f
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=90541b0c7d5ca9…
Author: Simon Betz <si(a)mathias-kettner.de>
Date: Fri Aug 18 13:23:37 2017 +0200
5113 FIX cifsmounts, nfsmounts: Fixed wrong reported error message if user has not right
permissions on mount point
Change-Id: I8e3eaf518034a6c6fb1d6d31796c19731461933d
---
.werks/5113 | 10 +++++
agents/check_mk_agent.aix | 20 ++++++---
agents/check_mk_agent.linux | 30 +++++++------
agents/check_mk_agent.openwrt | 22 ++++++----
checks/cifsmounts | 1 +
checks/network_fs.include | 97 ++++++++++++++++++++++++++-----------------
checks/nfsmounts | 1 +
7 files changed, 115 insertions(+), 66 deletions(-)
diff --git a/.werks/5113 b/.werks/5113
new file mode 100644
index 0000000..c0cc253
--- /dev/null
+++ b/.werks/5113
@@ -0,0 +1,10 @@
+Title: cifsmounts, nfsmounts: Fixed wrong reported error message if user has not right
permissions on mount point
+Level: 1
+Component: checks
+Compatible: compat
+Edition: cre
+Version: 1.5.0i1
+Date: 1503055157
+Class: fix
+
+
diff --git a/agents/check_mk_agent.aix b/agents/check_mk_agent.aix
index ad0996e..1a91b67 100755
--- a/agents/check_mk_agent.aix
+++ b/agents/check_mk_agent.aix
@@ -136,18 +136,26 @@ fi
# Check for hanging NFS mounts. This needs a GNU stat installed in the PATH
if type stat >/dev/null 2>&1 ; then
echo '<<<nfsmounts>>>'
- mount | grep ' nfs' | awk '{print $3;}' | \
+ mount | grep ' nfs' | awk '{print $3;}' | \
while read MP
do
- waitmax 2 stat -f -c '"'$MP' ok - - - -"' "$MP"
|| \
- echo "$MP hanging 0 0 0 0"
+ if [ ! -r $MP ]; then
+ echo "$MP Permission denied"
+ else
+ waitmax 2 stat -f -c '"'$MP' ok - - - -"'
"$MP" || \
+ echo "$MP hanging 0 0 0 0"
+ fi
done
echo '<<<cifsmounts>>>'
- mount | grep ' cifs' | awk '{print $3;}' | \
+ mount | grep ' cifs' | awk '{print $3;}' | \
while read MP
do
- waitmax 2 stat -f -c '"'$MP' ok - - - -"' "$MP"
|| \
- echo "$MP hanging 0 0 0 0"
+ if [ ! -r $MP ]; then
+ echo "$MP Permission denied"
+ else
+ waitmax 2 stat -f -c '"'$MP' ok - - - -"'
"$MP" || \
+ echo "$MP hanging 0 0 0 0"
+ fi
done
fi
diff --git a/agents/check_mk_agent.linux b/agents/check_mk_agent.linux
index caeed2a..2f5b94b 100755
--- a/agents/check_mk_agent.linux
+++ b/agents/check_mk_agent.linux
@@ -300,28 +300,32 @@ then
sed 's/\\040/ /g' |
while read MP
do
- if [ $STAT_VERSION != $STAT_BROKE ]; then
- waitmax -s 9 2 stat -f -c "$MP ok %b %f %a %s" "$MP" || \
- echo "$MP hanging 0 0 0 0"
- else
- waitmax -s 9 2 stat -f -c "$MP ok %b %f %a %s" "$MP" &&
\
- printf '\n'|| echo "$MP hanging 0 0 0 0"
- fi
+ if [ ! -r $MP ]; then
+ echo "$MP Permission denied"
+ elif [ $STAT_VERSION != $STAT_BROKE ]; then
+ waitmax -s 9 2 stat -f -c "$MP ok %b %f %a %s" "$MP" || \
+ echo "$MP hanging 0 0 0 0"
+ else
+ waitmax -s 9 2 stat -f -c "$MP ok %b %f %a %s" "$MP"
&& \
+ printf '\n'|| echo "$MP hanging 0 0 0 0"
+ fi
done
echo '<<<cifsmounts>>>'
sed -n '/ cifs\? /s/[^ ]* \([^ ]*\) .*/\1/p' < /proc/mounts |
sed 's/\\040/ /g' |
while read MP
- do
- if [ $STAT_VERSION != $STAT_BROKE ]; then
+ do
+ if [ ! -r $MP ]; then
+ echo "$MP Permission denied"
+ elif [ $STAT_VERSION != $STAT_BROKE ]; then
waitmax -s 9 2 stat -f -c "$MP ok %b %f %a %s" "$MP" ||
\
echo "$MP hanging 0 0 0 0"
- else
+ else
waitmax -s 9 2 stat -f -c "$MP ok %b %f %a %s" "$MP"
&& \
- printf '\n'|| echo "$MP hanging 0 0 0 0"
- fi
- done
+ printf '\n'|| echo "$MP hanging 0 0 0 0"
+ fi
+ done
fi
# Check mount options. Filesystems may switch to 'ro' in case
diff --git a/agents/check_mk_agent.openwrt b/agents/check_mk_agent.openwrt
index ca6838d..d8ff0ec 100755
--- a/agents/check_mk_agent.openwrt
+++ b/agents/check_mk_agent.openwrt
@@ -278,13 +278,15 @@ then
sed 's/\\040/ /g' |
while read MP
do
- if [ $STAT_VERSION != $STAT_BROKE ]; then
- waitmax -s 9 2 stat -f -c "$MP ok %b %f %a %s" "$MP" || \
- echo "$MP hanging 0 0 0 0"
- else
- waitmax -s 9 2 stat -f -c "$MP ok %b %f %a %s" "$MP" &&
\
- printf '\n'|| echo "$MP hanging 0 0 0 0"
- fi
+ if [ ! -r $MP ]; then
+ echo "$MP Permission denied"
+ if [ $STAT_VERSION != $STAT_BROKE ]; then
+ waitmax -s 9 2 stat -f -c "$MP ok %b %f %a %s" "$MP" || \
+ echo "$MP hanging 0 0 0 0"
+ else
+ waitmax -s 9 2 stat -f -c "$MP ok %b %f %a %s" "$MP"
&& \
+ printf '\n'|| echo "$MP hanging 0 0 0 0"
+ fi
done
echo '<<<cifsmounts>>>'
@@ -292,12 +294,14 @@ then
sed 's/\\040/ /g' |
while read MP
do
- if [ $STAT_VERSION != $STAT_BROKE ]; then
+ if [ ! -r $MP ]; then
+ echo "$MP Permission denied"
+ elif [ $STAT_VERSION != $STAT_BROKE ]; then
waitmax -s 9 2 stat -f -c "$MP ok %b %f %a %s" "$MP" ||
\
echo "$MP hanging 0 0 0 0"
else
waitmax -s 9 2 stat -f -c "$MP ok %b %f %a %s" "$MP"
&& \
- printf '\n'|| echo "$MP hanging 0 0 0 0"
+ printf '\n'|| echo "$MP hanging 0 0 0 0"
fi
done
fi
diff --git a/checks/cifsmounts b/checks/cifsmounts
index 08e17ce..c1e88b8 100644
--- a/checks/cifsmounts
+++ b/checks/cifsmounts
@@ -31,6 +31,7 @@
check_info["cifsmounts"] = {
+ 'parse_function': parse_network_fs_mounts,
'check_function': check_network_fs_mounts,
'inventory_function': inventory_network_fs_mounts,
'service_description': 'CIFS mount %s',
diff --git a/checks/network_fs.include b/checks/network_fs.include
index 730267e..a52dd15 100644
--- a/checks/network_fs.include
+++ b/checks/network_fs.include
@@ -28,48 +28,69 @@
# <<<...mounts>>>
# /foobar hanging 0 0 0 0
# /with spaces ok 217492 123563 112515 524288
+# /with spaces Permission denied
-def inventory_network_fs_mounts(info):
- return [ (" ".join(line[:-5]), None) for line in info ]
+def parse_network_fs_mounts(info):
+ parsed = {}
+ for line in info:
+ if " ".join(line[-2:]) == "Permission denied":
+ parsed.setdefault(" ".join(line[:-2]), {"state":
"Permission denied"})
+ else:
+ parsed.setdefault(" ".join(line[:-5]), {
+ "state": line[-5],
+ "data": line[-4:],
+ })
-def check_network_fs_mounts(item, params, info):
- for line in info:
- mountpoint = " ".join(line[:-5])
- if mountpoint == item:
- # On some operating systems there is no information about
- # used and free space, but just dashes (e.g. AIX)
- if line[-4] == '-':
- if line[-5] == 'ok':
- return 0, "mount seems OK"
- else:
- return 2, "Server not responding"
-
- size_blocks = int(line[-4])
- free_blocks = int(line[-2]) # for non-root user
- blocksize = int(line[-1])
-
- if size_blocks <= 0 or free_blocks < 0 or blocksize > 1024*1024:
- return 2, "Stale fs handle"
-
- size_bytes = size_blocks * blocksize
- free_bytes = free_blocks * blocksize
- used_bytes = size_bytes - free_bytes
- used_perc = 100.0 * used_bytes / size_bytes
- perfdata = None
- if params is not None and params.get("has_perfdata"):
- perfdata = [("fs_size", size_bytes), ("fs_used",
used_bytes)]
-
- if line[-5] == 'ok':
- if size_bytes == 0:
- return 0, "server is responding", perfdata
-
- return 0, "%.1f%% used (%s of %s)" % \
- (used_perc, get_bytes_human_readable(used_bytes),
- get_bytes_human_readable(size_bytes)), perfdata
+ return parsed
+
+
+def inventory_network_fs_mounts(parsed):
+ for mp in parsed:
+ yield mp, None
+
+
+def check_network_fs_mounts(item, params, parsed):
+ if item in parsed:
+ attrs = parsed[item]
+ state = attrs["state"]
+ data = attrs.get("data")
+
+ if state == "Permission denied" or data is None:
+ return 2, "Permissions denied"
+ size_blocks_, unused_, free_blocks_, block_size_ = data
+ if size_blocks_ == "-":
+ if state == 'ok':
+ return 0, "mount seems OK"
else:
- return 2, "server not responding", perfdata
+ return 2, "Server not responding"
+
+ size_blocks = int(size_blocks_)
+ free_blocks = int(free_blocks_) # for non-root user
+ blocksize = int(block_size_)
+
+ if size_blocks <= 0 or free_blocks < 0 or blocksize > 1024*1024:
+ return 2, "Stale fs handle"
+
+ size_bytes = size_blocks * blocksize
+ free_bytes = free_blocks * blocksize
+ used_bytes = size_bytes - free_bytes
+ used_perc = 100.0 * used_bytes / size_bytes
+ perfdata = None
+ if params is not None and params.get("has_perfdata"):
+ perfdata = [("fs_size", size_bytes), ("fs_used",
used_bytes)]
+
+ if state == 'ok':
+ if size_bytes == 0:
+ return 0, "server is responding", perfdata
+
+ return 0, "%.1f%% used (%s of %s)" % \
+ (used_perc, get_bytes_human_readable(used_bytes),
+ get_bytes_human_readable(size_bytes)), perfdata
+
+ else:
+ return 2, "server not responding", perfdata
- return 3, "not mounted"
+ return 3, "%s not mounted" % item
diff --git a/checks/nfsmounts b/checks/nfsmounts
index a9cc3eb..b9ef802 100644
--- a/checks/nfsmounts
+++ b/checks/nfsmounts
@@ -31,6 +31,7 @@
check_info["nfsmounts"] = {
+ 'parse_function' : parse_network_fs_mounts,
'check_function' : check_network_fs_mounts,
'inventory_function' : inventory_network_fs_mounts,
'service_description' : 'NFS mount %s',