#!/bin/bash
PATH="$PATH:/bin:/usr/bin:/usr/local/bin:/sbin:/usr/sbin:/usr/local/sbin"
umask 022
mkdir -p "/tmp/zabbix.ipmitool/"
temp_discovery="$(mktemp)"
chmod 644 "$temp_discovery"
(
echo -n "{\"data\":["
ipmitool sensor | awk -F '\|' '{gsub(/ /, "", $0); print $1 " " $2 " " $3 }' \
| while read sensor value type
do
if [ "${value,,}" == "na" ] ; then
rm -f "/tmp/zabbix.ipmitool/$sensor."*
else
echo -n "{\"{#SENSORNAME}\":\"$sensor\",\"{#TYPE}\":\"$type\"},"
echo "$value" > "/tmp/zabbix.ipmitool/$sensor.$type"
fi
done
echo "]}"
) | sed 's/,]}/]}/g' > "$temp_discovery"
mv "$temp_discovery" "/tmp/zabbix.ipmitool/sensor.discovery"