Issues (2963)

includes/html/pages/device/entphysical.inc.php (1 issue)

1
<?php
2
3
use Illuminate\Database\Eloquent\Builder;
4
5
function printEntPhysical($device, $ent, $level, $class)
6
{
7
    $ents = dbFetchRows('SELECT * FROM `entPhysical` WHERE device_id = ? AND entPhysicalContainedIn = ? ORDER BY entPhysicalContainedIn,entPhysicalIndex', [$device['device_id'], $ent]);
8
9
    foreach ($ents as $ent) {
0 ignored issues
show
$ent is overwriting one of the parameters of this function.
Loading history...
10
        //Let's find if we have any sensors attached to the current entity;
11
        //We hit this code for every type of entity because not all vendors have 1 'sensor' entity per sensor
12
        $sensors = DeviceCache::getPrimary()->sensors()->where(function (Builder $query) use ($ent) {
13
            return $query->where('entPhysicalIndex', $ent['entPhysicalIndex'])
14
                ->orWhere('sensor_index', $ent['entPhysicalIndex']);
15
        })->get();
16
        echo "
17
 <li class='$class'>";
18
19
        if ($ent['entPhysicalClass'] == 'chassis') {
20
            echo '<i class="fa fa-server fa-lg icon-theme" aria-hidden="true"></i> ';
21
        } elseif ($ent['entPhysicalClass'] == 'module') {
22
            echo '<i class="fa fa-database fa-lg icon-theme" aria-hidden="true"></i> ';
23
        } elseif ($ent['entPhysicalClass'] == 'port') {
24
            echo '<i class="fa fa-link fa-lg icon-theme" aria-hidden="true"></i> ';
25
        } elseif ($ent['entPhysicalClass'] == 'container') {
26
            echo '<i class="fa fa-square fa-lg icon-theme" aria-hidden="true"></i> ';
27
        } elseif ($ent['entPhysicalClass'] == 'sensor') {
28
            echo '<i class="fa fa-heartbeat fa-lg icon-theme" aria-hidden="true"></i> ';
29
        } elseif ($ent['entPhysicalClass'] == 'backplane') {
30
            echo '<i class="fa fa-bars fa-lg icon-theme" aria-hidden="true"></i> ';
31
        } elseif ($ent['entPhysicalClass'] == 'stack') {
32
            echo '<i class="fa fa-list-ol fa-lg icon-theme" aria-hidden="true"></i> ';
33
        } elseif ($ent['entPhysicalClass'] == 'powerSupply') {
34
            echo '<i class="fa fa-bolt fa-lg icon-theme" aria-hidden="true"></i> ';
35
        }
36
37
        if ($ent['entPhysicalParentRelPos'] > '-1') {
38
            echo '<strong>' . $ent['entPhysicalParentRelPos'] . '.</strong> ';
39
        }
40
41
        $display_entPhysicalName = $ent['entPhysicalName'];
42
        if ($ent['ifIndex']) {
43
            $interface = get_port_by_ifIndex($device['device_id'], $ent['ifIndex']);
44
            $interface = cleanPort($interface);
45
            $display_entPhysicalName = generate_port_link($interface);
46
        }
47
48
        if ($ent['entPhysicalModelName'] && $display_entPhysicalName) {
49
            echo '<strong>' . $ent['entPhysicalModelName'] . '</strong> (' . $display_entPhysicalName . ')';
50
        } elseif ($ent['entPhysicalModelName']) {
51
            echo '<strong>' . $ent['entPhysicalModelName'] . '</strong>';
52
        } elseif (is_numeric($ent['entPhysicalName']) && $ent['entPhysicalVendorType']) {
53
            echo '<strong>' . $ent['entPhysicalName'] . ' ' . $ent['entPhysicalVendorType'] . '</strong>';
54
        } elseif ($display_entPhysicalName) {
55
            echo '<strong>' . $display_entPhysicalName . '</strong>';
56
        } elseif ($ent['entPhysicalDescr']) {
57
            echo '<strong>' . $ent['entPhysicalDescr'] . '</strong>';
58
        }
59
60
        // Display matching sensor value (without descr, as we have only one)
61
        if ($sensors->count() == 1) {
62
            foreach ($sensors as $sensor) {
63
                echo "<a href='graphs/id=" . $sensor->sensor_id . '/type=sensor_' . $sensor->sensor_class . "/' onmouseover=\"return overlib('<img src=\'graph.php?id=" . $sensor->sensor_id . '&amp;type=sensor_' . $sensor->sensor_class . '&amp;from=-2d&amp;to=now&amp;width=400&amp;height=150&amp;a=' . $ent['entPhysical_id'] . "\'><img src=\'graph.php?id=" . $sensor->sensor_id . '&amp;type=sensor_' . $sensor->sensor_class . '&amp;from=-2w&amp;to=now&amp;width=400&amp;height=150&amp;a=' . $ent['entPhysical_id'] . "\'>', LEFT,FGCOLOR,'#e5e5e5', BGCOLOR, '#c0c0c0', BORDER, 5, CELLPAD, 4, CAPCOLOR, '#050505');\" onmouseout=\"return nd();\">";
64
                //echo "<span style='color: #000099;'>" . $sensor->sensor_class . ': ' . $sensor->sensor_descr . '</span>';
65
                echo ' ';
66
                echo $sensor->sensor_class == 'state' ? get_state_label($sensor->toArray()) : get_sensor_label_color($sensor->toArray());
67
                echo '</a>';
68
            }
69
        }
70
71
        // display entity state
72
        $entState = dbFetchRow(
73
            'SELECT * FROM `entityState` WHERE `device_id`=? && `entPhysical_id`=?',
74
            [$device['device_id'], $ent['entPhysical_id']]
75
        );
76
77
        if (! empty($entState)) {
78
            $display_states = [
79
                //                'entStateAdmin',
80
                'entStateOper',
81
                'entStateUsage',
82
                'entStateStandby',
83
            ];
84
            foreach ($display_states as $state_name) {
85
                $value = $entState[$state_name];
86
                $display = parse_entity_state($state_name, $value);
87
                echo " <span class='label label-{$display['color']}' data-toggle='tooltip' title='$state_name ($value)'>";
88
                echo $display['text'];
89
                echo '</span> ';
90
            }
91
92
            // ignore none and unavailable alarms
93
            if ($entState['entStateAlarm'] != '00' && $entState['entStateAlarm'] != '80') {
94
                $alarms = parse_entity_state_alarm($entState['entStateAlarm']);
95
                echo '<br />';
96
                echo "<span style='margin-left: 20px;'>Alarms: ";
97
                foreach ($alarms as $alarm) {
98
                    echo " <span class='label label-{$alarm['color']}'>{$alarm['text']}</span>";
99
                }
100
                echo '</span>';
101
            }
102
        }
103
104
        echo "<br /><div class='interface-desc' style='margin-left: 20px;'>" . $ent['entPhysicalDescr'];
105
106
        if ($ent['entPhysicalAlias'] && $ent['entPhysicalAssetID']) {
107
            echo ' <br />Alias: ' . $ent['entPhysicalAlias'] . ' - AssetID: ' . $ent['entPhysicalAssetID'];
108
        } elseif ($ent['entPhysicalAlias']) {
109
            echo ' <br />Alias: ' . $ent['entPhysicalAlias'];
110
        } elseif ($ent['entPhysicalAssetID']) {
111
            echo ' <br />AssetID: ' . $ent['entPhysicalAssetID'];
112
        }
113
114
        if ($ent['entPhysicalSerialNum']) {
115
            echo " <br /><span style='color: #000099;'>Serial No. " . $ent['entPhysicalSerialNum'] . '</span> ';
116
        }
117
118
        // Display sensors values with their descr, as we have more than one attached to this entPhysical
119
        if ($sensors->count() > 1) {
120
            echo "<br>Sensors:<div class='interface-desc' style='margin-left: 20px;'>";
121
            foreach ($sensors as $sensor) {
122
                $disp_name = str_replace([$ent['entPhysicalDescr'], $ent['entPhysicalName']], ['', ''], $sensor->sensor_descr);
123
                echo "<a href='graphs/id=" . $sensor->sensor_id . '/type=sensor_' . $sensor->sensor_class . "/' onmouseover=\"return overlib('<img src=\'graph.php?id=" . $sensor->sensor_id . '&amp;type=sensor_' . $sensor->sensor_class . '&amp;from=-2d&amp;to=now&amp;width=400&amp;height=150&amp;a=' . $ent['entPhysical_id'] . "\'><img src=\'graph.php?id=" . $sensor->sensor_id . '&amp;type=sensor_' . $sensor->sensor_class . '&amp;from=-2w&amp;to=now&amp;width=400&amp;height=150&amp;a=' . $ent['entPhysical_id'] . "\'>', LEFT,FGCOLOR,'#e5e5e5', BGCOLOR, '#c0c0c0', BORDER, 5, CELLPAD, 4, CAPCOLOR, '#050505');\" onmouseout=\"return nd();\">";
124
                echo "<span style='color: #000099;'>" . $disp_name . ' ' . $sensor->sensor_class . '</span>';
125
                echo ' ';
126
                echo $sensor->sensor_class == 'state' ? get_state_label($sensor->toArray()) : get_sensor_label_color($sensor->toArray());
127
                echo '</a><br>';
128
            }
129
            echo '</div>';
130
        }
131
        echo '</div>';
132
133
        $count = dbFetchCell("SELECT COUNT(*) FROM `entPhysical` WHERE device_id = '" . $device['device_id'] . "' AND entPhysicalContainedIn = '" . $ent['entPhysicalIndex'] . "'");
134
        if ($count) {
135
            echo '<ul>';
136
            printEntPhysical($device, $ent['entPhysicalIndex'], ($level + 1), 'liClosed');
137
            echo '</ul>';
138
        }
139
140
        echo '</li>';
141
    }//end foreach
142
}//end printEntPhysical()
143
144
echo "<div style='float: right;'>
145
       <a href='#' class='button' onClick=\"expandTree('enttree');return false;\"><i class='fa fa-plus fa-lg icon-theme'  aria-hidden='true'></i>Expand All Nodes</a>
146
       <a href='#' class='button' onClick=\"collapseTree('enttree');return false;\"><i class='fa fa-minus fa-lg icon-theme'  aria-hidden='true'></i>Collapse All Nodes</a>
147
     </div>";
148
149
echo "<div style='clear: both;'><UL CLASS='mktree' id='enttree'>";
150
$level = '0';
151
$ent['entPhysicalIndex'] = '0';
152
printEntPhysical($device, $ent['entPhysicalIndex'], $level, 'liOpen');
153
echo '</ul></div>';
154
155
$pagetitle = 'Inventory';
156