Module: check_mk
Branch: master
Commit: ff7ab6146060bb87784975686c789cc82ebbeca0
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=ff7ab6146060bb…
Author: Tom Baerwinkel <tb(a)mathias-kettner.de>
Date: Mon Nov 20 18:26:39 2017 +0100
5479 FIX fileinfo: handle globbing pattern expansion and whitespace in fileinfo.cfg
This werk fixes the issue that spaces and globbing patterns defined in
fileinfo.cfg were not handled correctly. Now files containing spaces
are recognized corretly and globbing patterns are expanded.
Change-Id: Ic2f710811addd8cfe008d4c45402f60f15a8c601
---
.werks/5479 | 12 ++++++++++++
agents/check_mk_agent.aix | 25 +++++++++++++++----------
agents/check_mk_agent.freebsd | 18 +++++++++++-------
agents/check_mk_agent.linux | 23 ++++++++++++-----------
agents/check_mk_agent.macosx | 18 +++++++++++-------
agents/check_mk_agent.openwrt | 18 +++++++++++-------
agents/check_mk_agent.solaris | 42 +++++++++++++++++++++++-------------------
7 files changed, 95 insertions(+), 61 deletions(-)
diff --git a/.werks/5479 b/.werks/5479
new file mode 100644
index 0000000..5612ef6
--- /dev/null
+++ b/.werks/5479
@@ -0,0 +1,12 @@
+Title: fileinfo: handle globbing pattern expansion and whitespace in fileinfo.cfg
+Level: 1
+Component: checks
+Compatible: compat
+Edition: cre
+Version: 1.5.0i2
+Date: 1511197837
+Class: fix
+
+This werk fixes the issue that spaces and globbing patterns defined in
+fileinfo.cfg were not handled correctly. Now files containing spaces
+are recognized corretly and globbing patterns are expanded.
diff --git a/agents/check_mk_agent.aix b/agents/check_mk_agent.aix
index 4031f66..532b08f 100755
--- a/agents/check_mk_agent.aix
+++ b/agents/check_mk_agent.aix
@@ -291,16 +291,21 @@ if [ -r "$MK_CONFDIR/fileinfo.cfg" ]; then
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
+ OLD_IFS=$IFS
+ IFS='
+'
+ while read -r pattern; do
+ case $pattern in
+ /*) for file in $pattern; do
+ if [ -f "$file" ]; then
+ /usr/bin/perl -e 'printf "$_|%s|%s\n", (stat) [7,9]
for @ARGV' "$file"
+ else
+ echo "$file|missing|`date +%s`"
+ fi
+ done ;;
+ esac
+ done < "$MK_CONFDIR/fileinfo.cfg"
+ IFS=$OLD_IFS
fi
# powerHA
diff --git a/agents/check_mk_agent.freebsd b/agents/check_mk_agent.freebsd
index d68df23..a944f61 100755
--- a/agents/check_mk_agent.freebsd
+++ b/agents/check_mk_agent.freebsd
@@ -380,14 +380,18 @@ fi
if [ -r "$MK_CONFDIR/fileinfo.cfg" ] ; then
echo '<<<fileinfo:sep(124)>>>'
date +%s
- for line in $(cat "$MK_CONFDIR/fileinfo.cfg")
- do
- stat -f "%N|%z|%m" "$line" 2>/dev/null
- if [ $? -ne 0 ]; then
- echo "$line|missing|$(date +%s)"
- fi
- done
+ OLD_IFS=$IFS
+ IFS='
+'
+ while read -r pattern; do
+ case $pattern in
+ /*) for file in $pattern; do
+ stat -f "%N|%z|%m" "$file" 2>/dev/null || echo
"$file|missing|`date +%s`"
+ done ;;
+ esac
+ done < "$MK_CONFDIR/fileinfo.cfg"
+ IFS=$OLD_IFS
fi
diff --git a/agents/check_mk_agent.linux b/agents/check_mk_agent.linux
index 0e08cbf..7ce4333 100755
--- a/agents/check_mk_agent.linux
+++ b/agents/check_mk_agent.linux
@@ -766,18 +766,19 @@ function replace_datevariable()
if [ -r "$MK_CONFDIR/fileinfo.cfg" ] ; then
echo '<<<fileinfo:sep(124)>>>'
date +%s
- for line in $(cat "$MK_CONFDIR/fileinfo.cfg")
- do
- # only work on lines containing files, skip e.g. comments and blank lines
- 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
+ OLD_IFS=$IFS
+ IFS='
+'
+ while read -r pattern; do
+ case $pattern in
+ /*) pattern=`replace_datevariable "$pattern"`
+ for file in $pattern; do
+ stat -c "%n|%s|%Y" "$file" 2> /dev/null ||
echo "$file|missing|`date +%s`"
+ done ;;
+ esac
+ done < "$MK_CONFDIR/fileinfo.cfg"
+ IFS=$OLD_IFS
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 a93ba28..99d5782 100755
--- a/agents/check_mk_agent.macosx
+++ b/agents/check_mk_agent.macosx
@@ -93,14 +93,18 @@ 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")
- do
- stat -f "%N|%z|%m" "$line" 2>/dev/null
- if [ $? -ne 0 ]; then
- echo "$line|missing|$(date +%s)"
- fi
- done
+ OLD_IFS=$IFS
+ IFS='
+'
+ while read -r pattern; do
+ case $pattern in
+ /*) for file in $pattern; do
+ stat -f "%N|%z|%m" "$file" 2>/dev/null || echo
"$file|missing|`date +%s`"
+ done ;;
+ esac
+ done < "$MK_CONFDIR/fileinfo.cfg"
+ IFS=$OLD_IFS
fi
if type tmutil >/dev/null
diff --git a/agents/check_mk_agent.openwrt b/agents/check_mk_agent.openwrt
index 5b10b6a..bd14ef6 100755
--- a/agents/check_mk_agent.openwrt
+++ b/agents/check_mk_agent.openwrt
@@ -681,14 +681,18 @@ fi
if [ -r "$MK_CONFDIR/fileinfo.cfg" ] ; then
echo '<<<fileinfo:sep(124)>>>'
date +%s
- for line in $(cat "$MK_CONFDIR/fileinfo.cfg")
- do
- stat -c "%n|%s|%Y" "$line" 2>/dev/null
- if [ $? -ne 0 ]; then
- echo "$line|missing|$(date +%s)"
- fi
- done
+ OLD_IFS=$IFS
+ IFS='
+'
+ while read -r pattern; do
+ case $pattern in
+ /*) for file in $pattern; do
+ stat -c "%n|%s|%Y" "$file" 2>/dev/null || echo
"$file|missing|`date +%s`"
+ done ;;
+ esac
+ done < "$MK_CONFDIR/fileinfo.cfg"
+ IFS=$OLD_IFS
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 5eda934..a27b13b 100755
--- a/agents/check_mk_agent.solaris
+++ b/agents/check_mk_agent.solaris
@@ -368,26 +368,30 @@ if [ -f "$MK_CONFDIR/fileinfo.cfg" ]
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")
- 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 [ $? -eq 0 ]; then
- echo "$file" | \
- /usr/bin/perl -e '
- while(my $file = <>) {
- $file =~ s/\n$//;
- ($device, $inode, $mode, $nlink, $uid, $gid, $rdev, $size,
$atime, $mtime, $ctime, $blksize, $blocks) = stat($file);
- print("$file|$size|$mtime\n");
- }'
- else
- echo "$file|missing|$(/usr/bin/perl -e 'print time')"
- fi
- fi
- done
+ OLD_IFS=$IFS
+ IFS='
+'
+ while read -r pattern; do
+ case $pattern in
+ /*) pattern=`replace_datevariable "$pattern"`
+ for file in $pattern; do
+ if [ -f "$file" ]; then
+ echo "$file" | /usr/bin/perl -e '
+ while(my $file = <>) {
+ $file =~ s/\n$//;
+ ($device, $inode, $mode, $nlink, $uid, $gid, $rdev,
$size,
+ $atime, $mtime, $ctime, $blksize, $blocks) =
stat($file);
+ print("$file|$size|$mtime\n");
+ }'
+ else
+ echo "$file|missing|`/usr/bin/perl -e 'print
time'`"
+ fi
+ done ;;
+ esac
+ done < "$MK_CONFDIR/fileinfo.cfg"
+ IFS=$OLD_IFS
fi
# Libelle Business Shadow