1<?php 2 3use Illuminate\Database\Eloquent\Builder; 4 5function 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) { 10 echo " 11 <li class='$class'>"; 12 13 if ($ent['entPhysicalClass'] == 'chassis') { 14 echo '<i class="fa fa-server fa-lg icon-theme" aria-hidden="true"></i> '; 15 } elseif ($ent['entPhysicalClass'] == 'module') { 16 echo '<i class="fa fa-database fa-lg icon-theme" aria-hidden="true"></i> '; 17 } elseif ($ent['entPhysicalClass'] == 'port') { 18 echo '<i class="fa fa-link fa-lg icon-theme" aria-hidden="true"></i> '; 19 } elseif ($ent['entPhysicalClass'] == 'container') { 20 echo '<i class="fa fa-square fa-lg icon-theme" aria-hidden="true"></i> '; 21 } elseif ($ent['entPhysicalClass'] == 'sensor') { 22 echo '<i class="fa fa-heartbeat fa-lg icon-theme" aria-hidden="true"></i> '; 23 $sensor = DeviceCache::getPrimary()->sensors()->where(function (Builder $query) use ($ent) { 24 return $query->where('entPhysicalIndex', $ent['entPhysicalIndex']) 25 ->orWhere('sensor_index', $ent['entPhysicalIndex']); 26 })->first(); 27 if ($sensor) { 28 $link = "<a href='graphs/id=" . $sensor->sensor_id . '/type=sensor_' . $sensor->sensor_class . "/' onmouseover=\"return overlib('<img src=\'graph.php?id=" . $sensor->sensor_id . '&type=sensor_' . $sensor->sensor_class . '&from=-2d&to=now&width=400&height=150&a=' . $ent['entPhysical_id'] . "\'><img src=\'graph.php?id=" . $sensor->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();\">"; 29 } 30 } elseif ($ent['entPhysicalClass'] == 'backplane') { 31 echo '<i class="fa fa-bars fa-lg icon-theme" aria-hidden="true"></i> '; 32 } elseif ($ent['entPhysicalClass'] == 'stack') { 33 echo '<i class="fa fa-list-ol fa-lg icon-theme" aria-hidden="true"></i> '; 34 } elseif ($ent['entPhysicalClass'] == 'powerSupply') { 35 echo '<i class="fa fa-bolt fa-lg icon-theme" aria-hidden="true"></i> '; 36 } 37 38 if ($ent['entPhysicalParentRelPos'] > '-1') { 39 echo '<strong>' . $ent['entPhysicalParentRelPos'] . '.</strong> '; 40 } 41 42 if (isset($link)) { 43 echo $link; 44 } 45 46 if ($ent['ifIndex']) { 47 $interface = get_port_by_ifIndex($device['device_id'], $ent['ifIndex']); 48 $interface = cleanPort($interface); 49 $ent['entPhysicalName'] = generate_port_link($interface); 50 } 51 52 if ($ent['entPhysicalModelName'] && $ent['entPhysicalName']) { 53 echo '<strong>' . $ent['entPhysicalModelName'] . '</strong> (' . $ent['entPhysicalName'] . ')'; 54 } elseif ($ent['entPhysicalModelName']) { 55 echo '<strong>' . $ent['entPhysicalModelName'] . '</strong>'; 56 } elseif (is_numeric($ent['entPhysicalName']) && $ent['entPhysicalVendorType']) { 57 echo '<strong>' . $ent['entPhysicalName'] . ' ' . $ent['entPhysicalVendorType'] . '</strong>'; 58 } elseif ($ent['entPhysicalName']) { 59 echo '<strong>' . $ent['entPhysicalName'] . '</strong>'; 60 } elseif ($ent['entPhysicalDescr']) { 61 echo '<strong>' . $ent['entPhysicalDescr'] . '</strong>'; 62 } 63 64 if ($ent['entPhysicalClass'] == 'sensor' && isset($sensor)) { 65 echo ' '; 66 echo $sensor->sensor_class == 'state' ? get_state_label($sensor->toArray()) : get_sensor_label_color($sensor->toArray()); 67 } 68 69 if (isset($link)) { 70 echo '</a>'; 71 unset($link); 72 } 73 74 // display entity state 75 $entState = dbFetchRow( 76 'SELECT * FROM `entityState` WHERE `device_id`=? && `entPhysical_id`=?', 77 [$device['device_id'], $ent['entPhysical_id']] 78 ); 79 80 if (! empty($entState)) { 81 $display_states = [ 82 // 'entStateAdmin', 83 'entStateOper', 84 'entStateUsage', 85 'entStateStandby', 86 ]; 87 foreach ($display_states as $state_name) { 88 $value = $entState[$state_name]; 89 $display = parse_entity_state($state_name, $value); 90 echo " <span class='label label-{$display['color']}' data-toggle='tooltip' title='$state_name ($value)'>"; 91 echo $display['text']; 92 echo '</span> '; 93 } 94 95 // ignore none and unavailable alarms 96 if ($entState['entStateAlarm'] != '00' && $entState['entStateAlarm'] != '80') { 97 $alarms = parse_entity_state_alarm($entState['entStateAlarm']); 98 echo '<br />'; 99 echo "<span style='margin-left: 20px;'>Alarms: "; 100 foreach ($alarms as $alarm) { 101 echo " <span class='label label-{$alarm['color']}'>{$alarm['text']}</span>"; 102 } 103 echo '</span>'; 104 } 105 } 106 107 echo "<br /><div class='interface-desc' style='margin-left: 20px;'>" . $ent['entPhysicalDescr']; 108 109 if ($ent['entPhysicalAlias'] && $ent['entPhysicalAssetID']) { 110 echo ' <br />Alias: ' . $ent['entPhysicalAlias'] . ' - AssetID: ' . $ent['entPhysicalAssetID']; 111 } elseif ($ent['entPhysicalAlias']) { 112 echo ' <br />Alias: ' . $ent['entPhysicalAlias']; 113 } elseif ($ent['entPhysicalAssetID']) { 114 echo ' <br />AssetID: ' . $ent['entPhysicalAssetID']; 115 } 116 117 if ($ent['entPhysicalSerialNum']) { 118 echo " <br /><span style='color: #000099;'>Serial No. " . $ent['entPhysicalSerialNum'] . '</span> '; 119 } 120 121 echo '</div>'; 122 123 $count = dbFetchCell("SELECT COUNT(*) FROM `entPhysical` WHERE device_id = '" . $device['device_id'] . "' AND entPhysicalContainedIn = '" . $ent['entPhysicalIndex'] . "'"); 124 if ($count) { 125 echo '<ul>'; 126 printEntPhysical($device, $ent['entPhysicalIndex'], ($level + 1), 'liClosed'); 127 echo '</ul>'; 128 } 129 130 echo '</li>'; 131 }//end foreach 132}//end printEntPhysical() 133 134echo "<div style='float: right;'> 135 <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> 136 <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> 137 </div>"; 138 139echo "<div style='clear: both;'><UL CLASS='mktree' id='enttree'>"; 140$level = '0'; 141$ent['entPhysicalIndex'] = '0'; 142printEntPhysical($device, $ent['entPhysicalIndex'], $level, 'liOpen'); 143echo '</ul></div>'; 144 145$pagetitle = 'Inventory'; 146