Use sensor labels for overview/inventory pages, refactor some html-page related code (#10287)

* Refactor: use get_state_label() for the overview

* Move state translation to get_state_label()

Several html pages used similar database calls and sometimes very
different methodology to determine the state label and state text
before calling get_state_label(), so moved that part of the task
into the function itself instead of replicating the same code
multiple times on different pages.

* Move label creation to get_sensor_label_color()

Also removed a duplicate sensor class to unit function.

* Refactor some if/else statements for simplicity.

* Enable state translations for the inventory page.

* Remove blank line found at end of control structure

* Enable unit translation, fix typos.

* Change to dbFetchRow(), return string directly.

* Update functions.inc.php

* Stop displaying the raw value on state labels.

* Apply 1c7c3ca change for default case too.
This commit is contained in:
Martijn Schmidt
2019-06-27 00:30:10 -05:00
committed by Tony Murray
parent ebd004edc7
commit 9d68f27296
7 changed files with 34 additions and 141 deletions

View File

@@ -3,12 +3,7 @@
$sensors = dbFetchRows("SELECT * FROM `sensors` WHERE `device_id` = ? AND `entPhysicalIndex` = ? AND entPhysicalIndex_measured = 'ports' ORDER BY `sensor_type` ASC", array($device['device_id'],$port['ifIndex']));
foreach ($sensors as $sensor) {
$unit = get_unit_for_sensor_class($sensor['sensor_class']);
$state_translation = array();
if (($graph_type == 'sensor_state')) {
$state_translation = dbFetchRows('SELECT * FROM state_translations as ST, sensors_to_state_indexes as SSI WHERE ST.state_index_id=SSI.state_index_id AND SSI.sensor_id = ? AND ST.state_value = ? ', array($sensor['sensor_id'], $sensor['sensor_current']));
}
$unit = __('sensors.' . $sensor['sensor_class'] . '.unit');
if ($sensor['poller_type'] == 'ipmi') {
$sensor_descr = ipmiSensorName($device['hardware'], $sensor['sensor_descr']);
@@ -16,12 +11,7 @@ foreach ($sensors as $sensor) {
$sensor_descr = $sensor['sensor_descr'];
}
if (($graph_type == 'sensor_state') && !empty($state_translation['0']['state_descr'])) {
$sensor_current = get_state_label($sensor['state_generic_value'], $state_translation[0]['state_descr'] . ' (' . $sensor['sensor_current'] . ')');
} else {
$current_label = get_sensor_label_color($sensor);
$sensor_current = "<span class='label $current_label'>" . trim(format_si($sensor['sensor_current']) . $unit). '</span>';
}
$sensor_current = $graph_type == 'sensor_state' ? get_state_label($sensor) : get_sensor_label_color($sensor);
$sensor_limit = trim(format_si($sensor['sensor_limit']) . $unit);
$sensor_limit_low = trim(format_si($sensor['sensor_limit_low']) . $unit);