#! /usr/bin/perl # Copyright (C) 2008 Joey Schulze # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; version 2 dated June, 1991. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. # Source: http://www.infodrom.org/Infodrom/tools/munin.html # Supported configuration: # # [ipmi_fans] # user root # env.ipmitool /usr/bin/ipmitool use strict; use warnings; my $ipmitool = '/usr/bin/ipmitool'; $ipmitool = $ENV{'ipmitool'} if exists $ENV{'ipmitool'}; sub gather { my %info; return undef unless -x $ipmitool; if (open (my $ipmi, "$ipmitool sensor|")) { while (<$ipmi>) { next unless /^Fan [^|]*(\d+)\s+[^|]*\|\s+(\d+(\.\d+)?)\s+\|/; $info{$1} = $2; } close $ipmi; } return undef unless %info; return \%info; } sub descriptions { my $info = shift; my %descr; my $gotcha = 0; my $fan = 0; return undef unless -x $ipmitool; if (open (my $ipmi, "$ipmitool -v sdr|")) { while (<$ipmi>) { if (/^$/) { $gotcha = 0; next; } next unless $gotcha || /^Sensor ID\s+:\s+Fan [^|]*(\d+)\s+[^|]*/; if ($gotcha) { $descr{$fan} = $1 if /^ Entity ID\s+:\s+[^\(]*\(([^\)]*)\)/; } else { $gotcha = 1; $fan = $1; } } close $ipmi; } return undef unless %descr; return \%descr; } my $info = gather; if (@ARGV) { if ($ARGV[0] eq 'autoconf' || $ARGV[0] eq 'detect') { if ($info) { print "yes\n"; exit 0; } else { print "no\n"; exit 1; } } elsif ($ARGV[0] eq 'config') { exit unless $info; my $descr = descriptions $info; print "graph_title Fan speed\n"; print "graph_args -l 0\n"; print "graph_vlabel rpm\n"; print "graph_category sensors\n"; print "graph_info This graph shows the speed of fans active in the machine.\n"; foreach my $fan (sort keys %$info) { if (defined $descr && exists $descr->{$fan}) { printf "fan_%d.label Fan %d (%s)\n", $fan, $fan, $descr->{$fan}; } else { printf "fan_%d.label Fan %d\n", $fan, $fan; } } exit 0; } } foreach my $fan (sort keys %$info) { printf "fan_%d.value %9.2f\n", $fan, $info->{$fan}; }