Add support for lm_sensors

tags/zabbix-agent-addons-0.2.20-1 0.2.11_el5
Daniel Berteaud 8 years ago
parent f8b1f0f4cb
commit 4d03342c5d
  1. 48
      zabbix_scripts/util_generate_sensors_ini

@ -62,6 +62,7 @@ unless ($output){
# Path # Path
my $ipmitool = which('ipmitool'); my $ipmitool = which('ipmitool');
my $smartctl = which('smartctl'); my $smartctl = which('smartctl');
my $lmsensor = which('sensors');
my $upsc = which('upsc'); my $upsc = which('upsc');
my $cfg = new Config::Simple(syntax => 'ini'); my $cfg = new Config::Simple(syntax => 'ini');
@ -232,6 +233,53 @@ if ($ipmitool && -x $ipmitool){
} }
} }
# Try to detect lm_sensors, using the sensors command
if ($lmsensor && -x $lmsensor){
print "Trying $lmsensor\n";
my @lines = qx($lmsensor);
if ($? == 0){
SENSOR: foreach my $l (@lines){
chomp $l;
# Looks like
# temp1: +27.8°C (crit = +119.0°C)
# or
# Core 0: +36.0°C (high = +80.0°C, crit = +100.0°C)
if ($l !~ m/^(\w+[\s\w]+?):\s*\+?(\d+)(\.\d+)?°C\s*(.*)$/){
next SENSOR;
}
my $name = $1;
my $val = $2;
my $thr = $4;
my $sensor = {};
if ($val !~ m/^\-?\d+$/){
print "Skipping sensor $name, couldn't parse its value: $val\n";
next SENSOR;
}
if ($thr =~ m/high\s+=\s+\+(\d+(\.\d+)?)/){
$sensor->{threshold_high} = $1;
}
elsif ($thr =~ m/^crit\s+=\s+\+(\d+(\.\d+)?)/){
$sensor->{threshold_high} = $1 - $temp_margin;
}
next SENSOR unless $val;
$sensor->{threshold_low} ||= ($sensor->{threshold_high}) ? $sensor->{threshold_high}-$temp_hyst : $def_temp_thres_high-$temp_hyst;
$sensor->{threshold_high} ||= $def_temp_thres_high;
$sensor->{threshold_high} =~ s/\.0+$//;
$sensor->{threshold_low} =~ s/\.0+$//;
$sensor->{description} = $name;
$sensor->{type} = 'temp';
$sensor->{unit} = '°C';
$sensor->{cmd} = "$lmsensor | grep '$name:' | cut -d+ -f2 | cut -d. -f1";
my $id = sensor_name($name);
$sensors->{$id} = $sensor;
print "Found a temperature sensor using lm_sensors: $name\n";
}
}
}
# Now, try to detect smart capable HDD # Now, try to detect smart capable HDD
if ($smartctl && -x $smartctl){ if ($smartctl && -x $smartctl){
foreach my $block (Zabbix::Agent::Addons::Disks::list_smart_hdd({ skip_remouvable => 1 })){ foreach my $block (Zabbix::Agent::Addons::Disks::list_smart_hdd({ skip_remouvable => 1 })){

Loading…
Cancel
Save