diff --git a/conf/sensors.conf b/conf/sensors.conf index 35b9b60..7ad52fb 100644 --- a/conf/sensors.conf +++ b/conf/sensors.conf @@ -1,7 +1,9 @@ # You can configure here the sensors -# Format is =!! +# Format is =!!! # An alert is triggerd if the temperature is above the high threshold # The alert is cleared if the temperature is less than low threshold +# the last field (sensor type) is optional and defaults to temp +# It's used if you want to monitor other sensors, like fan, or power # Example: # # @@ -9,6 +11,9 @@ # cpu0 = /usr/bin/ipmitool sdr get 'P1 Therm Margin' | grep 'Sensor Reading' | cut -d':' -f 2 | awk '{print$1}'!-30!-39 # mb = /usr/bin/ipmitool sdr get 'Baseboard Temp' | grep 'Sensor Reading' | cut -d':' -f 2 | awk '{print$1}'!50!45 # +# fan1 = fan1a=/usr/bin/ipmitool sdr get 'Fan1A RPM' | grep 'Sensor Reading' | cut -d':' -f 2 | awk '{print$1}'!0!0!fan +# pwr1=/usr/bin/ipmitool sdr get 'Pwr Consumption' | grep 'Sensor Reading' | cut -d':' -f 2 | awk '{print$1}'!0!0!power +# ## Examples with smartctl # sda = /usr/sbin/smartctl -a /dev/sda | grep Temperature_Celsius | awk '{print $10}'!45!40 # sdb = /usr/sbin/smartctl -a /dev/sdb | grep Temperature_Celsius | awk '{print $10}'!45!50 diff --git a/zabbix_conf/sensors.conf b/zabbix_conf/sensors.conf index 341aa6d..c9a4a1e 100644 --- a/zabbix_conf/sensors.conf +++ b/zabbix_conf/sensors.conf @@ -1,6 +1,6 @@ # Sensors discovery # See /etc/zabbix/sensors.conf -UserParameter=hardware.sensor.discovery,/var/lib/zabbix/bin/disco_sensors +UserParameter=hardware.sensor.discovery[*],/var/lib/zabbix/bin/disco_sensors --type=$1 # Sensors UserParameter=hardware.sensor[*],/usr/bin/sudo /var/lib/zabbix/bin/check_sensors_sudo $1 $2 diff --git a/zabbix_scripts/check_sensors_sudo b/zabbix_scripts/check_sensors_sudo index 2c5d4f0..42c1b7e 100644 --- a/zabbix_scripts/check_sensors_sudo +++ b/zabbix_scripts/check_sensors_sudo @@ -1,7 +1,6 @@ #!/usr/bin/perl -w my $what = $ARGV[0]; -my $thres = $ARGV[1]; unless (defined $what){ usage(); @@ -14,23 +13,9 @@ open SENSORS, ('){ - next unless (/^$what(\s+)?=(\s+)?(.*)!(\-?\d+)!(\-?\d+)$/); + next unless (/^$what(\s+)?=(\s+)?(.*)!(\-?\d+)!(\-?\d+)(!(\w+))?$/); my $cmd = $3; - my $high = $4; - my $low = $5; - if (!defined $thres){ - $ret = `$cmd`; - } - elsif ($thres eq 'high'){ - $ret = $high - } - elsif ($thres eq 'low'){ - $ret = $low; - } - else { - usage(); - exit(1); - } + $ret = `$cmd`; } print $ret; exit(0); diff --git a/zabbix_scripts/disco_sensors b/zabbix_scripts/disco_sensors index b941d9a..dba1cff 100644 --- a/zabbix_scripts/disco_sensors +++ b/zabbix_scripts/disco_sensors @@ -1,6 +1,16 @@ #!/usr/bin/perl -w use JSON; +use Getopt::Long; + +my $sensor_type = 'temp'; +GetOptions( + "type:s" => \$sensor_type +); + +# empty means temp +$sensor_type = ($sensor_type eq '') ? 'temp' : $sensor_type; + my $json; @{$json->{data}} = (); @@ -9,14 +19,18 @@ open SENSORS, ('){ - next unless (/^(\w+)(\s+)?=(\s+)?(.*)!(\-?\d+)!(\-?\d+)$/); - my ($sensor,$threshigh,$threslow) = ($1,$5,$6); + next unless (/^(\w+)(\s+)?=(\s+)?(.*)!(\-?\d+)!(\-?\d+)(!(\w+))?$/); + my ($sensor,$threshigh,$threslow,$type) = ($1,$5,$6,$8); + $type ||= 'temp'; + next if ($sensor_type ne 'all' && $type ne $sensor_type); push @{$json->{data}}, { - "{#SENSORNAME}" => $sensor, + "{#SENSORNAME}" => $sensor, "{#SENSORTHRESHIGH}" => $threshigh, - "{#SENSORTHRESLOW}" => $threslow + "{#SENSORTHRESLOW}" => $threslow, + "{#SENSORTYPE}" => $type }; } close SENSORS; print to_json($json); exit(0); +