From ea8a5ba5552a65d5ba77144c0c7a588a4d2aba88 Mon Sep 17 00:00:00 2001
From: PipoCanaja <38363551+PipoCanaja@users.noreply.github.com>
Date: Wed, 21 Jul 2021 17:08:24 +0200
Subject: [PATCH] More sensor data on inventory page (#13057)
* new display
* style
---
.../html/pages/device/entphysical.inc.php | 58 +++++++++++--------
1 file changed, 34 insertions(+), 24 deletions(-)
diff --git a/includes/html/pages/device/entphysical.inc.php b/includes/html/pages/device/entphysical.inc.php
index 98099beee3..633df569da 100644
--- a/includes/html/pages/device/entphysical.inc.php
+++ b/includes/html/pages/device/entphysical.inc.php
@@ -7,6 +7,12 @@ function printEntPhysical($device, $ent, $level, $class)
$ents = dbFetchRows('SELECT * FROM `entPhysical` WHERE device_id = ? AND entPhysicalContainedIn = ? ORDER BY entPhysicalContainedIn,entPhysicalIndex', [$device['device_id'], $ent]);
foreach ($ents as $ent) {
+ //Let's find if we have any sensors attached to the current entity;
+ //We hit this code for every type of entity because not all vendors have 1 'sensor' entity per sensor
+ $sensors = DeviceCache::getPrimary()->sensors()->where(function (Builder $query) use ($ent) {
+ return $query->where('entPhysicalIndex', $ent['entPhysicalIndex'])
+ ->orWhere('sensor_index', $ent['entPhysicalIndex']);
+ })->get();
echo "
";
@@ -20,13 +26,6 @@ function printEntPhysical($device, $ent, $level, $class)
echo ' ';
} elseif ($ent['entPhysicalClass'] == 'sensor') {
echo ' ';
- $sensor = DeviceCache::getPrimary()->sensors()->where(function (Builder $query) use ($ent) {
- return $query->where('entPhysicalIndex', $ent['entPhysicalIndex'])
- ->orWhere('sensor_index', $ent['entPhysicalIndex']);
- })->first();
- if ($sensor) {
- $link = "sensor_class . "/' onmouseover=\"return overlib('
sensor_id . '&type=sensor_' . $sensor->sensor_class . '&from=-2d&to=now&width=400&height=150&a=' . $ent['entPhysical_id'] . "\'>
sensor_id . '&type=sensor_' . $sensor->sensor_class . '&from=-2w&to=now&width=400&height=150&a=' . $ent['entPhysical_id'] . "\'>', LEFT,FGCOLOR,'#e5e5e5', BGCOLOR, '#c0c0c0', BORDER, 5, CELLPAD, 4, CAPCOLOR, '#050505');\" onmouseout=\"return nd();\">";
- }
} elseif ($ent['entPhysicalClass'] == 'backplane') {
echo ' ';
} elseif ($ent['entPhysicalClass'] == 'stack') {
@@ -39,36 +38,34 @@ function printEntPhysical($device, $ent, $level, $class)
echo '' . $ent['entPhysicalParentRelPos'] . '. ';
}
- if (isset($link)) {
- echo $link;
- }
-
+ $display_entPhysicalName = $ent['entPhysicalName'];
if ($ent['ifIndex']) {
$interface = get_port_by_ifIndex($device['device_id'], $ent['ifIndex']);
$interface = cleanPort($interface);
- $ent['entPhysicalName'] = generate_port_link($interface);
+ $display_entPhysicalName = generate_port_link($interface);
}
- if ($ent['entPhysicalModelName'] && $ent['entPhysicalName']) {
- echo '' . $ent['entPhysicalModelName'] . ' (' . $ent['entPhysicalName'] . ')';
+ if ($ent['entPhysicalModelName'] && $display_entPhysicalName) {
+ echo '' . $ent['entPhysicalModelName'] . ' (' . $display_entPhysicalName . ')';
} elseif ($ent['entPhysicalModelName']) {
echo '' . $ent['entPhysicalModelName'] . '';
} elseif (is_numeric($ent['entPhysicalName']) && $ent['entPhysicalVendorType']) {
echo '' . $ent['entPhysicalName'] . ' ' . $ent['entPhysicalVendorType'] . '';
- } elseif ($ent['entPhysicalName']) {
- echo '' . $ent['entPhysicalName'] . '';
+ } elseif ($display_entPhysicalName) {
+ echo '' . $display_entPhysicalName . '';
} elseif ($ent['entPhysicalDescr']) {
echo '' . $ent['entPhysicalDescr'] . '';
}
- if ($ent['entPhysicalClass'] == 'sensor' && isset($sensor)) {
- echo ' ';
- echo $sensor->sensor_class == 'state' ? get_state_label($sensor->toArray()) : get_sensor_label_color($sensor->toArray());
- }
-
- if (isset($link)) {
- echo '';
- unset($link);
+ // Display matching sensor value (without descr, as we have only one)
+ if ($sensors->count() == 1) {
+ foreach ($sensors as $sensor) {
+ echo "sensor_class . "/' onmouseover=\"return overlib('
sensor_id . '&type=sensor_' . $sensor->sensor_class . '&from=-2d&to=now&width=400&height=150&a=' . $ent['entPhysical_id'] . "\'>
sensor_id . '&type=sensor_' . $sensor->sensor_class . '&from=-2w&to=now&width=400&height=150&a=' . $ent['entPhysical_id'] . "\'>', LEFT,FGCOLOR,'#e5e5e5', BGCOLOR, '#c0c0c0', BORDER, 5, CELLPAD, 4, CAPCOLOR, '#050505');\" onmouseout=\"return nd();\">";
+ //echo "" . $sensor->sensor_class . ': ' . $sensor->sensor_descr . '';
+ echo ' ';
+ echo $sensor->sensor_class == 'state' ? get_state_label($sensor->toArray()) : get_sensor_label_color($sensor->toArray());
+ echo '';
+ }
}
// display entity state
@@ -118,6 +115,19 @@ function printEntPhysical($device, $ent, $level, $class)
echo "
Serial No. " . $ent['entPhysicalSerialNum'] . ' ';
}
+ // Display sensors values with their descr, as we have more than one attached to this entPhysical
+ if ($sensors->count() > 1) {
+ echo "
Sensors:";
+ foreach ($sensors as $sensor) {
+ $disp_name = str_replace([$ent['entPhysicalDescr'], $ent['entPhysicalName']], ['', ''], $sensor->sensor_descr);
+ echo "
sensor_class . "/' onmouseover=\"return overlib('
sensor_id . '&type=sensor_' . $sensor->sensor_class . '&from=-2d&to=now&width=400&height=150&a=' . $ent['entPhysical_id'] . "\'>
sensor_id . '&type=sensor_' . $sensor->sensor_class . '&from=-2w&to=now&width=400&height=150&a=' . $ent['entPhysical_id'] . "\'>', LEFT,FGCOLOR,'#e5e5e5', BGCOLOR, '#c0c0c0', BORDER, 5, CELLPAD, 4, CAPCOLOR, '#050505');\" onmouseout=\"return nd();\">";
+ echo "" . $disp_name . ' ' . $sensor->sensor_class . '';
+ echo ' ';
+ echo $sensor->sensor_class == 'state' ? get_state_label($sensor->toArray()) : get_sensor_label_color($sensor->toArray());
+ echo '';
+ }
+ echo '
';
+ }
echo '';
$count = dbFetchCell("SELECT COUNT(*) FROM `entPhysical` WHERE device_id = '" . $device['device_id'] . "' AND entPhysicalContainedIn = '" . $ent['entPhysicalIndex'] . "'");