#!/bin/bash

# Beware: this is a draft and not yet tested. Use this as datasource_program
# for a host that is an DELL iDrac remote management interface.

HOST=$1
USERNAME=$2
PASSWORD=$3

echo '<<<check_mk>>>'
echo 'Version: ipmi 1.0'
echo 'AgentOS: IPMI'

if which ipmi-sensors >/dev/null 2>&1
then
    echo '<<<ipmi_sensors>>>'
    ipmi-sensors -h $1 -u $2 -p $3 -l USER -Q --ignore-not-available-sensors --legacy-output \
       | sed -e 's/ /_/g' -e 's/:_\?/ /g' -e 's@ \([^(]*\)_(\([^)]*\))@ \2_\1@' ; test ${PIPESTATUS[0]} -eq 0
else
    echo '<<<ipmi>>>'
    ipmitool -i lan -H "$HOST" -U "$USERNAME" -f "$PASSWORD" sensor show 2>/dev/null \
       | grep -v 'command failed' \
       | sed -e 's/ *| */|/g' -e 's/ /_/g' -e 's/_*"'$'"//' -e 's/|/ /g' \
       | egrep -v '^[^ ]+ na ' \
       | grep -v ' discrete '
fi
