File: //usr/share/locaweb-plugins/check-mk/ipmi_sensors.sh
sdrcache=/var/cache/.freeipmi/sdr-cache/sdr-cache-$(hostname).127.0.0.1
if type ipmi-sensors >/dev/null && [ ! -e "$sdrcache" -o -s "$sdrcache" ]
then
# No cache file existing? => Impose a high time limit. We do not suffice
# in creating the cache we most probably run on a hardware where this tool
# is hanging forever. We make sure that we never try again in that case!
if [ ! -e "$sdrcache" ]
then
WAITMAX="waitmax 300"
elif tail --bytes 2 < "$sdrcache" | od -t x2 | grep -q 0a0a
then
WAITMAX="waitmax 3"
else
# Cache file corrupt. Must end with two linefeeds.
rm -f $sdrcache
WAITMAX=
fi
# Newer ipmi-sensors version have new output format; Legacy format can be used
if ipmi-sensors --help | grep -q legacy-output; then
IPMI_FORMAT="--legacy-output"
else
IPMI_FORMAT=""
fi
# Aquire lock with flock in order to avoid multiple runs of ipmi-sensors
# in case of parallel or overlapping calls of the agent.
(
flock -n 200 --wait 60
# At least with ipmi-sensoirs 0.7.16 this group is Power_Unit instead of "Power Unit"
for class in Temperature Power_Unit Fan
do
$WAITMAX ipmi-sensors $IPMI_FORMAT --sdr-cache-directory /var/cache -g "$class" | sed -e 's/ /_/g' -e 's/:_\?/ /g' -e 's@ \([^(]*\)_(\([^)]*\))@ \2_\1@'
# In case of a timeout immediately leave loop.
if [ $? = 255 ] ; then break ; fi
WAITMAX="waitmax 3"
done
) 200>>"$sdrcache"
fi