Merge pull request #2764 from vitalisator/stp

Add STP port polling and device information
This commit is contained in:
Neil Lathwood
2016-01-28 19:08:09 +00:00
7 changed files with 229 additions and 13 deletions

View File

@@ -0,0 +1,39 @@
<?php
$common_output[] = '
<div class="table-responsive">
<table id="stp-ports" class="table table-condensed table-hover">
<thead>
<tr>
<th data-column-id="port_id">Port</th>
<th data-column-id="priority">Priority</th>
<th data-column-id="state">State</th>
<th data-column-id="enable">Enable</th>
<th data-column-id="pathCost">Path cost</th>
<th data-column-id="designatedRoot">Designated root</th>
<th data-column-id="designatedCost">Designated cost</th>
<th data-column-id="designatedBridge">Designated bridge</th>
<th data-column-id="designatedPort">Designated port</th>
<th data-column-id="forwardTransitions">Forward transitions</th>
</tr>
</thead>
</table>
</div>
<script>
var grid = $("#stp-ports").bootgrid( {
ajax: true,
templates: {search: ""},
post: function ()
{
return {
id: "stp-ports",
device_id: ' . $device['device_id'] . ',
};
},
url: "ajax_table.php"
});
</script>
';

View File

@@ -1,5 +1,6 @@
<?php
echo '<table class="table table-condensed table-striped table-hover">';
$stp_raw = dbFetchRow('SELECT * FROM `stp` WHERE `device_id` = ?', array($device['device_id']));
$stp = array (
'Root bridge' => ($stp_raw['rootBridge'] == 1) ? 'Yes' : 'No',
@@ -22,8 +23,9 @@ $stp = array (
foreach (array_keys($stp) as $key) {
echo "
<tr>
<td width=280 class=list-large>$key</td>
<td class=box-desc>$stp[$key]</td>
<td>$key</td>
<td>$stp[$key]</td>
</tr>
";
}
echo '</table>';

View File

@@ -0,0 +1,57 @@
<?php
$device_id = mres($_POST['device_id']);
$param[] = $device_id;
$sql = " FROM `ports_stp` `ps` JOIN `ports` `p` ON `ps`.`port_id`=`p`.`port_id` WHERE `ps`.`device_id` = ?";
$count_sql = "SELECT COUNT(*) $sql";
$total = dbFetchCell($count_sql, $param);
if (empty($total)) {
$total = 0;
}
if (!isset($sort) || empty($sort)) {
$sort = 'port_id DESC';
}
$sql .= " ORDER BY ps.$sort";
if (isset($current)) {
$limit_low = (($current * $rowCount) - ($rowCount));
$limit_high = $rowCount;
}
if ($rowCount != -1) {
$sql .= " LIMIT $limit_low,$limit_high";
}
$sql = "SELECT `ps`.*, `p`.* $sql";
foreach (dbFetchRows($sql, array($device_id)) as $stp_ports_db) {
$bridge_device = dbFetchRow("SELECT `devices`.*, `stp`.`device_id`, `stp`.`bridgeAddress` FROM `devices` JOIN `stp` ON `devices`.`device_id`=`stp`.`device_id` WHERE `stp`.`bridgeAddress` = ?", array($stp_ports_db['designatedBridge']));
$root_device = dbFetchRow("SELECT `devices`.*, `stp`.`device_id`, `stp`.`bridgeAddress` FROM `devices` JOIN `stp` ON `devices`.`device_id`=`stp`.`device_id` WHERE `stp`.`bridgeAddress` = ?", array($stp_ports_db['designatedRoot']));
$response[] = array (
'port_id' => generate_port_link($stp_ports_db, $stp_ports_db['ifName'])."<br>".$stp_ports_db['ifAlias'],
'priority' => $stp_ports_db['priority'],
'state' => $stp_ports_db['state'],
'enable' => $stp_ports_db['enable'],
'pathCost' => $stp_ports_db['pathCost'],
'designatedRoot' => generate_device_link($root_device, $root_device['hostname'])."<br>".$stp_ports_db['designatedRoot'],
'designatedCost' => $stp_ports_db['designatedCost'],
'designatedBridge' => generate_device_link($bridge_device, $bridge_device['hostname'])."<br>".$stp_ports_db['designatedBridge'],
'designatedPort' => $stp_ports_db['designatedPort'],
'forwardTransitions' => $stp_ports_db['forwardTransitions']
);
}
$output = array(
'current' => $current,
'rowCount' => $rowCount,
'rows' => $response,
'total' => $total,
);
echo _json_encode($output);