Module: check_mk
Branch: master
Commit: 74b1be33c697cbad86b9097f6f5b1b3f847c4d16
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=74b1be33c697cb…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Tue Apr 12 17:31:22 2011 +0200
ipmi: Linux agent now (asynchronously) caches output of ipmitool for 20 minutes
---
ChangeLog | 1 +
agents/check_mk_agent.linux | 35 +++++++++++++++++++++++++++--------
2 files changed, 28 insertions(+), 8 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index fccfa61..a464543 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -75,6 +75,7 @@
* f5_bigip_vserver: status of F5 BIP/ip virtual servers
* ipmi: new configuration variable ipmi_ignored_sensors (see man page)
* hp_procurve_cpu: rename services description to CPU utilization
+ * ipmi: Linux agent now (asynchronously) caches output of ipmitool for 20 minutes
1.1.10:
diff --git a/agents/check_mk_agent.linux b/agents/check_mk_agent.linux
index c40821f..336579f 100755
--- a/agents/check_mk_agent.linux
+++ b/agents/check_mk_agent.linux
@@ -182,20 +182,39 @@ echo '<<<netctr>>>'
date +%s
sed -e 1,2d -e 's/:/ /g' < /proc/net/dev
-# IPMI-Daten (Luefter, CPU, Temperatur, etc)
-if which ipmitool >/dev/null ; then
+
+if which ipmitool >/dev/null
+then
echo '<<<ipmi>>>'
- # Transform output from |-separated into ' '-separated,
- # drop lines with no data (e.g. from non-present CPUs)
- # Columns: name value status unrec_low crit_low noncrit_low noncrit_high crit_high
unrec_high
- # Status: ok, nc (NonCritical=Warning), ??
- ipmitool sensor list \
- | grep -v 'command failed' \
+ IPMI_FILE=$MK_CONFDIR/ipmitool_sensors.cache
+ # Use cache file after 20 minutes
+ IPMI_MAXAGE=1200
+
+ # Check if file exists and recent enough
+ if [ -s $IPMI_FILE ]
+ then
+ NOW=$(date +%s)
+ MTIME=$(stat -c %Y $IPMI_FILE)
+ if [ $((NOW - MTIME)) -le $IPMI_MAXAGE ] ; then
+ USE_IPMI_FILE=1
+ fi
+ fi
+
+ if [ -s "$IPMI_FILE" ]
+ then
+ grep -v 'command failed' "$IPMI_FILE" \
| sed -e 's/ *| */|/g' -e "s/ /_/g" -e 's/_*$//' -e
's/|/ /g' \
| egrep -v '^[^ ]+ na ' \
| grep -v ' discrete '
+ fi
+
+ if [ -z "$USE_IPMI_FILE" -a ! -e "$IPMI_FILE.new" ]
+ then
+ setsid bash -c "set -o noclobber ; ipmitool sensor list > $IPMI_FILE.new
&& mv $IPMI_FILE.new $IPMI_FILE || rm -f $IPMI_FILE*" &
+ fi
fi
+
# IPMI data via ipmi-sensors (of freeipmi). Please make sure, that if you
# have installed freeipmi that IPMI is really support by your hardware.
# The agent tries to avoid hanging forever by setting a limit of 300 seconds