#!/usr/bin/bash
#
# Dump a binary cache of the system SDR (sensor) meta-data
# for zabbix monitoring to read
#

if [[ ! -c /dev/ipmi0 && ! -c /dev/ipmi/0 && ! -c /dev/ipmidev/0 ]] \
        || [[ -f /sys/hypervisor/uuid && $(head -c 3 /sys/hypervisor/uuid 2>/dev/null) == ec2 ]] \
        || [[ -f /sys/devices/virtual/dmi/id/product_uuid ]]; then
        # No IPMI available (or this is a virtual machine), at least not right now...
        exit 0
fi

IPMITOOL=$(command -v ipmitool)
[[ -n "$IPMITOOL" && -x "$IPMITOOL" ]] || exit

# All looks Ok, go ahead and generate the dump
CACHE=/var/cache/ipmitool.sdr
$IPMITOOL sdr dump $CACHE >/dev/null
chown root:zabbix $CACHE
chmod 0640 $CACHE
