Module: check_mk
Branch: master
Commit: d8695e13d0cfdbfa06c420f3e6ac33935d16900f
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=d8695e13d0cfdb…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Mon Dec 2 12:04:33 2013 +0100
FIX Solaris Agent: fixed broken fileinfo section
The fileinfo section of the Solaris agent couldn't handle
more than one file in a directory. This has now been fixed.
---
.werks/12 | 9 +++
ChangeLog | 1 +
agents/check_mk_agent.solaris | 122 ++++++++++++++++++++++++++++++-----------
3 files changed, 101 insertions(+), 31 deletions(-)
diff --git a/.werks/12 b/.werks/12
new file mode 100644
index 0000000..f6c617c
--- /dev/null
+++ b/.werks/12
@@ -0,0 +1,9 @@
+Title: Solaris Agent: fixed broken fileinfo section
+Level: 1
+Component: checks
+Version: 1.2.3i7
+Date: 1385982228
+Class: fix
+
+The fileinfo section of the Solaris agent couldn't handle
+more than one file in a directory. This has now been fixed.
diff --git a/ChangeLog b/ChangeLog
index 53dc555..e02e2dc 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -44,6 +44,7 @@
* 0286 FIX: esx_vsphrere_counters.ramdisk: Better handling for non existant
ramdisks...
* 0290 FIX: winperf_processor mem.win: Handling no/empty agent responses correctly
now...
* 0293 FIX: esx_vsphere_counters_ramdisk_sizes: Handles ram disk
"ibmscratch" by default now
+ * 0012 FIX: Solaris Agent: fixed broken fileinfo section...
Multisite:
* 0001 New filters for selecting several host/service-groups at once...
diff --git a/agents/check_mk_agent.solaris b/agents/check_mk_agent.solaris
old mode 100755
new mode 100644
index 4244213..37494af
--- a/agents/check_mk_agent.solaris
+++ b/agents/check_mk_agent.solaris
@@ -27,8 +27,8 @@
export LC_ALL=C
unset LANG
-export MK_LIBDIR="/change/me"
-export MK_CONFDIR="/change/me"
+export MK_LIBDIR="/usr/lib/check_mk_agent"
+export MK_CONFDIR="/etc/check_mk"
# All executables in PLUGINSDIR will simply be executed and their
# ouput appended to the output of the agent. Plugins define their own
@@ -48,8 +48,51 @@ else
exec <&- 2>/dev/null
fi
+function file_age() {
+ /usr/bin/perl -e 'if (! -f $ARGV[0]){die
"0000000"};$mtime=(stat($ARGV[0]))[9];print ($^T-$mtime);' "$1"
+}
+
+
+
+
+# Runs a command asynchronous by use of a cache file
+function run_cached () {
+ if [ "$1" = -s ] ; then local section="echo
'<<<$2>>>' ; " ; shift ; fi
+ local NAME=$1
+ local MAXAGE=$2
+ shift 2
+ local CMDLINE="$section$@"
+
+ if [ ! -d $MK_CONFDIR/cache ]; then mkdir -p $MK_CONFDIR/cache ; fi
+ CACHEFILE="$MK_CONFDIR/cache/$NAME.cache"
+
+ # Check if the creation of the cache takes suspiciously long and return
+ # nothing if the age (access time) of $CACHEFILE.new is twice the MAXAGE
+ if [ -e "$CACHEFILE.new" ] ; then
+ AGE=$(file_age "$CACHEFILE.new")
+ if [ $AGE -ge $((MAXAGE * 2)) ] ; then
+ return
+ fi
+ fi
+
+ # Check if cache file exists and is recent enough
+ if [ -s "$CACHEFILE" ] ; then
+ AGE=$(file_age "$CACHEFILE")
+ if [ $AGE -le $MAXAGE ] ; then local USE_CACHEFILE=1 ; fi
+ # Output the file in any case, even if it is
+ # outdated. The new file will not yet be available
+ cat "$CACHEFILE"
+ fi
+
+ # Cache file outdated and new job not yet running? Start it
+ if [ -z "$USE_CACHEFILE" -a ! -e "$CACHEFILE.new" ] ; then
+ echo "set -o noclobber ; exec > $CACHEFILE.new || exit 1 ; $CMDLINE
&& mv $CACHEFILE.new $CACHEFILE || rm -f $CACHEFILE $CACHEFILE.new" | nohup
bash 2>/dev/null &
+ fi
+}
+
+
echo '<<<check_mk>>>'
-echo Version: 1.2.3i6
+echo Version: 2013.12.02
echo AgentOS: solaris
@@ -183,52 +226,69 @@ then
fi
-if cd $PLUGINSDIR 2>/dev/null
-then
- for skript in $(ls)
- do
- if [ -x "$skript" ] ; then
- ./$skript
- fi
- done
-fi
-
-
# Fileinfo-Check: put patterns for files into $MK_CONFDIR/fileinfo.cfg
if [ -f "$MK_CONFDIR/fileinfo.cfg" ]
then
echo '<<<fileinfo:sep(124)>>>'
- echo ''
- nawk 'BEGIN{print srand()}'
- file=$(ls $(cat "$MK_CONFDIR/fileinfo.cfg"))
- size=$(ls -nl $file | nawk '{print $5}')
- date=$(truss -v lstat -t lstat ls -d $file 2>&1 | nawk '/mt = /{printf
"%d\n", $9}')
- echo ${file}'|'${size}'|'${date}
+ /usr/bin/perl -e 'print time."\n"'
+ ls $(cat "$MK_CONFDIR/fileinfo.cfg") | \
+ /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");
+ }'
fi
-# Local
+
+# MK's Remote Plugin Executor
+if test -f "$MK_CONFDIR/mrpe.cfg"
+then
+ echo '<<<mrpe>>>'
+ grep -v '^ *#' "$MK_CONFDIR/mrpe.cfg" | grep -v '^ *$' | \
+ while read descr cmdline
+ do
+ OUTPUT=$($cmdline)
+ echo "$descr $? $OUTPUT"
+ done
+fi
+
+# Local checks
if cd $LOCALDIR 2>/dev/null
then
echo '<<<local>>>'
for skript in $(ls)
do
- if [ -x "$skript" ]
- then
+ if [ -x "$skript" ] ; then
./$skript
fi
done
-fi
+ # Call some plugins only every X'th second
+ for skript in [1-9]*/* ; do
+ if [ -x "$skript" ] ; then
+ run_cached local_${skript//\//\#} ${skript%/*} "$skript"
+ fi
+ done
+
+fi
-# MK's Remote Plugin Executor
-if test -f "$MK_CONFDIR/mrpe.cfg"
+# Plugins
+if cd $PLUGINSDIR 2>/dev/null
then
- echo '<<<mrpe>>>'
- grep -v '^ *#' "$MK_CONFDIR/mrpe.cfg" | grep -v '^ *$' | \
- while read descr cmdline
+ for skript in $(ls)
do
- OUTPUT=$($cmdline)
- echo "$descr $? $OUTPUT"
+ if [ -x "$skript" ] ; then
+ ./$skript
+ fi
+ done
+
+ # Call some plugins only every X'th second
+ for skript in [1-9]*/* ; do
+ if [ -x "$skript" ] ; then
+ run_cached plugins_${skript//\//\#} ${skript%/*} "$skript"
+ fi
done
fi
+