#!/bin/bash

if [ "$1" == "config" ] ; then
	echo "graph_title HP server temperatures"
	echo "graph_vlabel celsius"
	echo "graph_category environment"
	echo "graph_info temperatures read using hpscan"
	echo "processor_zone.label Processor zone temperature"
	echo "io_zone.label I/O zone temperature"
	echo "processor0.label Processor 0 temperature"
	echo "processor1.label Processor 1 temperature"
	echo "psu_bay.label PSU bay temperature"
	exit 0
fi

#ID     TYPE        LOCATION      STATUS    CURRENT  THRESHOLD 
#1  ADM1022      Processor Zone  Normal   104F/ 40C 143F/ 62C 
#2  ADM1022      CPU (1)         Normal    96F/ 36C 163F/ 73C 
#3  ADM1022      I/O Zone        Normal   118F/ 48C 154F/ 68C 
#4  ADM1022      CPU (2)         Normal   127F/ 53C 163F/ 73C 
#5  ADM1022      Pwr. Supply Bay Normal    95F/ 35C 127F/ 53C 

CPUNUMBER=0

/sbin/hplog -t | ( while read a b c d e f g h i j k l m
do
	if [ "$c" == "Processor" ] ; then
		echo -n "processor_zone.value "
		echo $g | sed 's/C//'
	elif [ "$c" == "I/O" ] ; then
		echo -n "io_zone.value "
		echo $g | sed 's/C//'
	elif [ "$c" == "CPU" ] ; then
		echo -n "processor$CPUNUMBER.value "
		echo $g | sed 's/C//'
		CPUNUMBER=`expr $CPUNUMBER + 1`
	elif [ "$c" == "Pwr." ] ; then
		echo -n "psu_bay.value "
		echo $h | sed 's/C//'
	fi
	
done
)
