#!/bin/bash
#
# Dump a binary cache of the system DMI data for 
# zabbix monitoring to read
#

# We need a version of dmidecode which supports --dump-bin & --from-dump
# for this to work / be useful, since this isn't available on el4 by default
# we'll check for it here & then check for the existance of dmidata.bin in
# the zabbix UserParameter
[ -x /usr/sbin/dmidecode ] || exit 0
for arg in dump-bin from-dump; do
	if ! /usr/sbin/dmidecode --help | grep -- "--$arg" >/dev/null 2>&1; then
		exit 0;
	fi
done

# All looks Ok, go ahead and generate the dump
CACHE=/var/cache/dmidata.bin

umask 077
TEMP=$(mktemp -q)
if [ -n "$TEMP" ] && [ -f "$TEMP" ] && [ ! -s "$TEMP" ]; then
	/usr/sbin/dmidecode -q --dump-bin "$TEMP" 2>/dev/null
	if [ -s "$TEMP" ]; then
		install -o root -g zabbix -m 0640 -Z -T "$TEMP" "$CACHE" 2>/dev/null
	fi
	rm -f -- "$TEMP"
fi
