|
|
@ -12,6 +12,7 @@ my $output = undef; |
|
|
|
# you may want to be notified before it's reached, so you can |
|
|
|
# you may want to be notified before it's reached, so you can |
|
|
|
# set a margin which will be substracted from the real threshold |
|
|
|
# set a margin which will be substracted from the real threshold |
|
|
|
my $temp_margin = '10'; |
|
|
|
my $temp_margin = '10'; |
|
|
|
|
|
|
|
my $pwr_margin = '200'; |
|
|
|
#This value will be substracted from the higher threshold to define the low one |
|
|
|
#This value will be substracted from the higher threshold to define the low one |
|
|
|
#so you can have hysteresis to prevent flip-flop |
|
|
|
#so you can have hysteresis to prevent flip-flop |
|
|
|
my $temp_hyst = '10'; |
|
|
|
my $temp_hyst = '10'; |
|
|
@ -19,7 +20,8 @@ my $temp_hyst = '10'; |
|
|
|
GetOptions( |
|
|
|
GetOptions( |
|
|
|
"output=s" => \$output, |
|
|
|
"output=s" => \$output, |
|
|
|
"temp-margin=i" => \$temp_margin, |
|
|
|
"temp-margin=i" => \$temp_margin, |
|
|
|
"temp-hyst=i" => \$temp_hyst |
|
|
|
"pwr-margin=i" => \$pwr_margin, |
|
|
|
|
|
|
|
"temp-hyst=i" => \$temp_hyst, |
|
|
|
); |
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
sub usage(){ |
|
|
|
sub usage(){ |
|
|
@ -43,6 +45,9 @@ my $def_temp_thres_high = '50'; |
|
|
|
my $def_fan_thres_high = '1000'; |
|
|
|
my $def_fan_thres_high = '1000'; |
|
|
|
my $def_fan_thres_low = '700'; |
|
|
|
my $def_fan_thres_low = '700'; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
my $def_pwr_thres_high = '1000'; |
|
|
|
|
|
|
|
my $def_pwr_thres_low = '800'; |
|
|
|
|
|
|
|
|
|
|
|
my $cfg = new Config::Simple(syntax => 'ini'); |
|
|
|
my $cfg = new Config::Simple(syntax => 'ini'); |
|
|
|
|
|
|
|
|
|
|
|
my $sensors = {}; |
|
|
|
my $sensors = {}; |
|
|
@ -51,6 +56,7 @@ my $sensors = {}; |
|
|
|
if (-x $ipmitool){ |
|
|
|
if (-x $ipmitool){ |
|
|
|
# First check for temperature sensors |
|
|
|
# First check for temperature sensors |
|
|
|
my @lines = qx($ipmitool sdr type Temperature); |
|
|
|
my @lines = qx($ipmitool sdr type Temperature); |
|
|
|
|
|
|
|
if ($? == 0){ |
|
|
|
SENSOR: foreach my $l (@lines){ |
|
|
|
SENSOR: foreach my $l (@lines){ |
|
|
|
chomp $l; |
|
|
|
chomp $l; |
|
|
|
# Looks like |
|
|
|
# Looks like |
|
|
@ -62,6 +68,10 @@ if (-x $ipmitool){ |
|
|
|
my $sensor = {}; |
|
|
|
my $sensor = {}; |
|
|
|
|
|
|
|
|
|
|
|
my @details = qx($ipmitool sdr get '$name'); |
|
|
|
my @details = qx($ipmitool sdr get '$name'); |
|
|
|
|
|
|
|
if ($? != 0){ |
|
|
|
|
|
|
|
print "Couldn't get detail for sensor $name\n"; |
|
|
|
|
|
|
|
next SENSOR; |
|
|
|
|
|
|
|
} |
|
|
|
foreach my $d (@details){ |
|
|
|
foreach my $d (@details){ |
|
|
|
chomp $d; |
|
|
|
chomp $d; |
|
|
|
if ($d =~ m/^\s*Sensor\sReading\s*:\s*(\w+)/){ |
|
|
|
if ($d =~ m/^\s*Sensor\sReading\s*:\s*(\w+)/){ |
|
|
@ -91,22 +101,28 @@ if (-x $ipmitool){ |
|
|
|
$sensors->{$id} = $sensor; |
|
|
|
$sensors->{$id} = $sensor; |
|
|
|
print "Found a temperature sensor using IPMI: $name\n"; |
|
|
|
print "Found a temperature sensor using IPMI: $name\n"; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
# Now check for Fan, nearly the same as Temp, but |
|
|
|
# Now check for Fan, nearly the same as Temp, but |
|
|
|
# * We try to detect the unit |
|
|
|
# * We try to detect the unit |
|
|
|
# * threshold handling is not the same |
|
|
|
# * threshold handling is not the same |
|
|
|
@lines = qx($ipmitool sdr type Fan); |
|
|
|
@lines = qx($ipmitool sdr type Fan); |
|
|
|
|
|
|
|
if ($? == 0){ |
|
|
|
SENSOR: foreach my $l (@lines){ |
|
|
|
SENSOR: foreach my $l (@lines){ |
|
|
|
chomp $l; |
|
|
|
chomp $l; |
|
|
|
$l =~ m/^(\w+[\s\w]+?\w+)\s*\|.*\|\s*([\w\.\s]+)\s*\|.*\|\s*([\-\w\.\s]+)$/; |
|
|
|
$l =~ m/^(\w+[\s\w]+?\w+)\s*\|.*\|\s*([\w\.\s]+)\s*\|.*\|\s*([\-\w\.\s]+)$/; |
|
|
|
my $name = $1; |
|
|
|
my $name = $1; |
|
|
|
my $val = $3; |
|
|
|
my $value = my $val = $3; |
|
|
|
my $sensor = {}; |
|
|
|
my $sensor = {}; |
|
|
|
|
|
|
|
|
|
|
|
my @details = qx($ipmitool sdr get '$name'); |
|
|
|
my @details = qx($ipmitool sdr get '$name'); |
|
|
|
|
|
|
|
if ($? != 0){ |
|
|
|
|
|
|
|
print "Couldn't get detail for sensor $name\n"; |
|
|
|
|
|
|
|
next SENSOR; |
|
|
|
|
|
|
|
} |
|
|
|
foreach my $d (@details){ |
|
|
|
foreach my $d (@details){ |
|
|
|
chomp $d; |
|
|
|
chomp $d; |
|
|
|
if ($d =~ m/^\s*Sensor\sReading\s*:\s*(\w+)/){ |
|
|
|
if ($d =~ m/^\s*Sensor\sReading\s*:\s*(\w+)/){ |
|
|
|
my $val = $1; |
|
|
|
$val = $1; |
|
|
|
if ($val !~ m/^\d+$/){ |
|
|
|
if ($val !~ m/^\d+$/){ |
|
|
|
print "Skipping sensor $name, couldn't parse its value: $val\n"; |
|
|
|
print "Skipping sensor $name, couldn't parse its value: $val\n"; |
|
|
|
next SENSOR; |
|
|
|
next SENSOR; |
|
|
@ -125,7 +141,7 @@ if (-x $ipmitool){ |
|
|
|
$sensor->{threshold_low} =~ s/\.0+$//; |
|
|
|
$sensor->{threshold_low} =~ s/\.0+$//; |
|
|
|
$sensor->{description} = $name; |
|
|
|
$sensor->{description} = $name; |
|
|
|
$sensor->{type} = 'fan'; |
|
|
|
$sensor->{type} = 'fan'; |
|
|
|
$sensor->{unit} = ($val =~ m/percent|%/) ? '%' : 'rpm'; |
|
|
|
$sensor->{unit} = ($value =~ m/percent|%/ || $val < 100) ? '%' : 'rpm'; |
|
|
|
$sensor->{cmd} = "$ipmitool sdr get '$name' | grep 'Sensor Reading' | awk '{print \$4}'"; |
|
|
|
$sensor->{cmd} = "$ipmitool sdr get '$name' | grep 'Sensor Reading' | awk '{print \$4}'"; |
|
|
|
my $id = lc $name; |
|
|
|
my $id = lc $name; |
|
|
|
$id =~ s/\s/_/g; |
|
|
|
$id =~ s/\s/_/g; |
|
|
@ -133,6 +149,53 @@ if (-x $ipmitool){ |
|
|
|
print "Found a fan sensor using IPMI: $name\n"; |
|
|
|
print "Found a fan sensor using IPMI: $name\n"; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
# Now look for power information |
|
|
|
|
|
|
|
@lines = qx($ipmitool sdr type 'Current'); |
|
|
|
|
|
|
|
if ($? == 0){ |
|
|
|
|
|
|
|
SENSOR: foreach my $l (@lines){ |
|
|
|
|
|
|
|
chomp $l; |
|
|
|
|
|
|
|
$l =~ m/^(\w+[\s\w]+?\w+)\s*\|.*\|\s*([\w\.\s]+)\s*\|.*\|\s*([\-\w\.\s]+)$/; |
|
|
|
|
|
|
|
my $name = $1; |
|
|
|
|
|
|
|
my $val = $3; |
|
|
|
|
|
|
|
my $sensor = {}; |
|
|
|
|
|
|
|
if ($name =~ m/Power|Pwr|Consumption/i || $val =~ m/W(att)?/i){ |
|
|
|
|
|
|
|
my @details = qx($ipmitool sdr get '$name'); |
|
|
|
|
|
|
|
if ($? != 0){ |
|
|
|
|
|
|
|
print "Couldn't get detail for sensor $name\n"; |
|
|
|
|
|
|
|
next SENSOR; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
foreach my $d (@details){ |
|
|
|
|
|
|
|
chomp $d; |
|
|
|
|
|
|
|
if ($d =~ m/^\s*Sensor\sReading\s*:\s*(\w+)/){ |
|
|
|
|
|
|
|
$val = $1; |
|
|
|
|
|
|
|
if ($val !~ m/^\d+$/){ |
|
|
|
|
|
|
|
print "Skipping sensor $name, couldn't parse its value: $val\n"; |
|
|
|
|
|
|
|
next SENSOR; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
elsif ($d =~ m/^\s*Lower\scritical\s*:\s*(\d+(\.\d+))/){ |
|
|
|
|
|
|
|
$sensor->{threshold_low} = $1-$pwr_margin; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
elsif ($d =~ m/^\s*Lower\snon\-critical\s*:\s*(\d+(\.\d+))/){ |
|
|
|
|
|
|
|
$sensor->{threshold_high} = $1-$pwr_margin; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
$sensor->{threshold_high} ||= $def_pwr_thres_high; |
|
|
|
|
|
|
|
$sensor->{threshold_low} ||= $def_pwr_thres_high-$temp_hyst; |
|
|
|
|
|
|
|
$sensor->{threshold_high} =~ s/\.0+$//; |
|
|
|
|
|
|
|
$sensor->{threshold_low} =~ s/\.0+$//; |
|
|
|
|
|
|
|
$sensor->{description} = $name; |
|
|
|
|
|
|
|
$sensor->{type} = 'power'; |
|
|
|
|
|
|
|
$sensor->{unit} = 'Watt'; |
|
|
|
|
|
|
|
$sensor->{cmd} = "$ipmitool sdr get '$name' | grep 'Sensor Reading' | awk '{print \$4}'"; |
|
|
|
|
|
|
|
my $id = lc $name; |
|
|
|
|
|
|
|
$id =~ s/\s/_/g; |
|
|
|
|
|
|
|
$sensors->{$id} = $sensor; |
|
|
|
|
|
|
|
print "Found a power sensor using IPMI: $name\n"; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
# Now, try to detect smart capable HDD |
|
|
|
# Now, try to detect smart capable HDD |
|
|
|
if (-x $smartctl){ |
|
|
|
if (-x $smartctl){ |
|
|
|