Module: check_mk
Branch: master
Commit: 2a7b7594461b066d4d733ab77d5b825450cd4654
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=2a7b7594461b06…
Author: Andreas Boesl <ab(a)mathias-kettner.de>
Date: Tue Nov 18 14:17:12 2014 +0100
#1439 mk-job: now also available on solaris systems
Regarding the mk-job feature itself, you can find more information
<a href="https://mathias-kettner.de/checkmk_job.html">here</a>.
---
.werks/1439 | 12 +++++++
ChangeLog | 1 +
agents/check_mk_agent.solaris | 30 +++++++++++++++--
agents/mk-job.solaris | 73 +++++++++++++++++++++++++++++++++++++++++
4 files changed, 114 insertions(+), 2 deletions(-)
diff --git a/.werks/1439 b/.werks/1439
new file mode 100644
index 0000000..51d4d76
--- /dev/null
+++ b/.werks/1439
@@ -0,0 +1,12 @@
+Title: mk-job: now also available on solaris systems
+Level: 1
+Component: core
+Compatible: compat
+Version: 1.2.5i7
+Date: 1416315864
+Class: feature
+
+Regarding the mk-job feature itself, you can find more information
+<a href="https://mathias-kettner.de/checkmk_job.html">here</a>.
+
+
diff --git a/ChangeLog b/ChangeLog
index 3398a48..d32b19d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,6 @@
1.2.5i7:
Core & Setup:
+ * 1439 mk-job: now also available on solaris systems...
* 1483 FIX: Savely replace illegal vertical bars in check plugin output...
* 1431 FIX: windows_agent: fixed error on parsing unicode formatted logfiles...
diff --git a/agents/check_mk_agent.solaris b/agents/check_mk_agent.solaris
index b5babc3..e8dac81 100755
--- a/agents/check_mk_agent.solaris
+++ b/agents/check_mk_agent.solaris
@@ -6,7 +6,7 @@
# | | |___| | | | __/ (__| < | | | | . \ |
# | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
# | |
-# | Copyright Mathias Kettner 2014 mk(a)mathias-kettner.de |
+# | Copyright Mathias Kettner 2013 mk(a)mathias-kettner.de |
# +------------------------------------------------------------------+
#
# This file is part of Check_MK.
@@ -86,7 +86,7 @@ function run_cached () {
# 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
&
+ 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
}
@@ -108,6 +108,32 @@ else
fi
+# Get statistics about monitored jobs. Below the job directory there
+# is a sub directory per user that ran a job. That directory must be
+# owned by the user so that a symlink or hardlink attack for reading
+# arbitrary files can be avoided.
+if pushd /var/lib/check_mk_agent/job >/dev/null; then
+ echo '<<<job>>>'
+ for username in *
+ do
+ if [ -d "$username" ] && cd "$username" ; then
+ count=$(su "$username" -c "ls -1 * | wc -l")
+
+ if [ "$count" -eq "1" ]; then
+ filename=$(su "$username" -c "ls -1 *")
+ echo "==> $filename <=="
+ fi
+
+ su "$username" -c "head -n1000 *"
+ cd ..
+ fi
+ done
+ popd > /dev/null
+fi
+
+
+
+
# Filesystem usage for UFS and VXFS
echo '<<<df>>>'
for fs in ufs vxfs samfs lofs
diff --git a/agents/mk-job.solaris b/agents/mk-job.solaris
new file mode 100644
index 0000000..f584b95
--- /dev/null
+++ b/agents/mk-job.solaris
@@ -0,0 +1,73 @@
+#!/bin/bash
+# +------------------------------------------------------------------+
+# | ____ _ _ __ __ _ __ |
+# | / ___| |__ ___ ___| | __ | \/ | |/ / |
+# | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
+# | | |___| | | | __/ (__| < | | | | . \ |
+# | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
+# | |
+# | Copyright Mathias Kettner 2013 mk(a)mathias-kettner.de |
+# +------------------------------------------------------------------+
+#
+# This file is part of Check_MK.
+# The official homepage is at
http://mathias-kettner.de/check_mk.
+#
+# check_mk is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation in version 2. check_mk is distributed
+# in the hope that it will be useful, but WITHOUT ANY WARRANTY; with-
+# out even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+# PARTICULAR PURPOSE. See the GNU General Public License for more de-
+# ails. You should have received a copy of the GNU General Public
+# License along with GNU Make; see the file COPYING. If not, write
+# to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
+# Boston, MA 02110-1301 USA.
+
+help() {
+ echo "Usage: mk-job IDENT PROGRAM [ARGS...]"
+ echo ""
+ echo "Execute PROGRAM as subprocess while measuring performance
information"
+ echo "about the running process and writing it to an output file. This
file"
+ echo "can be monitored using Check_MK. The Check_MK Agent will forward
the"
+ echo "information of all job files to the monitoring server."
+ echo ""
+ echo "This file is being distributed with the Check_MK Agent."
+}
+
+if [ $# -lt 2 ]; then
+ help >&2
+ exit 1
+fi
+
+MYSELF=$(id | awk -F')' '{print $1}' | awk -F'(' '{print
$2}')
+OUTPUT_PATH=/var/lib/check_mk_agent/job/$MYSELF
+IDENT=$1
+shift
+
+if [ ! -d "$OUTPUT_PATH" ]; then
+ if [ "$MYSELF" = root ] ; then
+ mkdir -p "$OUTPUT_PATH"
+ else
+ echo "ERROR: Missing output directory $OUTPUT_PATH for non-root user
'$MYSELF'." >&2
+ exit 1
+ fi
+fi
+
+if ! type $1 >/dev/null 2>&1; then
+ echo -e "ERROR: Cannot run $1. Command not found.\n" >&2
+ help >&2
+ exit 1
+fi
+
+
+echo "start_time $(perl -e 'print time')" >
"$OUTPUT_PATH/$IDENT.running"
+
+info=$((/usr/bin/time -p sh -c "$@ 2>/dev/null 1>&2" 2>&1;
echo $?) | sed -e 's/,/\./g');
+RC=$(echo $info | awk '{print $7}')
+
+(echo $info | awk '{print "exit_code "$7"\nreal_time
"$2"\nuser_time "$4"\nsystem_time "$6""}') >>
"$OUTPUT_PATH/$IDENT.running"
+(echo -e "reads 0\nwrites 0\nmax_res_kbytes 0\navg_mem_kbytes
0\ninvol_context_switches 0\nvol_context_switches 0";) >>
"$OUTPUT_PATH/$IDENT.running"
+
+mv "$OUTPUT_PATH/$IDENT.running" "$OUTPUT_PATH/$IDENT"
+exit $RC
+