#!/usr/bin/perl -w
#
# Plugin to measure the temperature of a powerpc CPU.
#
# Pierre Bauduin <pierre@baudu.in>
#
# This works (at least) on Apple computers based on the powerpc CPU
# This means machines including:
#	PowerMacintosh
#	PowerBook
#	iBook
#	iMac (G3, G4, G5) but of course *not* the iMac based on Intel CPU
#
# $Log$
# Revision 0.2  2007/04/21 14:00:07 
#
# Magic markers - optional - used by installation scripts and
# munin-config:
#
#%# family=manual
#%# capabilities=autoconf

# Vérifions que nous sommes bien en architecture powerpc
$uname = `uname -m`;

unless ($uname =~ /ppc/)
    {
    die ("Sorry, this script is for the PowerPC architecture only\n");
    }

if ( $ARGV[0] and $ARGV[0] eq "autoconf")
{
	print "yes\n";
	exit 0;
}


if ( $ARGV[0] and $ARGV[0] eq "config" )
{
    print "graph_title CPU Temperature\n";
    print "graph_args --base 1000 -l 0\n";
    print "graph_vlabel Celsius\n";
    print "graph_category sensors\n";
    print "graph_info This graph shows the temperature in degrees Celsius of the powerpc CPU\n";
    print "cputemp.label CPU Temp\n";
    exit 0;
}


$maligne=`/bin/grep temperature /proc/cpuinfo`;

# Je substitue:
# espaces:
$maligne =~ s/\ \ */ /g;
# moins:
$maligne =~ s/\-/ /g;

# Je splitte
@data = split(/ /, $maligne);

# La température, c'est la première valeur du split
if ($data[2] eq "")
	{
        printf STDERR "ERROR: Could not find CPU temperature !\n";
        printf STDERR "       Are you sure this is a powerpc machine ?\n";
	exit
	}
else
	{
	$temperature=sprintf("%d",$data[2]);
        print "cputemp.value $temperature\n";
	}

