Merge pull request #4525 from murrant/port-lastchanged

feature: Add last changed, connected, and mtu to all ports data
This commit is contained in:
Neil Lathwood
2016-09-21 19:56:15 +01:00
committed by GitHub
4 changed files with 42 additions and 14 deletions

View File

@@ -102,6 +102,8 @@ if (isset($sort) && !empty($sort)) {
$sql .= " ORDER BY `D`.`hostname` $sort_order";
} elseif ($sort_column == 'port') {
$sql .= " ORDER BY `ifDescr` $sort_order";
} elseif ($sort_column == 'ifLastChange') {
$sql .= " ORDER BY `secondsIfLastChange` $sort_order";
} else {
$sql .= " ORDER BY `$sort_column` $sort_order";
}
@@ -116,9 +118,12 @@ if ($rowCount != -1) {
$sql .= " LIMIT $limit_low,$limit_high";
}
$sql = "SELECT DISTINCT(`ports`.`port_id`),`ports`.* $sql";
$query = 'SELECT DISTINCT(`ports`.`port_id`),`ports`.*';
// calculate ifLastChange as seconds ago
$query .= ',`D`.`uptime` - `ports`.`ifLastChange` / 100 as secondsIfLastChange ';
$query .= $sql;
foreach (dbFetchRows($sql, $param) as $port) {
foreach (dbFetchRows($query, $param) as $port) {
$device = device_by_id_cache($port['device_id']);
// FIXME what actions should we have?
@@ -138,7 +143,10 @@ foreach (dbFetchRows($sql, $param) as $port) {
$response[] = array(
'device' => generate_device_link($device),
'port' => generate_port_link($port),
'ifLastChange' => ceil($port['secondsIfLastChange']),
'ifConnectorPresent' => ($port['ifConnectorPresent'] == 'true') ? 'yes' : 'no',
'ifSpeed' => $port['ifSpeed'],
'ifMtu' => $port['ifMtu'],
'ifInOctets_rate' => $port['ifInOctets_rate'] * 8,
'ifOutOctets_rate' => $port['ifOutOctets_rate'] * 8,
'ifInUcastPkts_rate' => $port['ifInUcastPkts_rate'],

View File

@@ -18,11 +18,14 @@ if ($vars['errors']) {
<tr>
<th data-column-id="device">Device</th>
<th data-column-id="port"<?php echo $sort ?>>Port</th>
<th data-column-id="ifSpeed" data-formatter="human-bps">Speed</th>
<th data-column-id="ifInOctets_rate" data-searchable="false" data-css-class="green" data-formatter="human-bps">Down</th>
<th data-column-id="ifOutOctets_rate" data-searchable="false" data-css-class="blue" data-formatter="human-bps">Up</th>
<th data-column-id="ifInUcastPkts_rate" data-searchable="false" data-visible="<?php echo $details_visible ?>" data-css-class="green" data-formatter="human-pps">Packets In</th>
<th data-column-id="ifOutUcastPkts_rate" data-searchable="false" data-visible="<?php echo $details_visible ?>" data-css-class="blue" data-formatter="human-pps">Packets Out</th>
<th data-column-id="ifLastChange" data-converter="duration">Status Changed</th>
<th data-column-id="ifConnectorPresent" data-visible="false">Connected</th>
<th data-column-id="ifSpeed" data-converter="human-bps">Speed</th>
<th data-column-id="ifMtu" data-visible="false">MTU</th>
<th data-column-id="ifInOctets_rate" data-searchable="false" data-css-class="green" data-converter="human-bps">Down</th>
<th data-column-id="ifOutOctets_rate" data-searchable="false" data-css-class="blue" data-converter="human-bps">Up</th>
<th data-column-id="ifInUcastPkts_rate" data-searchable="false" data-visible="<?php echo $details_visible ?>" data-css-class="green" data-converter="human-pps">Packets In</th>
<th data-column-id="ifOutUcastPkts_rate" data-searchable="false" data-visible="<?php echo $details_visible ?>" data-css-class="blue" data-converter="human-pps">Packets Out</th>
<th data-column-id="ifInErrors" data-searchable="false" data-visible="<?php echo $errors_visible ?>" data-css-class="red"<?php echo $error_sort ?>>Errors In</th>
<th data-column-id="ifOutErrors" data-searchable="false" data-visible="<?php echo $errors_visible ?>" data-css-class="red">Errors Out</th>
<th data-column-id="ifType">Media</th>
@@ -47,17 +50,22 @@ function formatUnits(units,decimals,display,base) {
var grid = $("#ports").bootgrid({
ajax: true,
rowCount: [25, 50,100,250,-1],
formatters: {
'human-bps': function(column, row) {
return formatUnits(row[column.id]);
rowCount: [25, 50, 100, 250, -1],
converters: {
'duration': {
to: function (value) { return moment.duration(value, 'seconds').humanize(); }
},
'human-pps': function(column, row) {
return formatUnits(row[column.id], 2, ['pps', 'Kpps', 'Mpps', 'Gpps', 'Tpps', 'Ppps', 'Epps', 'Zpps', 'Ypps']);
'human-bps': {
to: function (value) { return formatUnits(value); }
},
'human-pps': {
to: function (value) {
return formatUnits(value, 2, ['pps', 'Kpps', 'Mpps', 'Gpps', 'Tpps', 'Ppps', 'Epps', 'Zpps', 'Ypps']);
}
}
},
templates: {
search: ""
search: "" // hide the generic search
},
post: function ()
{

View File

@@ -7,6 +7,7 @@ $data_oids = array(
'ifAlias',
'ifAdminStatus',
'ifOperStatus',
'ifLastChange',
'ifMtu',
'ifSpeed',
'ifHighSpeed',
@@ -112,6 +113,7 @@ $ifmib_oids = array(
'ifDescr',
'ifAdminStatus',
'ifOperStatus',
'ifLastChange',
'ifType',
'ifPhysAddress',
'ifMtu',
@@ -471,6 +473,9 @@ foreach ($ports as $port) {
echo $oid.' ';
}
} elseif ($port[$oid] != $this_port[$oid]) {
// if the value is different, update it
// rrdtune if needed
$port_tune = $attribs['ifName_tune:'.$port['ifName']];
$device_tune = $attribs['override_rrdtool_tune'];
if ($port_tune == "true" ||
@@ -480,10 +485,15 @@ foreach ($ports as $port) {
$tune_port = true;
}
}
// set the update data
$port['update'][$oid] = $this_port[$oid];
// store the previous values for alerting
if ($oid == 'ifOperStatus' || $oid == 'ifAdminStatus') {
$port['update'][$oid.'_prev'] = $port[$oid];
}
log_event($oid.': '.$port[$oid].' -> '.$this_port[$oid], $device, 'interface', $port['port_id']);
if ($debug) {
d_echo($oid.': '.$port[$oid].' -> '.$this_port[$oid].' ');

2
sql-schema/136.sql Normal file
View File

@@ -0,0 +1,2 @@
UPDATE `ports` SET `ifLastChange` = 0;
ALTER TABLE `ports` CHANGE `ifLastChange` `ifLastChange` INT NOT NULL DEFAULT 0;