Module: check_mk
Branch: master
Commit: 8be294797c5792e976ce9159ae3d115b059cfac0
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=8be294797c5792…
Author: Tom Baerwinkel <tb(a)mathias-kettner.de>
Date: Mon Oct 16 11:54:03 2017 +0200
5344 FIX fileinfo: correct handling of file names with spaces in fileinfo.cfg
Change-Id: Icdaa3afb31d14efc494e4fa99a81b13e69a98109
---
.werks/5344 | 11 +++++++++++
agents/check_mk_agent.aix | 20 ++++++++++++++------
agents/check_mk_agent.freebsd | 6 +++---
agents/check_mk_agent.linux | 8 ++++----
agents/check_mk_agent.macosx | 6 +++---
agents/check_mk_agent.openwrt | 6 +++---
agents/check_mk_agent.solaris | 13 ++++++-------
7 files changed, 44 insertions(+), 26 deletions(-)
diff --git a/.werks/5344 b/.werks/5344
new file mode 100644
index 0000000..f110ce4
--- /dev/null
+++ b/.werks/5344
@@ -0,0 +1,11 @@
+Title: fileinfo: correct handling of file names with spaces in fileinfo.cfg
+Level: 1
+Component: checks
+Class: fix
+Compatible: compat
+Edition: cre
+State: unknown
+Version: 1.5.0i1
+Date: 1508146535
+
+
diff --git a/agents/check_mk_agent.aix b/agents/check_mk_agent.aix
index dcc7a39..7632cb5 100755
--- a/agents/check_mk_agent.aix
+++ b/agents/check_mk_agent.aix
@@ -287,12 +287,20 @@ fi
# Fileinfo-Check: put patterns for files into /etc/check_mk/fileinfo.cfg
if [ -r "$MK_CONFDIR/fileinfo.cfg" ]; then
- echo '<<<fileinfo:sep(124)>>>'
- date +%s
- # simulate output of the Linux "stat -c "%n|%s|%Y" command
- # TODO: feel free to improve this command. It opens the perl interpreter for every
file found...
- for pattern in $(cat "$MK_CONFDIR/fileinfo.cfg" 2>/dev/null); do if [ -f
$pattern ]; then ls -1 "$pattern" ; fi; done |\
- while read file ; do /usr/bin/perl -e 'printf "$_|%s|%s\n", (stat) [7,9]
for @ARGV' "$file" ; done
+ echo '<<<fileinfo:sep(124)>>>'
+ date +%s
+ # simulate output of the Linux "stat -c "%n|%s|%Y" command
+ # TODO: feel free to improve this command. It opens the perl interpreter for every
file found...
+ while read pattern
+ do
+ if [ -f "$pattern" ]; then
+ ls -1 "$pattern"
+ fi
+ done < "$MK_CONFDIR/fileinfo.cfg" 2>/dev/null |\
+ while read file
+ do
+ /usr/bin/perl -e 'printf "$_|%s|%s\n", (stat) [7,9] for @ARGV'
"$file"
+ done
fi
# powerHA
diff --git a/agents/check_mk_agent.freebsd b/agents/check_mk_agent.freebsd
index 1b9a79b..3748661 100755
--- a/agents/check_mk_agent.freebsd
+++ b/agents/check_mk_agent.freebsd
@@ -380,14 +380,14 @@ fi
if [ -r "$MK_CONFDIR/fileinfo.cfg" ] ; then
echo '<<<fileinfo:sep(124)>>>'
date +%s
- for line in $(cat "$MK_CONFDIR/fileinfo.cfg")
+ while read line
do
- stat -f "%N|%z|%m" $line 2>/dev/null
+ stat -f "%N|%z|%m" "$line" 2>/dev/null
if [ $? -ne 0 ]; then
echo "$line|missing|$(date +%s)"
fi
- done
+ done < "$MK_CONFDIR/fileinfo.cfg"
fi
diff --git a/agents/check_mk_agent.linux b/agents/check_mk_agent.linux
index ec7af26..8dc40c0 100755
--- a/agents/check_mk_agent.linux
+++ b/agents/check_mk_agent.linux
@@ -764,18 +764,18 @@ function replace_datevariable()
if [ -r "$MK_CONFDIR/fileinfo.cfg" ] ; then
echo '<<<fileinfo:sep(124)>>>'
date +%s
- for line in $(cat "$MK_CONFDIR/fileinfo.cfg")
+ while read line
do
# only work on lines containing files, skip e.g. comments and blank lines
- if [ ${line:0:1} = "/" ]; then
- line="$(replace_datevariable $line)"
+ if [ "${line:0:1}" = "/" ]; then
+ line=$(replace_datevariable "$line")
stat -c "%n|%s|%Y" "${line}" 2>/dev/null
if [ $? -ne 0 ]; then
echo "$line|missing|$(date +%s)"
fi
fi
- done
+ done < "$MK_CONFDIR/fileinfo.cfg"
fi
# Get stats about OMD monitoring cores running on this machine.
diff --git a/agents/check_mk_agent.macosx b/agents/check_mk_agent.macosx
index 97ec400..73b65ee 100755
--- a/agents/check_mk_agent.macosx
+++ b/agents/check_mk_agent.macosx
@@ -93,14 +93,14 @@ netstat -ntfinet | awk ' /^tcp/ { c[$6]++; } END { for (x in c) {
print x, c[x];
if [ -r "$MK_CONFDIR/fileinfo.cfg" ] ; then
echo '<<<fileinfo:sep(124)>>>'
date +%s
- for line in $(cat "$MK_CONFDIR/fileinfo.cfg")
+ while read line
do
- stat -f "%N|%z|%m" $line 2>/dev/null
+ stat -f "%N|%z|%m" "$line" 2>/dev/null
if [ $? -ne 0 ]; then
echo "$line|missing|$(date +%s)"
fi
- done
+ done < "$MK_CONFDIR/fileinfo.cfg"
fi
if type tmutil >/dev/null
diff --git a/agents/check_mk_agent.openwrt b/agents/check_mk_agent.openwrt
index d8ff0ec..02ae32d 100755
--- a/agents/check_mk_agent.openwrt
+++ b/agents/check_mk_agent.openwrt
@@ -679,14 +679,14 @@ fi
if [ -r "$MK_CONFDIR/fileinfo.cfg" ] ; then
echo '<<<fileinfo:sep(124)>>>'
date +%s
- for line in $(cat "$MK_CONFDIR/fileinfo.cfg")
+ while read line
do
- stat -c "%n|%s|%Y" $line 2>/dev/null
+ stat -c "%n|%s|%Y" "$line" 2>/dev/null
if [ $? -ne 0 ]; then
echo "$line|missing|$(date +%s)"
fi
- done
+ done < "$MK_CONFDIR/fileinfo.cfg"
fi
# Get stats about OMD monitoring cores running on this machine.
diff --git a/agents/check_mk_agent.solaris b/agents/check_mk_agent.solaris
index 05134d1..95b4dac 100755
--- a/agents/check_mk_agent.solaris
+++ b/agents/check_mk_agent.solaris
@@ -369,15 +369,14 @@ then
echo '<<<fileinfo:sep(124)>>>'
/usr/bin/perl -e 'print time."\n"'
# note: patterns in the fileinfo.cfg are resolved inside this loop
- for file in $(cat "$MK_CONFDIR/fileinfo.cfg")
+ while read file
do
# only work on lines containing files, skip e.g. comments and blank lines
- if [ ${file:0:1} = "/" ]; then
- file="$(replace_datevariable $file)"
- ls $file > /dev/null 2>&1
-
+ if [ "${file:0:1}" = "/" ]; then
+ file=$(replace_datevariable "$file")
+ ls "$file" > /dev/null 2>&1
if [ $? -eq 0 ]; then
- echo $file | \
+ echo "$file" | \
/usr/bin/perl -e '
while(my $file = <>) {
$file =~ s/\n$//;
@@ -388,7 +387,7 @@ then
echo "$file|missing|$(/usr/bin/perl -e 'print time')"
fi
fi
- done
+ done < "$MK_CONFDIR/fileinfo.cfg"
fi
# Libelle Business Shadow