cd /tmp/
wget
use strict; # to keep things clean... er cleaner
use Socket; # to resolve host names into IP addresses
# code to clean up after forks
use POSIX ":sys_wait_h";
# nodeFile: is just a plain text file with a list of nodes:
# e.g:
# node01
# node02
# ...
# nodexx
my $nodeFile = "/usr/local/bin/nodes";
# gmetric binary
my $gmetric = "/usr/bin/gmetric";
#ipmitool binary
my $ipmi = "/usr/bin/ipmitool";
# userid for BMCs
my $u = "xcat";
# password for BMCs
my $p = "f00bar";
# open the nodes file and iterate through each node
open(FH, "$nodeFile") or die "can't open $nodeFile";
while(my $node = <FH>){
# fork so each remote data call is done in parallel
if(my $pid = fork()){
# parent process
next;
}
# child process begins here
chomp($node); # get rid of new line
# resolve node's IP address for spoofing
my $ip;
my $pip = gethostbyname($node);
if(defined $pip){
$ip = inet_ntoa($pip);
}else{
print "Can't get IP for $node!\n";
exit 1;
}
# check if the SDR cache file exists.
my $ipmiCmd;
unless(-f "/tmp/$node.sdr"){
# no SDR cache, so try to create it...
$ipmiCmd = "$ipmi -I lan -H $node-bmc -U $u -P $p sdr dump /tmp/$node.sdr";
`$ipmiCmd`;
}
if(-f "/tmp/$node.sdr"){
# run the command against the cache so that its faster
$ipmiCmd = "$ipmi -I lan -H $node-bmc -U $u -P $p -S /tmp/$node.sdr sdr type
Temperature ";
# put all the output into the @out array
my @out = `$ipmiCmd`;
# iterate through each @out entry.
foreach(@out){
# each output line looks like this:
# Ambient Temp | 32h | ok | 12.1 | 25 degrees C
# so we parse it out
chomp(); # get rid of the new line
# grap the first and 5th fields. (Description and Temp)
my ($descr, undef, undef, undef,$temp) = split(/\|/);
# get rid of white space in description
$descr =~ s/ //g;
# grap just the temp, (We assume C anyway)
$temp = (split(' ', $temp))[0];
# make sure that temperature is a number:
if($temp =~ /^\d+/ ){
#print "$node: $descr $temp\n";
my $gcmd = "$gmetric -n '$descr' -v $temp -t int16 -u Celcius -S $ip:$node";
`$gcmd`;
}
}
}
# Child Thread done and exits.
exit;
}
# wait for all forks to end...
while(waitpid(-1,WNOHANG) != -1){
1;
}